Closed
Description
-
I have checked that this issue has not already been reported.
-
I have confirmed this bug exists on the latest version of pandas.
-
(optional) I have confirmed this bug exists on the master branch of pandas.
Note: Please read this guide detailing how to provide the necessary information for us to reproduce your bug.
Code Sample, a copy-pastable example
>>> s = pd.Series([1, 2, 3], dtype="Int64")
>>> s
0 1
1 2
2 3
dtype: Int64
>>>
>>> s2 = -s
>>>
>>> s2
0 -1
1 -2
2 -3
dtype: Int64
>>>
>>> s[0] = None # assigning None
>>>
>>> s
0 <NA>
1 2
2 3
dtype: Int64
>>>
>>> s2
0 <NA> # <--- expected -1
1 -2
2 -3
dtype: Int64
>>>
>>> s[1] = 10 # assigning a value is ok
>>> s
0 <NA>
1 10
2 3
dtype: Int64
>>>
>>> s2
0 <NA>
1 -2
2 -3
dtype: Int64
>>>
>>> s2[2] = None
>>> s2
0 <NA>
1 -2
2 <NA>
dtype: Int64
>>>
>>> s
0 <NA>
1 10
2 <NA> # expected 3
dtype: Int64
>>>
>>> s.values._data is s2.values._data
False
>>>
>>> s.values._mask is s2.values._mask
True
Problem description
shared mask leads to an inconsistency when assigning a non-null value compared to assigning a null value
also for __invert__
in BaseMaskedArray so will also affect other nullable arrays
Expected Output
Output of pd.show_versions()
[paste the output of pd.show_versions()
here leaving a blank line after the details tag]