Skip to content

Commit 667dfc1

Browse files
committed
reworking test cases
1 parent 9043508 commit 667dfc1

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

pandas/tests/test_algos.py

+30-4
Original file line numberDiff line numberDiff line change
@@ -616,16 +616,42 @@ def test_categorical_from_codes(self):
616616

617617
def test_same_object_is_in(self):
618618
# GH 22160
619-
# nan is special, because out of a is a doesn't follow a == a
620-
comps = ['ss', np.nan]
619+
# nan is special, because from " a is b" doesn't follow "a == b"
620+
# casting to -> np.float64 -> float-object will results in another nan-object
621+
comps = [np.nan] # could be casted to float64
621622
values = [np.nan]
622-
expected = np.array([False, True])
623+
expected = np.array([True])
623624
result = algos.isin(comps, values)
624625
tm.assert_numpy_array_equal(expected, result)
625626

627+
def test_different_nans(self):
628+
# GH 22160
629+
# the current behavior is:
630+
# * list, array of objects: isin() is False for different nan-objects
631+
# * array of float64s: isin() is True for all nans
632+
# this behavior might be changed in the future
633+
#
634+
# this test case only ensures it doesn't happen accidentally
635+
#
636+
comps = [float('nan')]
637+
values = [float('nan')]
638+
assert comps[0] is not values[0] # different nan-objects
639+
640+
# as list of python-objects:
641+
result = algos.isin(comps, values)
642+
tm.assert_numpy_array_equal(np.array([False]), result)
643+
644+
# as object-array:
645+
result = algos.isin(np.asarray(comps, dtype=np.object), np.asarray(values, dtype=np.object))
646+
tm.assert_numpy_array_equal(np.array([False]), result)
647+
648+
#as float64-array:
649+
result = algos.isin(np.asarray(comps, dtype=np.float64), np.asarray(values, dtype=np.float64))
650+
tm.assert_numpy_array_equal(np.array([True]), result)
651+
626652
def test_no_cast(self):
627653
# GH 22160
628-
# ensure 42 is not casted to string
654+
# ensure 42 is not casted to a string
629655
comps = ['ss', 42]
630656
values = ['42']
631657
expected = np.array([False, False])

0 commit comments

Comments
 (0)