-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
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
Changes from all commits
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 |
---|---|---|
|
@@ -66,7 +66,7 @@ def run_arithmetic(self, df, other, assert_func, check_dtype=False, test_flex=Tr | |
operator_name = "truediv" | ||
|
||
if test_flex: | ||
op = lambda x, y: getattr(df, arith)(y) | ||
op = lambda x, y: getattr(x, arith)(y) | ||
op.__name__ = arith | ||
else: | ||
op = getattr(operator, operator_name) | ||
|
@@ -318,7 +318,6 @@ def testit(): | |
for f in [self.frame, self.frame2, self.mixed, self.mixed2]: | ||
|
||
for cond in [True, False]: | ||
|
||
c = np.empty(f.shape, dtype=np.bool_) | ||
c.fill(cond) | ||
result = expr.where(c, f.values, f.values + 1) | ||
|
@@ -431,3 +430,29 @@ def test_bool_ops_column_name_dtype(self, test_input, expected): | |
# GH 22383 - .ne fails if columns containing column name 'dtype' | ||
result = test_input.loc[:, ["a", "dtype"]].ne(test_input.loc[:, ["a", "dtype"]]) | ||
assert_frame_equal(result, expected) | ||
|
||
@pytest.mark.parametrize( | ||
"arith", ("add", "sub", "mul", "mod", "truediv", "floordiv") | ||
) | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@pytest.mark.parametrize("axis", (0, 1)) | ||
def test_frame_series_axis(self, axis, arith): | ||
# GH#26736 Dataframe.floordiv(Series, axis=1) fails | ||
if axis == 1 and arith == "floordiv": | ||
TomAugspurger marked this conversation as resolved.
Show resolved
Hide resolved
|
||
pytest.xfail("'floordiv' does not succeed with axis=1 #27636") | ||
|
||
df = self.frame | ||
if axis == 1: | ||
other = self.frame.iloc[0, :] | ||
else: | ||
other = self.frame.iloc[:, 0] | ||
|
||
expr._MIN_ELEMENTS = 0 | ||
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. What does this do? 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. 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 commentThe 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 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. 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 commentThe reason will be displayed to describe this comment to others. Learn more. Thanks, I wasn't familiar with these tests. |
||
|
||
op_func = getattr(df, arith) | ||
|
||
expr.set_use_numexpr(False) | ||
expected = op_func(other, axis=axis) | ||
expr.set_use_numexpr(True) | ||
|
||
result = op_func(other, axis=axis) | ||
assert_frame_equal(expected, result) |
Uh oh!
There was an error while loading. Please reload this page.