Skip to content

Min max added to reduction ops #50988

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

Conversation

ShisuiUzumaki
Copy link
Contributor

@ShisuiUzumaki
Copy link
Contributor Author

ShisuiUzumaki commented Jan 26, 2023

Can someone from pandas team review this?

@mroeschke mroeschke added the expressions pd.eval, query label Jan 26, 2023
Copy link
Member

@mroeschke mroeschke left a comment

Choose a reason for hiding this comment

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

Needs tests and a whatsnew note in v2.0.0.rst

@ShisuiUzumaki
Copy link
Contributor Author

Needs tests and a whatsnew note in v2.0.0.rst

Could you give some pointers on how can I add these tests and whatsnew

@mroeschke
Copy link
Member

A unit test that checks the behavior of the related issue be added to pandas/tests/frame/test_query_eval.py.

An entry should be added to doc/source/whatsnew/v2.0.0.rst describing what was fixed

@ShisuiUzumaki
Copy link
Contributor Author

A unit test that checks the behavior of the related issue be added to pandas/tests/frame/test_query_eval.py.

An entry should be added to doc/source/whatsnew/v2.0.0.rst describing what was fixed

Would the following test be okay?

class TestDataFrameQueryNumExprPython(TestDataFrameQueryNumExprPandas):

    ...

    def test_query_numexpr_with_min_and_max_columns(self):
        df = DataFrame({"min": [1, 2, 3], "max": [4, 5, 6]})
        regex_to_match = r"Variables in expression \"\(min\) == \(1\)\" overlap with builtins: \('min'\)"
        with pytest.raises(NumExprClobberingError, match=regex_to_match):
            df.query("min == 1")

        regex_to_match = r"Variables in expression \"\(max\) == \(1\)\" overlap with builtins: \('max'\)"
        with pytest.raises(NumExprClobberingError, match=regex_to_match):
            df.query("max == 1")

@mroeschke
Copy link
Member

Yes but the tests can just be stand alone functions

@ShisuiUzumaki
Copy link
Contributor Author

ShisuiUzumaki commented Jan 31, 2023

An entry should be added to doc/source/whatsnew/v2.0.0.rst describing what was fixed

Also, could you give me some more hints on what format I should follow to add changes descriptions in
doc/source/whatsnew/v2.0.0.rst? Like in what section, what should be the phrasing format, etc.

Is this ok:

Numeric
^^^^^^^

  • Bug in :meth:query with engine="numexpr" and column names are min or max, does not work correctly (:issue:50937)

@mroeschke
Copy link
Member

This will be easier to comment on if you commit the changes you suggested

@ShisuiUzumaki
Copy link
Contributor Author

This will be easier to comment on if you commit the changes you suggested

Sure!

- Added `test_query_numexpr_with_min_and_max_columns`  in `pandas/frame/tests/test_query_eval.py`
- Bug fix entry added in `pandas/doc/source/whatsnew/v2.0.0.rst` for issue `pandas-dev#50937`
@ShisuiUzumaki ShisuiUzumaki force-pushed the min_max_added_to_reduction_ops branch from b6c286e to 357a2b0 Compare February 1, 2023 09:54
@mroeschke
Copy link
Member

************* Module pandas.tests.frame.test_query_eval
pandas/tests/frame/test_query_eval.py:540:8: W0404: Reimport 'NumExprClobberingError' (imported line 6) (reimported)

@mroeschke mroeschke added this to the 2.0 milestone Feb 2, 2023
@mroeschke mroeschke merged commit f623a6e into pandas-dev:main Feb 2, 2023
@mroeschke
Copy link
Member

Thanks @ShisuiUzumaki

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
expressions pd.eval, query
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG: query(engine='numexpr') not work correctly when column name is 'max' or 'min'.
2 participants