Skip to content

Commit 4e858b4

Browse files
committed
TST: GH35131 Add failing test of numpy-like array handling
1 parent 19e8fcc commit 4e858b4

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/dtypes/test_inference.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ def coerce(request):
5959
return request.param
6060

6161

62+
class DuckArray:
63+
"""
64+
A class which wraps around numpy (e.g. Pint's Quantity) but is not actually a numpy array
65+
"""
66+
def __init__(self, values):
67+
self.values = values
68+
69+
def __iter__(self):
70+
it_here = iter(self.values)
71+
72+
for element in it_here:
73+
yield element
74+
75+
@property
76+
def ndim(self):
77+
return self.values.ndim
78+
79+
6280
# collect all objects to be tested for list-like-ness; use tuples of objects,
6381
# whether they are list-like or not (special casing for sets), and their ID
6482
ll_params = [
@@ -93,6 +111,15 @@ def coerce(request):
93111
(np.ndarray((2,) * 4), True, "ndarray-4d"),
94112
(np.array([[[[]]]]), True, "ndarray-4d-empty"),
95113
(np.array(2), False, "ndarray-0d"),
114+
(DuckArray(np.ndarray((2,) * 1)), True, "duck-ndarray-1d"),
115+
(DuckArray(np.array([])), True, "duck-ndarray-1d-empty"),
116+
(DuckArray(np.ndarray((2,) * 2)), True, "duck-ndarray-2d"),
117+
(DuckArray(np.array([[]])), True, "duck-ndarray-2d-empty"),
118+
(DuckArray(np.ndarray((2,) * 3)), True, "duck-ndarray-3d"),
119+
(DuckArray(np.array([[[]]])), True, "duck-ndarray-3d-empty"),
120+
(DuckArray(np.ndarray((2,) * 4)), True, "duck-ndarray-4d"),
121+
(DuckArray(np.array([[[[]]]])), True, "duck-ndarray-4d-empty"),
122+
(DuckArray(np.array(2)), False, "duck-ndarray-0d"),
96123
(1, False, "int"),
97124
(b"123", False, "bytes"),
98125
(b"", False, "bytes-empty"),

0 commit comments

Comments
 (0)