Skip to content
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

interpolate_na drops DataArray attributes #3968

Closed
RobWatersMet opened this issue Apr 13, 2020 · 2 comments · Fixed by #3970
Closed

interpolate_na drops DataArray attributes #3968

RobWatersMet opened this issue Apr 13, 2020 · 2 comments · Fixed by #3970
Labels
topic-metadata Relating to the handling of metadata (i.e. attrs and encoding)

Comments

@RobWatersMet
Copy link

RobWatersMet commented Apr 13, 2020

When performing interpolate_na on a DataArray the attributes are removed. Unless I am doing something incorrect.

MCVE Code Sample

print(dhi_da)
dhi_ds = dhi_ds.interpolate_na(dim='time')
print(dhi_da)

Output first print statement

<xarray.DataArray 'dhi' (south_north: 90, west_east: 90, time: 105408)>
dask.array<rechunk-merge, shape=(90, 90, 105408), dtype=float64, chunksize=(90, 90, 105408), chunktype=numpy.ndarray>
Coordinates:
    lat      (south_north, west_east) float32 dask.array<chunksize=(90, 90), meta=np.ndarray>
    lon      (south_north, west_east) float32 dask.array<chunksize=(90, 90), meta=np.ndarray>
  * time     (time) datetime64[ns] 2016-12-31 ... 2019-01-01T23:50:00.000000064
Dimensions without coordinates: south_north, west_east
Attributes:
    long_name:        Diffuse Horizontal Irradiance
    standard_name:    dhi
    units:            W/m2
    dhi_calc_method:  pvlib.irradiance.erbs

Output secondprint statement

<xarray.DataArray 'dhi' (south_north: 90, west_east: 90, time: 105408)>
dask.array<vectorize_func_interpolate_na, shape=(90, 90, 105408), dtype=float64, chunksize=(90, 90, 105408), chunktype=numpy.ndarray>
Coordinates:
    lat      (south_north, west_east) float32 dask.array<chunksize=(90, 90), meta=np.ndarray>
    lon      (south_north, west_east) float32 dask.array<chunksize=(90, 90), meta=np.ndarray>
  * time     (time) datetime64[ns] 2016-12-31 ... 2019-01-01T23:50:00.000000064
Dimensions without coordinates: south_north, west_east

Problem Description

I do not believe attributes should ever be dropped like this as they typically contain persistent information.

Versions

Output of `xr.show_versions()`

INSTALLED VERSIONS

commit: None
python: 3.7.6 | packaged by conda-forge | (default, Mar 23 2020, 23:03:20)
[GCC 7.3.0]
python-bits: 64
OS: Linux
OS-release: 3.10.0-862.14.4.el7.x86_64
machine: x86_64
processor:
byteorder: little
LC_ALL: C.UTF-8
LANG: C.UTF-8
LOCALE: en_US.UTF-8
libhdf5: 1.10.5
libnetcdf: 4.7.4

xarray: 0.15.1
pandas: 1.0.3
numpy: 1.18.1
scipy: 1.4.1
netCDF4: 1.5.3
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.1.1.2
nc_time_axis: None
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: None
dask: 2.14.0
distributed: 2.14.0
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
setuptools: 46.1.3.post20200325
pip: 20.0.2
conda: 4.8.3
pytest: None
IPython: None
sphinx: None

@TomNicholas TomNicholas added the topic-metadata Relating to the handling of metadata (i.e. attrs and encoding) label Apr 14, 2020
@TomNicholas
Copy link
Member

Hi Rob,

Thanks for flagging this. It was a bug, which I've now fixed in a PR.

My fix adds a keep_attrs argument to interpolate_na in order to be consistent with the rest of the API. That means to preserve the attrs you'll either have to pass keep_attrs=True explicitly, or set the global option with xr.set_options(keep_attrs=True). I would recommend doing the latter, and then please raise another issue if you spot any other methods which don't preserve attrs.

I do not believe attributes should ever be dropped like this as they typically contain persistent information.

I basically agree, but we're discussing the details of whether or not to change to this behaviour as the default over in #3891 .

@RobWatersMet
Copy link
Author

Hi Tom,

thanks for the information and timely response.

Cheers,

Rob

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-metadata Relating to the handling of metadata (i.e. attrs and encoding)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants