Skip to content

Commit eb2da20

Browse files
committed
reworking test cases
1 parent aa672b9 commit eb2da20

File tree

1 file changed

+30
-4
lines changed

1 file changed

+30
-4
lines changed

pandas/tests/test_algos.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -617,16 +617,42 @@ def test_categorical_from_codes(self):
617617

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

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

0 commit comments

Comments
 (0)