8000 ENH: make is_list_like handle non iterable numpy-like arrays correctly by znicholls · Pull Request #35127 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

ENH: make is_list_like handle non iterable numpy-like arrays correctly #35127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Prev Previous commit
Next Next commit
Make a mess
  • Loading branch information
znicholls committed Feb 13, 2021
commit 088dff81863047d9260a0daba7d2b0015cc4010b
1 change: 1 addition & 0 deletions pandas/_libs/testing.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ from pandas._libs.lib import is_complex
from pandas._libs.util cimport is_array, is_real_number_object

from pandas.core.dtypes.common import is_dtype_equal
from pandas.core.dtypes.inference import is_array_like
from pandas.core.dtypes.missing import array_equivalent, isna


Expand Down
5 changes: 5 additions & 0 deletions pandas/core/dtypes/missing.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,11 @@ def array_equivalent(
# Slow path when we allow comparing different dtypes.
# Object arrays can contain None, NaN and NaT.
# string dtypes must be come to this path for NumPy 1.7.1 compat
try:
return np.array_equal(left, right)
except:
pass

if is_string_dtype(left.dtype) or is_string_dtype(right.dtype):
return _array_equivalent_object(left, right, strict_nan)

Expand Down
8 changes: 8 additions & 0 deletions pandas/tests/dtypes/test_inference.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,8 @@ def test_is_array_like():
assert inference.is_array_like(Series([1, 2]))
assert inference.is_array_like(np.array(["a", "b"]))
assert inference.is_array_like(Index(["2016-01-01"]))
assert inference.is_array_like(np.array([2, 3]))
assert inference.is_array_like(MockNumpyLikeArray(np.array([2, 3])))

class DtypeList(list):
dtype = "special"
Expand All @@ -221,6 +223,12 @@ class DtypeList(list):
assert not inference.is_array_like(123)


def test_assert_almost_equal():
tm.assert_almost_equal(np.array(2), np.array(2))
eg = MockNumpyLikeArray(np.array(2))
tm.assert_almost_equal(eg, eg)


@pytest.mark.parametrize(
"eg",
(
Expand Down
0