-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
BUG: Allow using numpy in DataFrame.eval
and DataFrame.query
via @-notation
#58057
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
Changes from 5 commits
b6722c5
4051d36
fd47a93
e0b1e72
81d9c7f
1642cdb
dee12b3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -737,6 +737,13 @@ def test_and_logic_string_match(self): | |
assert pd.eval(f"{event.str.match('hello').a}") | ||
assert pd.eval(f"{event.str.match('hello').a and event.str.match('hello').a}") | ||
|
||
def test_using_numpy(self): | ||
# GH 58041 | ||
df = Series([0.2, 1.5, 2.8], name="a").to_frame() | ||
res = df.eval("@np.floor(a)") | ||
expected = np.floor(df["a"]) | ||
tm.assert_series_equal(expected, res, check_names=False) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you set the proper name on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, I can't. The issue is that
Please see my previous comment and/or #58069 for a little bit more details. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On a further thought, we can sort of work around the issue by explicitly stating the |
||
|
||
|
||
# ------------------------------------- | ||
# gh-12388: Typecasting rules consistency with python | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if "when using numpy" is clear - what do you think of doing something like
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated as per suggestion, thanks