@@ -60,6 +60,50 @@ 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
+ iter_values = iter (self ._values )
80
+
81
+ def it_outer ():
82
+ for element in iter_values :
83
+ yield element
84
+
85
+ return it_outer ()
86
+
87
+ def __len__ (self ):
88
+ return len (self ._values )
89
+
90
+ @property
91
+ def ndim (self ):
92
+ return self ._values .ndim
93
+
94
+ @property
95
+ def dtype (self ):
96
+ return self ._values .dtype
97
+
98
+ @property
99
+ def size (self ):
100
+ return self ._values .size
101
+
102
+ @property
103
+ def shape (self ):
104
+ return self ._values .shape
105
+
106
+
63
107
# collect all objects to be tested for list-like-ness; use tuples of objects,
64
108
# whether they are list-like or not (special casing for sets), and their ID
65
109
ll_params = [
@@ -166,6 +210,14 @@ class DtypeList(list):
166
210
assert not inference .is_array_like (123 )
167
211
168
212
213
+ @pytest .mark .parametrize ("eg" , (
214
+ np .array (2 ),
215
+ MockNumpyLikeArray (np .array (2 )),
216
+ ))
217
+ def test_assert_almost_equal (eg ):
218
+ tm .assert_almost_equal (eg , eg )
219
+
220
+
169
221
@pytest .mark .parametrize (
170
222
"inner" ,
171
223
[
0 commit comments