fillna on dataset converts all variables to float
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 4.2k
- Forks
- 1.4k
- Avg merge
- 2d 15h
- Merged PRs (30d)
- 14
Description
MCVE Code Sample
xr.Dataset(
{
"A": ("x", [np.nan, 2, np.nan, 0]),
"B": ("x", [3, 4, np.nan, 1]),
"C": ("x", [True, True, False, False]),
"D": ("x", [np.nan, 3, np.nan, 4])
},
coords={"x": [0, 1, 2, 3]}
).fillna(value={"A": 0})
<xarray.Dataset>
Dimensions: (x: 4)
Coordinates:
* x (x) int64 0 1 2 3
Data variables:
A (x) float64 0.0 2.0 0.0 0.0
B (x) float64 3.0 4.0 nan 1.0
C (x) float64 1.0 1.0 0.0 0.0
D (x) float64 nan 3.0 nan 4.0
Expected Output
<xarray.Dataset>
Dimensions: (x: 4)
Coordinates:
* x (x) int64 0 1 2 3
Data variables:
A (x) float64 0.0 2.0 0.0 0.0
B (x) float64 3.0 4.0 nan 1.0
C (x) bool True True False False
D (x) float64 nan 3.0 nan 4.0
Problem Description
I'd like to use fillna to replace NaN's in some of a Dataset's variables.
However, fillna unexpectably converts all variables to float, even if they are boolean or integers.
Would it be possible to apply fillna only on float / object types and consider the value argument, if I only want to apply fillna to a subset of the dataset?
Output of xr.show_versions()
INSTALLED VERSIONS
commit: None
python: 3.7.4 (default, Aug 13 2019, 20:35:49)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 3.10.0-957.27.2.el7.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.4
libnetcdf: 4.6.1
xarray: 0.14.0
pandas: 0.25.1
numpy: 1.17.2
scipy: 1.3.1
netCDF4: 1.4.2
pydap: None
h5netcdf: 0.7.4
h5py: 2.9.0
Nio: None
zarr: 2.3.2
cftime: 1.0.3.4
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2.5.2
distributed: 2.5.2
matplotlib: 3.1.1
cartopy: None
seaborn: 0.9.0
numbagg: None
setuptools: 41.4.0
pip: 19.2.3
conda: None
pytest: 5.0.1
IPython: 7.8.0
sphinx: None
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start from the Dataset.fillna entry point and reproduce the supplied MCVE with the listed Python, NumPy, pandas, and xarray versions. Check how applying a value to variable A affects the other variables, then add coverage for the expected result: A is filled while boolean C remains boolean and unrelated variables retain their types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100