Skip to content

Commit 8f18ffc

Browse files
committed
BUG: array_equivalent was not passing its own doctest. The examples showed lists being passed to array_equivalent. array_equivalent expects ndarrays only.
1 parent ea8fba4 commit 8f18ffc

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

pandas/core/common.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,7 @@ def array_equivalent(left, right):
287287
288288
Parameters
289289
----------
290-
left, right : array_like
291-
Input arrays.
290+
left, right : ndarrays
292291
293292
Returns
294293
-------
@@ -297,20 +296,15 @@ def array_equivalent(left, right):
297296
298297
Examples
299298
--------
300-
>>> array_equivalent([1, 2, nan], np.array([1, 2, nan]))
299+
>>> array_equivalent(np.array([1, 2, nan]), np.array([1, 2, nan]))
301300
True
302-
>>> array_equivalent([1, nan, 2], [1, 2, nan])
301+
>>> array_equivalent(np.array([1, nan, 2]), np.array([1, 2, nan]))
303302
False
304303
"""
305304
if left.shape != right.shape: return False
306305
# NaNs occur only in object arrays, float or complex arrays.
307-
if left.dtype == np.object_:
308-
# If object array, we need to use pd.isnull
309-
return ((left == right) | pd.isnull(left) & pd.isnull(right)).all()
310-
elif not issubclass(left.dtype.type, (np.floating, np.complexfloating)):
311-
# if not a float or complex array, then there are no NaNs
306+
if not issubclass(left.dtype.type, (np.floating, np.complexfloating)):
312307
return np.array_equal(left, right)
313-
# For float or complex arrays, using np.isnan is faster than pd.isnull
314308
return ((left == right) | (np.isnan(left) & np.isnan(right))).all()
315309

316310
def _iterable_not_string(x):

pandas/tests/test_common.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,15 +168,18 @@ def test_downcast_conv():
168168

169169

170170
def test_array_equivalent():
171-
assert array_equivalent(np.array([np.nan, np.nan]), np.array([np.nan, np.nan]))
172-
assert array_equivalent(np.array([np.nan, 1, np.nan]), np.array([np.nan, 1, np.nan]))
171+
assert array_equivalent(np.array([np.nan, np.nan]),
172+
np.array([np.nan, np.nan]))
173+
assert array_equivalent(np.array([np.nan, 1, np.nan]),
174+
np.array([np.nan, 1, np.nan]))
173175
assert array_equivalent(np.array([np.nan, None], dtype='object'),
174176
np.array([np.nan, None], dtype='object'))
175177
assert array_equivalent(np.array([np.nan, 1+1j], dtype='complex'),
176178
np.array([np.nan, 1+1j], dtype='complex'))
177179
assert not array_equivalent(np.array([np.nan, 1+1j], dtype='complex'),
178180
np.array([np.nan, 1+2j], dtype='complex'))
179-
assert not array_equivalent(np.array([np.nan, 1, np.nan]), np.array([np.nan, 2, np.nan]))
181+
assert not array_equivalent(np.array([np.nan, 1, np.nan]),
182+
np.array([np.nan, 2, np.nan]))
180183
assert not array_equivalent(np.array(['a', 'b', 'c', 'd']), np.array(['e', 'e']))
181184

182185
def test_datetimeindex_from_empty_datetime64_array():

0 commit comments

Comments
 (0)