Skip to content
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

ENH: DataFrame.query() should prioritize column names over types defined in local scope. #34958

Open
chrisjcameron opened this issue Jun 23, 2020 · 0 comments
Labels

Comments

@chrisjcameron
Copy link

chrisjcameron commented Jun 23, 2020

Is your feature request related to a problem?

If a column name matches a defined type it does not seem to be possible to include the column in a .query() string. For instance, df.query("Timestamp < 10") throws a TypeError: '<' not supported between instances of 'type' and 'int' for a dataframe where df[df.Timestamp < 10] yields the expected result.

Describe the solution you'd like

Ideally, a query string should prioritize the the column or row index values for the dataframe whose .query method is called. This the natural scope of a query on a dataframe and we already have special operators (e.g. @) to indicate that objects that exist outside the dataframe "namespace". The current behavior to automatically search outside the dataframe is almost a bug.

Describe alternatives you've considered

Alternative 1: Perhaps the backtick escaping for column names with spaces could be extended to prefer matching dataframe column names over classes in the local scope. It does not make as much sense namespace-wise but it is less breaking than the proposed solution.

@chrisjcameron chrisjcameron added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Jun 23, 2020
@rhshadrach rhshadrach added the expressions pd.eval, query label Jun 23, 2020
@jbrockmendel jbrockmendel removed the Needs Triage Issue that has not been reviewed by a pandas team member label Sep 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants