@@ -60,6 +60,30 @@ def coerce(request):
60
60
return request .param
61
61
62
62
63
+ class MockNumpyLikeArray :
64
+ """
65
+ A class which is numpy-like (e.g. Pint's Quantity) but not actually numpy
66
+
67
+ The key is that it is not actually a numpy array so
68
+ ``util.is_array(mock_numpy_like_array_instance)`` returns ``False``. Other
69
+ important properties are that the class defines a :meth:`__iter__` method
70
+ (so that ``isinstance(abc.Iterable)`` returns ``True``) and has a
71
+ :meth:`ndim` property which can be used as a check for whether it is a
72
+ scalar or not.
73
+ """
74
+
75
+ def __init__ (self , values ):
76
+ self ._values = values
77
+
78
+ def __iter__ (self ):
79
+ for element in iter (self ._values ):
80
+ yield element
81
+
82
+ @property
83
+ def ndim (self ):
84
+ return self ._values .ndim
85
+
86
+
63
87
# collect all objects to be tested for list-like-ness; use tuples of objects,
64
88
# whether they are list-like or not (special casing for sets), and their ID
65
89
ll_params = [
@@ -94,6 +118,15 @@ def coerce(request):
94
118
(np .ndarray ((2 ,) * 4 ), True , "ndarray-4d" ),
95
119
(np .array ([[[[]]]]), True , "ndarray-4d-empty" ),
96
120
(np .array (2 ), False , "ndarray-0d" ),
121
+ (MockNumpyLikeArray (np .ndarray ((2 ,) * 1 )), True , "duck-ndarray-1d" ),
122
+ (MockNumpyLikeArray (np .array ([])), True , "duck-ndarray-1d-empty" ),
123
+ (MockNumpyLikeArray (np .ndarray ((2 ,) * 2 )), True , "duck-ndarray-2d" ),
124
+ (MockNumpyLikeArray (np .array ([[]])), True , "duck-ndarray-2d-empty" ),
125
+ (MockNumpyLikeArray (np .ndarray ((2 ,) * 3 )), True , "duck-ndarray-3d" ),
126
+ (MockNumpyLikeArray (np .array ([[[]]])), True , "duck-ndarray-3d-empty" ),
127
+ (MockNumpyLikeArray (np .ndarray ((2 ,) * 4 )), True , "duck-ndarray-4d" ),
128
+ (MockNumpyLikeArray (np .array ([[[[]]]])), True , "duck-ndarray-4d-empty" ),
129
+ (MockNumpyLikeArray (np .array (2 )), False , "duck-ndarray-0d" ),
97
130
(1 , False , "int" ),
98
131
(b"123" , False , "bytes" ),
99
132
(b"" , False , "bytes-empty" ),
0 commit comments