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

call __finalize__ in DataFrame.eval with engine=numexpr #52888

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 9 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -4596,7 +4596,15 @@ def eval(self, expr: str, *, inplace: bool = False, **kwargs) -> Any | None:
kwargs["target"] = self
kwargs["resolvers"] = tuple(kwargs.get("resolvers", ())) + resolvers

return _eval(expr, inplace=inplace, **kwargs)
result = _eval(expr, inplace=inplace, **kwargs)

# Extract the engine from kwargs or use the default value "numexpr"
engine = kwargs.get("engine")

if engine == "numexpr" and inplace is False:
Copy link
Member

Choose a reason for hiding this comment

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

Can you fix this in _eval instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure! I will do that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@mroeschke Mr. Roeschke, I am sorry I tried but failed to move it to the eval in _eval, would you mind giving me some suggestions, please? I would very much appreciate it

return result.__finalize__(self, method="eval")
else:
return result

def select_dtypes(self, include=None, exclude=None) -> Self:
"""
Expand Down
1 change: 0 additions & 1 deletion pandas/tests/generic/test_finalize.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,6 @@ def test_finalize_called(ndframe_method):
assert result.attrs == {"a": 1}


@not_implemented_mark
def test_finalize_called_eval_numexpr():
pytest.importorskip("numexpr")
df = pd.DataFrame({"A": [1, 2]})
Expand Down