-
-
Notifications
You must be signed in to change notification settings - Fork 19.2k
Closed
Labels
BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolatenp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate
Description
From #11497. Found inconsistencyr regarding fillna downcasting.
I understand fillna(downcast=None) should downcast values appropriately. It doesn't work on float dtype.
# NG
pd.Series([1, 2, np.nan, 4]).fillna(3)
#0 1
#1 2
#2 3
#3 4
# dtype: float64
# OK
pd.Series([1, 2, np.nan, 4], dtype=object).fillna(3)
#0 1
#1 2
#2 3
#3 4
# dtype: int64
Based on the internal logic, downcast can accept dtype. It works on float, but not on object.
# OK
pd.Series([1, 2, np.nan, 4]).fillna(3, downcast='int')
#0 1
#1 2
#2 3
#3 4
# dtype: int64
# NG
pd.Series([1, 2, np.nan, 4], dtype=object).fillna(3, downcast='int')
#0 1
#1 2
#2 3
#3 4
# dtype: object
I understood the expected behavior as below:
- all dtypes should be downcast by default (downcast=None)
- if any dtype is passed via
downcastkw, downcast to the specified dtype if possible. downcast=Falsewill not perform downcast.- Add
Index.fillnato API (follow-up of ENH: Add Index.fillna #11343)
Metadata
Metadata
Assignees
Labels
BugMissing-datanp.nan, pd.NaT, pd.NA, dropna, isnull, interpolatenp.nan, pd.NaT, pd.NA, dropna, isnull, interpolate