-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: _can_use_numexpr fails when passed large Series #27773
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
Conversation
There was some CI failures (Looked like some unrelated http exceptions so I pulled the latest commits in from master to see if that fixes it). I have added the xfail for axis=1 on floordiv and made the whatsnew entry more specific now which should now cover all comments. |
3fb801c
to
7caea6c
Compare
I think the CI error is unrelated. Can you rebase and see if it resolves itself? |
7caea6c
to
c346eeb
Compare
That has fixed it. @WillAyd are you comfortable with the changes? |
else: | ||
other = self.frame.iloc[:, 0] | ||
|
||
expr._MIN_ELEMENTS = 0 |
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.
What does this do?
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.
There is an overhead in using numexpr for computations that makes it not worth using for a low number of computations. The values of this defaults to: 10,000. In this test suite we are trying to verify that numexpr is being invoked correctly however the function _can_use_numexpr checks that the objects operated on are sufficient size:
def _can_use_numexpr(op, op_str, a, b, dtype_check):
""" return a boolean if we WILL be using numexpr """
if op_str is not None:
# required min elements (otherwise we are adding overhead)
if np.prod(a.shape) > _MIN_ELEMENTS:
# further dtype checks to check compatibility may return True
return False
We can therefore run the test suite exclusively on objects where the number of elements > 10,000 or set the min elements to zero to always try and use numexpr.
This is what is meant by a "large DataFrame". Anything where the size of the objects is large enough to warrant using numexpr fails because of the regression, anything that is smaller than the threshold will succeed because numexpr evaluation will not even be considered.
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.
Hmm is affecting global state, right? I worry about this leaking into other tests...
Can you use the monkeypatch
fixture, and do this setting with (IIRC) monkeypatch.setattr
? That way it'll be undone when the test exits.
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.
It is but this is handled in the test classes teardown method on line 57 so the global state won't be affected permanently. I can move my test out of the class and handle this with monkeypatch or we can keep the setup/teardown framework already implemented in the TestExpressions class.
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.
Thanks, I wasn't familiar with these tests.
5d85901
to
1bc2900
Compare
Hi @WillAyd is the Whatsnew entry ok now? |
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.
Looks close, one question about the test.
else: | ||
other = self.frame.iloc[:, 0] | ||
|
||
expr._MIN_ELEMENTS = 0 |
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.
Hmm is affecting global state, right? I worry about this leaking into other tests...
Can you use the monkeypatch
fixture, and do this setting with (IIRC) monkeypatch.setattr
? That way it'll be undone when the test exits.
FYI, can you just merge master & do a regular push, rather than a force push? We don't always get notifications on force pushes. |
This should also close #27853 @ccharlesgb can you make sure the use case there is covered by the new tests? |
@jbrockmendel yes this case is covered in the test as long as divide/div and truediv are all still aliases of each other? |
Added comments to remind of Series case
2d82c8d
to
0100aba
Compare
@jbrockmendel Had to rebase as the CI was failing again. But I think everything is addressed now. |
Thanks @ccharlesgb! |
* BUG: _can_use_numexpr did not handle Series case correctly
* BUG: _can_use_numexpr did not handle Series case correctly
This fixes a regression introduced in #27145 where _can_use_numexpr would fail if passed a Series and not a DataFrame. I decided not to use run_arithmetic in the test_suite because there is a separate issue when running floordiv that is out of the scope of the fix. I will open a separate issue in improving the test coverage of "test_expressions.py" as it currently does not check any of the arguments you can pass to the operators, such as 'axis', 'level' and 'fill_value'.
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff