-
-
Notifications
You must be signed in to change notification settings - Fork 18.3k
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
BUG: fillna(0) does not fill NaNs for Float64Arrays #39926
Comments
I don't think that fillna is the issue here. The vaue in C should be pd.NA not np.nan. I am not sure if fillna is supposed to work for np.nan in a Float64 Array. Maybe @jorisvandenbossche can help here? |
@phofl |
I am not sure if this is the expected behavior here, hence I pinged joris. If this is the expected behavior in case of np.nan in Float64Arrays, then we should adjust the documnetation, if not then we got 2 unrelated bugs here. |
Thx, then let's repurpose this:
this should return
and not
|
Could maybe someone rename the issue? |
I think the return of |
In this case forgot what I have said. Did not think about this. |
Indeed, as @simonjayhawkins mentioned, this is still being discussed in #32265. So for now this is a bit "grey area". There are two different aspects being mentioned here (and I think both are still open for discussion):
But so that's discussion for #32265, which is a bit stalled at the moment, but something we need to revive. (let's keep the issue open for now, to have a reference for this aspect if people search for it, until we make a final decision on the topic) |
The OP is right that |
fillna(0) does seem to catch np.nan for me in pandas 1.3.3, however, if using it on a slice of a dataframe inplace doesn't work |
I'm not sure what to make of this, I'm wondering if it's a symptom of something else. >>> df = pd.DataFrame({'a': [0,0], 'b': [0,0]}, dtype=pd.Int64Dtype())
>>> df
a b
0 0 0
1 0 0
>>> df['c'] = df.a / df.b
>>> df
a b c
0 0 0 NaN
1 0 0 NaN
>>> df.replace([pd.NA, np.NaN], 0)
a b c
0 0 0 NaN
1 0 0 NaN
>>> df.iloc[0].c # They print out different values?
<NA> Using >>> df = pd.DataFrame({'a': [0,0], 'b': [0,0]}, dtype=np.dtype('int64'))
>>> df['c'] = df.a / df.b
>>> df
a b c
0 0 0 NaN
1 0 0 NaN
>>> df.replace(np.NaN, 0)
a b c
0 0 0 0.0
1 0 0 0.0
>>> df.fillna(0)
a b c
0 0 0 0.0
1 0 0 0.0 |
Can someone explain what is the difference of Saw in this SO question and I'm having problems with it... |
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
Code Sample, a copy-pastable example
Output:
Problem description
fillna does not work as expected. It do not fill na
Expected Output
Output of
pd.show_versions()
INSTALLED VERSIONS
commit : 7d32926
python : 3.7.9.final.0
python-bits : 64
OS : Windows
OS-release : 10
Version : 10.0.18362
machine : AMD64
processor : Intel64 Family 6 Model 142 Stepping 10, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : None.None
pandas : 1.2.2
numpy : 1.18.3
pytz : 2020.5
dateutil : 2.8.1
pip : 20.3.3
setuptools : 51.3.3.post20210118
Cython : 0.29.21
pytest : 6.2.1
hypothesis : None
sphinx : 3.4.3
blosc : None
feather : None
xlsxwriter : 1.3.7
lxml.etree : 4.6.2
html5lib : 1.1
pymysql : None
psycopg2 : None
jinja2 : 2.11.2
IPython : 7.19.0
pandas_datareader: None
bs4 : 4.9.3
bottleneck : 1.3.2
fsspec : 0.8.3
fastparquet : 0.3.3
gcsfs : None
matplotlib : 3.2.2
numexpr : 2.7.2
odfpy : None
openpyxl : 3.0.6
pandas_gbq : None
pyarrow : 0.16.0
pyxlsb : None
s3fs : None
scipy : 1.5.2
sqlalchemy : 1.3.21
tables : 3.6.1
tabulate : 0.8.7
xarray : None
xlrd : 2.0.1
xlwt : 1.3.0
numba : 0.51.2
The text was updated successfully, but these errors were encountered: