@@ -616,16 +616,42 @@ def test_categorical_from_codes(self):
616
616
617
617
def test_same_object_is_in (self ):
618
618
# 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
621
622
values = [np .nan ]
622
- expected = np .array ([False , True ])
623
+ expected = np .array ([True ])
623
624
result = algos .isin (comps , values )
624
625
tm .assert_numpy_array_equal (expected , result )
625
626
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
+
626
652
def test_no_cast (self ):
627
653
# GH 22160
628
- # ensure 42 is not casted to string
654
+ # ensure 42 is not casted to a string
629
655
comps = ['ss' , 42 ]
630
656
values = ['42' ]
631
657
expected = np .array ([False , False ])
0 commit comments