xarray-contrib/xarray-tutorial

Warning: saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs

scottyhq opened this issue · 2 comments

@dcherian Doing a bit of cleanup of https://tutorial.xarray.dev/overview/xarray-in-45-min.html#reading-and-writing-files I'm surprised by the serialization warning: Why is it saving floating point data as integer dtype?

import xarray as xr
ds = xr.tutorial.load_dataset("air_temperature")
ds.to_netcdf("my-example-dataset.nc")
/var/folders/gt/fg1fy12n5wg2b027zy5qmcr40000gn/T/ipykernel_90730/1274509432.py:3: SerializationWarning: saving variable air with floating point data as an integer dtype without any _FillValue to use for NaNs
  ds.to_netcdf("my-example-dataset.nc")

ncdump -h says

variables:
	float lat(lat) ;
		lat:standard_name = "latitude" ;
		lat:long_name = "Latitude" ;
		lat:units = "degrees_north" ;
		lat:axis = "Y" ;
	short air(time, lat, lon) ;
		air:long_name = "4xDaily Air temperature at sigma level 995" ;
		air:units = "degK" ;
		air:precision = 2s ;
		air:GRIB_id = 11s ;
		air:GRIB_name = "TMP" ;
		air:var_desc = "Air temperature" ;
		air:dataset = "NMC Reanalysis" ;
		air:level_desc = "Surface" ;
		air:statistic = "Individual Obs" ;
		air:parent_stat = "Other" ;
		air:actual_range = 185.16f, 322.1f ;
		air:scale_factor = 0.01 ;

So it's stored as 16-bit signed integer (short).

ah, right, and mask_and_scale=True by default.

In #110 I added:

To avoid the SerializationWarning you can assign a _FillValue for any NaNs in 'air' array by adding the keyword argument encoding=dict(air={_FillValue=-9999})