Skip to content

Commit c5d9c17

Browse files
committed
ENH: GH35131 Implement fix which allows numpy-like handling
Now pd.core.dtypes.inference.is_list_like correctly identifies numpy-like scalars as not being iterable
1 parent 4e858b4 commit c5d9c17

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

pandas/_libs/lib.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,8 +994,8 @@ cdef inline bint c_is_list_like(object obj, bint allow_sets) except -1:
994994
isinstance(obj, abc.Iterable)
995995
# we do not count strings/unicode/bytes as list-like
996996
and not isinstance(obj, (str, bytes))
997-
# exclude zero-dimensional numpy arrays, effectively scalars
998-
and not (util.is_array(obj) and obj.ndim == 0)
997+
# exclude zero-dimensional duck arrays, effectively scalars
998+
and not (hasattr(obj, "ndim") and obj.ndim == 0)
999999
# exclude sets if allow_sets is False
10001000
and not (allow_sets is False and isinstance(obj, abc.Set))
10011001
)

pandas/tests/dtypes/test_inference.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ def coerce(request):
6161

6262
class DuckArray:
6363
"""
64-
A class which wraps around numpy (e.g. Pint's Quantity) but is not actually a numpy array
64+
A class which wraps around numpy (e.g. Pint's Quantity)
65+
66+
The key is that it is not actually a numpy array so
67+
``util.is_array(duck_array_instance)`` returns ``False``
6568
"""
69+
6670
def __init__(self, values):
6771
self.values = values
6872

0 commit comments

Comments
 (0)