xarray icon indicating copy to clipboard operation
xarray copied to clipboard

better warning message for xarray/core/dataset.py:2060: SerializationWarning

Open raybellwaves opened this issue 3 years ago • 0 comments

Is your feature request related to a problem?

I was trying to store a zarr fstore and I got:

/opt/userenvs/ray.bell/autofront/lib/python3.9/site-packages/xarray/core/dataset.py:2060: SerializationWarning: saving variable None with floating point data as an integer dtype without any _FillValue to use for NaNs
  return to_zarr(  # type: ignore

~~What I was seeing was a time coord which had encoding 'dtype': dtype('int64'). Storing the time this way lost the HH:MM on my datetime array.~~ I think I am seeing 'units': 'days since 2022-MM-DD 00:00:00' whereas it should be hours for my data.

Describe the solution you'd like

The message captures the variable/coord name instead of None

It could offer a solution such as "to store floating point data you could possibly use encoding={variable/coord: {"dtype": float, "_Fillvalue": np.nan}"

Describe alternatives you've considered

No response

Additional context

I'll try to come back and write a MCVE

WIP: you can get the warning message by doing:

ds = xr.tutorial.open_dataset("air_temperature")
ds["time"].encoding # {'units': 'hours since 1800-01-01', 'calendar': 'standard', 'dtype': dtype('float32')}
ds.isel(time=0).to_zarr("tmp0.zarr", mode="w")

/Users/ray/miniconda3/envs/main/lib/python3.9/site-packages/xarray/core/dataset.py:2060: SerializationWarning: saving variable None with floating point data as an integer dtype without any _FillValue to use for NaNs return to_zarr( # type: ignore

My guess if one of lat, lon, time, air is raising that message

Can't find the associated code in the repo that raises this. 2060 is to_zarr AFICT (https://github.com/pydata/xarray/blob/main/xarray/core/dataset.py#L2066)

raybellwaves avatar Jul 27 '22 18:07 raybellwaves