-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: raise when doing arithmetic on DataFrame and list of iterables #37132
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
doc/source/whatsnew/v1.2.0.rst
Outdated
@@ -494,6 +494,7 @@ Other | |||
- Fixed metadata propagation in the :class:`Series.dt` and :class:`Series.str` accessors (:issue:`28283`) | |||
- Bug in :meth:`Index.union` behaving differently depending on whether operand is a :class:`Index` or other list-like (:issue:`36384`) | |||
- Passing an array with 2 or more dimensions to the :class:`Series` constructor now raises the more specific ``ValueError``, from a bare ``Exception`` previously (:issue:`35744`) | |||
- Bug in :class:`DataFrame` allowing arithmetic operations with list of array-likes with undefined results. Behavior changed to raising ``ValueError`` (:issue:`36702`) |
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.
put in Numeric section
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.
Done.
@@ -1577,3 +1577,17 @@ def test_arith_reindex_with_duplicates(): | |||
result = df1 + df2 | |||
expected = pd.DataFrame([[np.nan, 0, 0]], columns=["first", "second", "second"]) | |||
tm.assert_frame_equal(result, expected) | |||
|
|||
|
|||
@pytest.mark.parametrize("arg1", [pd.DataFrame({"x": [1, 2], "y": [1, 2]})]) |
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.
if there's just one of these (and i think there only needs to be one), then just put it in the test function instead of parameter
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 for spotting this! Moved the DataFrame inside the test.
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.
comment by @jbrockmendel ping on green
Ran indexing benchmarks three times, no stable regressions on my machine. |
Made the change suggested by @jbrockmendel , all green. |
thanks @AlexKirko nice! |
Unfortunately this fix breaks |
@vnmabus can you give a link or example? |
I have two extension arrays in https://github.com/GAA-UAM/scikit-fda, These extension arrays (mostly) work with Pandas, but this fix raises an exception, as they are "list like" and the elements (that is, the same class) are "array like". Yo can see the error here: https://github.com/GAA-UAM/scikit-fda/runs/3037343824. |
Haven't looked at this too closely, but I think maybe if you make |
The thing is that currently there isn't a separate class for the scalars. A scalar in my case is just an object of the same kind but with length one. |
Yah I don't see any obvious way to avoid inconsistencies. If this is a serious problem, I'd suggest opening a new issue for dedicated discussion |
black pandas
git diff upstream/master -u -- "*.py" | flake8 --diff
Problem
We currently allow doing arithmetic on a DataFrame, and, for example, a list of Series. The latter gets broadcast with
align_method_FRAME
and this leads to weirdness.Solution
We should raise. There is no definite answer to how such arithmetic should be handled, and the user should just make another DataFrame and add that to the frame instead of doing stuff like
[Series, Series]
.