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