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