-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
BUG: NA value doesn't match mask condition, still masked #52955
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
Comments
Thanks for the bug report, @shobsi . Yes, this is clearly not the intended behavior. A PR would be welcome. |
Hi, I'm interested in this issue and looked into the code. Lines 9888 to 9890 in 607316c
I thinks here is the suspicious line: it is filling NA values with As for this specific issue, I'm thinking that we can call def where(self, cond, other=np.nan, *, inplace=False, axis=None, level=None):
other = common.apply_if_callable(other, self)
if isinstance(cond, NDFrame):
cond = cond.fillna(True)
return self._where(cond, other, inplace, axis, level) Not sure if this is a neat approach. Though it passed all test cases that either calls |
I think that sound great that you want to take this! I agree that
|
Ah true, thanks for your reminder! I'll open a PR to add those lines in |
take |
@topper-123 I think I may understand now what >>> df = pd.DataFrame(np.random.random((3, 3)), dtype=pd.Float64Dtype())
>>> df[0][0] = pd.NA
>>> df
0 1 2
0 <NA> 0.609241 0.419094
1 0.274784 0.342904 0.026101
2 0.670259 0.218889 0.177126
>>> df[df >= 0.5] = 0
>>> df
0 1 2
0 <NA> 0.0 0.419094
1 0.274784 0.342904 0.026101
2 0.0 0.218889 0.177126 But still I doubt this will cause some problems. |
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Series.mask API is masking NA which does not match the mask condition. See the repro example.
Expected Behavior
Installed Versions
pd.__version__
'2.0.1'
The text was updated successfully, but these errors were encountered: