Skip to content

Commit 357a2b0

Browse files
committed
Added test and whatsnew
- 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 `#50937`
1 parent 63e40f3 commit 357a2b0

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

doc/source/whatsnew/v2.0.0.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,6 +1016,7 @@ Numeric
10161016
- 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`)
10171017
- 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`)
10181018
- Bug in :meth:`Series.__add__` casting to object for list and masked :class:`Series` (:issue:`22962`)
1019+
- Bug in :meth:`query` with ``engine="numexpr"`` and column names are ``min`` or ``max``, does not work correctly (:issue:`50937`)
10191020

10201021
Conversion
10211022
^^^^^^^^^^

pandas/tests/frame/test_query_eval.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import numpy as np
44
import pytest
55

6-
from pandas.errors import UndefinedVariableError
6+
from pandas.errors import (
7+
NumExprClobberingError,
8+
UndefinedVariableError,
9+
)
710
import pandas.util._test_decorators as td
811

912
import pandas as pd
@@ -864,6 +867,22 @@ def test_nested_scope(self):
864867
)
865868
tm.assert_frame_equal(expected, result)
866869

870+
def test_query_numexpr_with_min_and_max_columns(self):
871+
df = DataFrame({"min": [1, 2, 3], "max": [4, 5, 6]})
872+
regex_to_match = (
873+
r"Variables in expression \"\(min\) == \(1\)\" "
874+
r"overlap with builtins: \('min'\)"
875+
)
876+
with pytest.raises(NumExprClobberingError, match=regex_to_match):
877+
df.query("min == 1")
878+
879+
regex_to_match = (
880+
r"Variables in expression \"\(max\) == \(1\)\" "
881+
r"overlap with builtins: \('max'\)"
882+
)
883+
with pytest.raises(NumExprClobberingError, match=regex_to_match):
884+
df.query("max == 1")
885+
867886

868887
class TestDataFrameQueryPythonPandas(TestDataFrameQueryNumExprPandas):
869888
@classmethod

0 commit comments

Comments
 (0)