Skip to content

Fix .isin Considers "1" and 1 equal #34267

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 8, 2020
27 changes: 27 additions & 0 deletions pandas/tests/test_algos.py
Original file line number Diff line number Diff line change
Expand Up @@ -2374,3 +2374,30 @@ def test_index(self):
dtype="timedelta64[ns]",
)
tm.assert_series_equal(algos.mode(idx), exp)

@pytest.mark.xfail(reason="problem related with issue #34125")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you put these in the right class, Isin

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, sorry about that, I didn’t realize that this class exists, my bad! But everything looks good now!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it right?

def test_isin_int_df_string_search(self):
"""Comparing df with int`s (1,2) with a string at isin() ("1")
-> should not match values because int 1 is not equal str 1"""
df = pd.DataFrame({"values": [1, 2]})
result = df.isin(["1"])
expected_false = pd.DataFrame({"values": [False, False]})
tm.assert_frame_equal(result, expected_false)

@pytest.mark.xfail(reason="problem related with issue #34125")
def test_isin_nan_df_string_search(self):
"""Comparing df with nan value (np.nan,2) with a string at isin() ("NaN")
-> should not match values because np.nan is not equal str NaN """
df = pd.DataFrame({"values": [np.nan, 2]})
result = df.isin(["NaN"])
expected_false = pd.DataFrame({"values": [False, False]})
tm.assert_frame_equal(result, expected_false)

@pytest.mark.xfail(reason="problem related with issue #34125")
def test_isin_float_df_string_search(self):
"""Comparing df with floats (1.4245,2.32441) with a string at isin() ("1.4245")
-> should not match values because float 1.4245 is not equal str 1.4245"""
df = pd.DataFrame({"values": [1.4245, 2.32441]})
result = df.isin(["1.4245"])
expected_false = pd.DataFrame({"values": [False, False]})
tm.assert_frame_equal(result, expected_false)