-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
REGR: Series.__mod__ behaves different with numexpr #36552
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 4 commits
41bb091
14e8b92
1e2a086
4527d23
ccc7eb6
85db057
ff9e85b
b904d44
4f9b91d
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 |
---|---|---|
|
@@ -171,8 +171,6 @@ def _create_methods(cls, arith_method, comp_method, bool_method, special): | |
mul=arith_method(cls, operator.mul, special), | ||
truediv=arith_method(cls, operator.truediv, special), | ||
floordiv=arith_method(cls, operator.floordiv, special), | ||
# Causes a floating point exception in the tests when numexpr enabled, | ||
# so for now no speedup | ||
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. This message should have been moved in #19649 I think Ok if we have not had reports of floating point exceptions since enabled. |
||
mod=arith_method(cls, operator.mod, special), | ||
pow=arith_method(cls, operator.pow, special), | ||
# not entirely sure why this is necessary, but previously was included | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,7 @@ | |
import pytest | ||
|
||
import pandas._testing as tm | ||
from pandas.core.api import DataFrame | ||
from pandas.core.api import DataFrame, Index, Series | ||
from pandas.core.computation import expressions as expr | ||
|
||
_frame = DataFrame(randn(10000, 4), columns=list("ABCD"), dtype="float64") | ||
|
@@ -380,3 +380,33 @@ def test_frame_series_axis(self, axis, arith): | |
|
||
result = op_func(other, axis=axis) | ||
tm.assert_frame_equal(expected, result) | ||
|
||
@pytest.mark.parametrize( | ||
"op", | ||
[ | ||
"__mod__", | ||
pytest.param("__rmod__", marks=pytest.mark.xfail(reason="GH-36552")), | ||
"__floordiv__", | ||
"__rfloordiv__", | ||
], | ||
) | ||
@pytest.mark.parametrize( | ||
"box, tester", | ||
[ | ||
(DataFrame, tm.assert_frame_equal), | ||
(Series, tm.assert_series_equal), | ||
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. we don't need to usually add the tester as assert_equal handles this 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. good point. a bit belt and braces. will change so we re-run ci b4 merge. |
||
(Index, tm.assert_index_equal), | ||
], | ||
) | ||
@pytest.mark.parametrize("scalar", [-5, 5]) | ||
def test_python_semantics_with_numexpr_installed(self, op, box, tester, scalar): | ||
# https://github.com/pandas-dev/pandas/issues/36047 | ||
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. I see it is done like that in other tests as well (so doesn't need to be fixed here), but that doesn't seem a very clean way to patch this, as it will influence other tests as well 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. this is an class with a teardown_method that resets _MIN_ELEMENTS 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. but yes we should replace with a fixture. 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. Ah, didn't see the teardown/setup, only the import at the top .. |
||
data = np.arange(-50, 50) | ||
obj = box(data) | ||
method = getattr(obj, op) | ||
result = method(scalar) | ||
expr.set_use_numexpr(False) | ||
expected = method(scalar) | ||
expr.set_use_numexpr(True) | ||
tester(result, expected) | ||
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 also test against a manually constructed expected result? 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. i'll look though the tests again to see what we already have. the method i used here is inspired by I kept the object sizes small here so could do elementwise comparion similar to code in #36552 (comment) wdyt? 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's certainly good to test the equivalency of numpy vs numexpr behaviour. But here we discovered a specific case where they are not equal, and I think it is useful to also (in addition, can also be a separate test) test this corner case of negative values with modulo. The object size shouldn't matter since you did 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.
I meant iterating through in Python was not a resource issue. I have added an element-wise comparison but tests are failing at the moment
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. fixed test. this discrepancy that has surfaced is not related to the regression issue, will investigate further. 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. I think pandas is doing the right thing here? other than returning a non-integer result for floordiv. maybe should return IntegerArray in future
still outstanding |
Uh oh!
There was an error while loading. Please reload this page.