Skip to content

Error raised message: DataFrame eval will not work with 'Timestamp' column name #47273

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 38 commits into from
Aug 12, 2022
Merged
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
40a1b23
test
Jun 2, 2022
7b57da0
Merge branch 'main' of https://github.com/weikhor/pandas into test_ev…
Jun 7, 2022
b97005e
add test
Jun 7, 2022
93a8beb
Merge branch 'main' into test_eval_message
Jun 7, 2022
a692dea
Merge branch 'main' into test_eval_message
Jun 11, 2022
f77de75
add
Jun 11, 2022
cffac69
Merge branch 'test_eval_message' of https://github.com/weikhor/pandas…
Jun 11, 2022
272a7d1
add
Jun 11, 2022
d052199
Merge branch 'main' into test_eval_message
Jun 16, 2022
dbce57a
Merge branch 'main' into test_eval_message
Jun 18, 2022
27aa682
Merge branch 'main' into test_eval_message
Jun 19, 2022
9dbfad3
Merge branch 'main' into test_eval_message
Jun 27, 2022
ad5e033
Merge branch 'main' into test_eval_message
Jul 2, 2022
2519b5c
Merge branch 'main' into test_eval_message
Jul 5, 2022
01dfa46
Merge branch 'main' into test_eval_message
Jul 12, 2022
ffc7bc7
test
Jul 20, 2022
561d6ae
add
Jul 26, 2022
19c315f
Merge branch 'main' into test_eval_message
Jul 26, 2022
4fe8b84
test
Jul 26, 2022
b5285af
add xfail
Jul 26, 2022
debe671
change to KeyError
Jul 26, 2022
b8d5a53
Merge branch 'main' into test_eval_message
Jul 27, 2022
5d8ea93
test eval
Jul 27, 2022
84e23ea
Merge branch 'test_eval_message' of https://github.com/weikhor/pandas…
Jul 27, 2022
b1c2a4a
update to key
Jul 27, 2022
7813d4a
Merge branch 'main' into test_eval_message
Jul 27, 2022
595b477
add github issue
Jul 30, 2022
dd826cf
Merge branch 'test_eval_message' of https://github.com/weikhor/pandas…
Jul 30, 2022
4b4ae4e
add github issue
Jul 30, 2022
83cc8c5
Merge branch 'main' into test_eval_message
Aug 1, 2022
a8ece6d
gMerge branch 'main' of https://github.com/weikhor/pandas into test_e…
Aug 4, 2022
96314be
add whatsnew
Aug 4, 2022
9114ebc
Merge branch 'main' into test_eval_message
Aug 5, 2022
3ada522
Update doc/source/whatsnew/v1.5.0.rst
mroeschke Aug 8, 2022
ffd589c
update rst to conversion header
Aug 10, 2022
0d7859d
Merge branch 'main' into test_eval_message
Aug 10, 2022
8e9d86d
update rst to conversion header
Aug 10, 2022
f7a65c9
Merge branch 'test_eval_message' of https://github.com/weikhor/pandas…
Aug 10, 2022
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
9 changes: 8 additions & 1 deletion pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,14 @@ def evaluate(self, *args, **kwargs) -> Term:
return self

def _resolve_name(self):
res = self.env.resolve(self.local_name, is_local=self.is_local)
local_name = str(self.local_name)
is_local = self.is_local
if local_name in self.env.scope and isinstance(
self.env.scope[local_name], type
):
is_local = False

res = self.env.resolve(local_name, is_local=is_local)
self.update(res)

if hasattr(res, "ndim") and res.ndim > 2:
Expand Down
22 changes: 22 additions & 0 deletions pandas/tests/computation/test_eval.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
_binary_ops_dict,
_unary_math_ops,
)
from pandas.core.computation.scope import DEFAULT_GLOBALS


@pytest.fixture(
Expand Down Expand Up @@ -1890,6 +1891,27 @@ def test_negate_lt_eq_le(engine, parser):
tm.assert_frame_equal(result, expected)


@pytest.mark.parametrize(
"column",
DEFAULT_GLOBALS.keys(),
)
def test_eval_no_support_column_name(request, column):
# GH 44603
if column in ["True", "False", "inf", "Inf"]:
request.node.add_marker(
pytest.mark.xfail(
raises=KeyError,
reason=f"GH 47859 DataFrame eval not supported with {column}",
)
)

df = DataFrame(np.random.randint(0, 100, size=(10, 2)), columns=[column, "col1"])
expected = df[df[column] > 6]
result = df.query(f"{column}>6")

tm.assert_frame_equal(result, expected)


class TestValidate:
@pytest.mark.parametrize("value", [1, "True", [1, 2, 3], 5.0])
def test_validate_bool_args(self, value):
Expand Down