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
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions doc/source/whatsnew/v2.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ Numeric
- Bug in DataFrame reduction methods (e.g. :meth:`DataFrame.sum`) with object dtype, ``axis=1`` and ``numeric_only=False`` would not be coerced to float (:issue:`49551`)
- Bug in :meth:`DataFrame.sem` and :meth:`Series.sem` where an erroneous ``TypeError`` would always raise when using data backed by an :class:`ArrowDtype` (:issue:`49759`)
- Bug in :meth:`Series.__add__` casting to object for list and masked :class:`Series` (:issue:`22962`)
- Bug in :meth:`query` with ``engine="numexpr"`` and column names are ``min`` or ``max``, does not work correctly (:issue:`50937`)

Conversion
^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
pprint_thing_encoded,
)

REDUCTIONS = ("sum", "prod")
REDUCTIONS = ("sum", "prod", "min", "max")

_unary_math_ops = (
"sin",
Expand Down
21 changes: 20 additions & 1 deletion pandas/tests/frame/test_query_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import numpy as np
import pytest

from pandas.errors import UndefinedVariableError
from pandas.errors import (
NumExprClobberingError,
UndefinedVariableError,
)
import pandas.util._test_decorators as td

import pandas as pd
Expand Down Expand Up @@ -864,6 +867,22 @@ def test_nested_scope(self):
)
tm.assert_frame_equal(expected, result)

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\)\" "
r"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\)\" "
r"overlap with builtins: \('max'\)"
)
with pytest.raises(NumExprClobberingError, match=regex_to_match):
df.query("max == 1")


class TestDataFrameQueryPythonPandas(TestDataFrameQueryNumExprPandas):
@classmethod
Expand Down