Skip to content

TST: Added test for query method with string dtype and null values (#… #53130

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

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,37 @@ def test_query_string_scalar_variable(self, parser, engine):
r = df.query("Symbol == @symb", parser=parser, engine=engine)
tm.assert_frame_equal(e, r)

@pytest.mark.parametrize(
"in_list",
[
[None, "asdf", "ghjk"],
["asdf", None, "ghjk"],
["asdf", "ghjk", None],
[None, None, "asdf"],
["asdf", None, None],
[None, None, None],
],
)
def test_query_string_null_elements(self, in_list: list):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
def test_query_string_null_elements(self, in_list: list):
def test_query_string_null_elements(self, in_list):

# GITHUB ISSUE #31516
parser = "pandas"
engine = "python"
expected = {
i: value
for value, i in zip(in_list, range(len(in_list)))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
for value, i in zip(in_list, range(len(in_list)))
for i, value in enumerate(in_list)

if value == "asdf"
}
df_expected = DataFrame({"a": expected}, dtype="string")
df_expected.index = df_expected.index.astype("int64")
df = DataFrame({"a": in_list}, dtype="string")
res1 = df.query("a == 'asdf'", parser=parser, engine=engine)
res2 = df[df["a"] == "asdf"]
res3 = df.query("a <= 'asdf'", parser=parser, engine=engine)
tm.assert_frame_equal(res1, df_expected)
tm.assert_frame_equal(res1, res2)
tm.assert_frame_equal(res1, res3)
tm.assert_frame_equal(res2, res3)


class TestDataFrameEvalWithFrame:
@pytest.fixture
Expand Down