-
-
Notifications
You must be signed in to change notification settings - Fork 18.6k
REGR: Fix assignment bug for unary operators #39971
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
3968846
7fa3768
70a8bd8
57b2b27
52bc411
b28c417
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 |
---|---|---|
|
@@ -316,13 +316,13 @@ def __init__(self, values: np.ndarray, mask: np.ndarray, copy: bool = False): | |
super().__init__(values, mask, copy=copy) | ||
|
||
def __neg__(self): | ||
return type(self)(-self._data, self._mask) | ||
return type(self)(-self._data, self._mask.copy()) | ||
|
||
def __pos__(self): | ||
return self | ||
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 should do the same for 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. probably not for a backport. but indeed this needs some discussion to ensure consistency across the codebase. see TimedeltaArray
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. OK, I see, so that's indeed something we should fix more generally. Is there already an issue about it? 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. In the context here I had been thinking that something like 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.
no. will need to create one, since the issue that this PR addresses is slightly different. #39943 is about different arrays sharing a mask, whereas returning self for __pos__, although maybe incorrect, does not create the inconsistencies when assigning null and non-null vales |
||
|
||
def __abs__(self): | ||
return type(self)(np.abs(self._data), self._mask) | ||
return type(self)(np.abs(self._data), self._mask.copy()) | ||
|
||
@classmethod | ||
def _from_sequence( | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,3 +162,16 @@ def test_error_len_mismatch(data, all_arithmetic_operators): | |
s = pd.Series(data) | ||
with pytest.raises(ValueError, match="Lengths must match"): | ||
op(s, other) | ||
|
||
|
||
@pytest.mark.parametrize("op", ["__neg__", "__abs__", "__invert__"]) | ||
@pytest.mark.parametrize( | ||
"values, dtype", [([1, 2, 3], "Int64"), ([True, False, True], "boolean")] | ||
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. you can 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. this is being addressed in #39916, so no action required here |
||
) | ||
def test_unary_op_does_not_propagate_mask(op, values, dtype): | ||
# https://github.com/pandas-dev/pandas/issues/39943 | ||
s = pd.Series(values, dtype=dtype) | ||
result = getattr(s, op)() | ||
expected = result.copy(deep=True) | ||
s[0] = None | ||
tm.assert_series_equal(result, expected) |
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.
For future reference, I think we should generally say something like "nullable integer dtype" instead of "IntegerArray", as most users should never deal / know about IntegerArray
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.
Valid point, I can update this
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. #40019. thanks @dsaxton