-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: UndefinedVariableError in DataFrame.query with classname #49248
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
+32
−19
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
edd68dd
initial commit
debnathshoham 8f57a6a
cleanup
debnathshoham 17ec880
looking for column in scope
debnathshoham 7a66a06
looking for column in scope
debnathshoham 2f7ab28
looking for column in scope
debnathshoham 63906de
Merge branch 'main' into gh48694_bug_dfquery
debnathshoham c3a9116
initial commit
debnathshoham 45f68f8
cleanup
debnathshoham 847beed
looking for column in scope
debnathshoham 7b0ed78
looking for column in scope
debnathshoham 52ff08d
looking for column in scope
debnathshoham f16c404
fixed lint
debnathshoham af10f24
Merge remote-tracking branch 'origin/gh48694_bug_dfquery' into gh4869…
debnathshoham 9881ca6
Update ops.py
debnathshoham 69f5778
Merge branch 'main' into gh48694_bug_dfquery
debnathshoham 6b07d7f
minor change
debnathshoham 3817205
Merge branch 'main' into gh48694_bug_dfquery
debnathshoham a674f49
check if Series
debnathshoham 82617c3
mypy happy
debnathshoham 766482e
Merge branch 'main' into gh48694_bug_dfquery
debnathshoham 97e0c33
Merge branch 'main' into gh48694_bug_dfquery
debnathshoham 63dad3c
Merge branch 'main' into gh48694_bug_dfquery
debnathshoham File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1846,7 +1846,7 @@ def test_negate_lt_eq_le(engine, parser): | |
) | ||
def test_eval_no_support_column_name(request, column): | ||
# GH 44603 | ||
if column in ["True", "False", "inf", "Inf"]: | ||
if column in ["True", "False"]: | ||
request.node.add_marker( | ||
pytest.mark.xfail( | ||
raises=KeyError, | ||
|
@@ -1861,6 +1861,17 @@ def test_eval_no_support_column_name(request, column): | |
tm.assert_frame_equal(result, expected) | ||
|
||
|
||
def test_classname_frame_query(): | ||
# GH 48694 | ||
class A: | ||
a = 1 | ||
|
||
df1 = DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]}) | ||
df_test = DataFrame({"x": [1], "y": [4]}) | ||
tm.assert_frame_equal(df_test, df1.query(f"x=={A.a}")) | ||
tm.assert_frame_equal(df_test, df1.query("[email protected]")) | ||
|
||
|
||
@td.skip_array_manager_not_yet_implemented | ||
def test_set_inplace(using_copy_on_write): | ||
# https://github.com/pandas-dev/pandas/issues/47449 | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't
self.env.scope.get("column") == local_name
always produce a bool?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, ideally it should.
Although the tests were fine, but it threw the error you mentioned up here #49248 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not too familiar with this part of the codebase, but is there a way to check if it's local without checking if it's a series?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the error on the docs were specific to Series (either

local_name
orself.env.scope.get("column")
)One example below
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can the
self.env.scope.get("column")
Seriesname
just be compared to thelocal_name
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so something like
sorry but how is that any better?
EDIT: or did you mean just compare the Series.name? but for most cases, they aren't Series
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(This may be my ignorance to this part of the code base), but I assumed that
self.env.scope["column"]
would refer to a Series object and thelocal_name
would refer to the name of the Series so noSeries
checking needs to be done.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, no that's not the case. Usually it's name of a df column.
I did the Series check just to cover the Sphinx errors. Maybe someone with better Sphinx knowledge can fix this more elegantly.