Skip to content

Commit 9a2e821

Browse files
authored
Fix .isin Considers "1" and 1 equal (#34267)
1 parent fc37087 commit 9a2e821

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

pandas/tests/test_algos.py

+27
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,33 @@ def test_different_nans_as_float64(self):
944944
expected = np.array([True, True])
945945
tm.assert_numpy_array_equal(result, expected)
946946

947+
@pytest.mark.xfail(reason="problem related with issue #34125")
948+
def test_isin_int_df_string_search(self):
949+
"""Comparing df with int`s (1,2) with a string at isin() ("1")
950+
-> should not match values because int 1 is not equal str 1"""
951+
df = pd.DataFrame({"values": [1, 2]})
952+
result = df.isin(["1"])
953+
expected_false = pd.DataFrame({"values": [False, False]})
954+
tm.assert_frame_equal(result, expected_false)
955+
956+
@pytest.mark.xfail(reason="problem related with issue #34125")
957+
def test_isin_nan_df_string_search(self):
958+
"""Comparing df with nan value (np.nan,2) with a string at isin() ("NaN")
959+
-> should not match values because np.nan is not equal str NaN """
960+
df = pd.DataFrame({"values": [np.nan, 2]})
961+
result = df.isin(["NaN"])
962+
expected_false = pd.DataFrame({"values": [False, False]})
963+
tm.assert_frame_equal(result, expected_false)
964+
965+
@pytest.mark.xfail(reason="problem related with issue #34125")
966+
def test_isin_float_df_string_search(self):
967+
"""Comparing df with floats (1.4245,2.32441) with a string at isin() ("1.4245")
968+
-> should not match values because float 1.4245 is not equal str 1.4245"""
969+
df = pd.DataFrame({"values": [1.4245, 2.32441]})
970+
result = df.isin(["1.4245"])
971+
expected_false = pd.DataFrame({"values": [False, False]})
972+
tm.assert_frame_equal(result, expected_false)
973+
947974

948975
class TestValueCounts:
949976
def test_value_counts(self):

0 commit comments

Comments
 (0)