-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Time-based resampling drops lat/lon coordinate metadata #7012
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
Comments
I cannot reproduce this (on master but I don't think we touched this since 2022.06): import xarray as xr
import cf_xarray
air = xr.tutorial.open_dataset("air_temperature")
air.resample(time="MS").mean(dim="time").lat Returns
Would be interesting to get to the bottom of this. (Funny enough - the attrs are not even dropped for |
Ah - I probably don't have flox installed - that could be the reason. |
@mathause You're right! I noticed this first in my builds using "upstream" dependencies (xarray@main, flox@main, cftime@master, bottleneck@master). It might indeed be flox-related! |
cc @dcherian |
Closes pydata#7012 When `use_flox=False`, we pass `keep_attrs=None` to `Data*.reduce`. This ends up delete Dataset and DataArray level attrs but preserves coordinate variable attrs. We now set the default to True always to match the default behaviour of `apply_ufunc` used by `flox.xarray.xarray_reduce`.
Thanks @Zeitsperre and @mathause . I made a bad choice for the default in #6667 . See #7022 for a solution |
What happened?
When performing a DataArray resampling on a time dimension, the metadata attributes of non-affected coordinate variables are dropped. This behaviour breaks compatibility with
cf_xarray
as the coordinate metadata is needed to identify theX
,Y
,Z
coordinates.What did you expect to happen?
Metadata fields of unaffected coordinates (
lat
,lon
,height
) to be preserved.Minimal Complete Verifiable Example
MVCE confirmation
Relevant log output
Anything else we need to know?
Before
After
Environment
INSTALLED VERSIONS
commit: None
python: 3.10.5 | packaged by conda-forge | (main, Jun 14 2022, 07:06:46) [GCC 10.3.0]
python-bits: 64
OS: Linux
OS-release: 5.19.6-200.fc36.x86_64
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_CA.UTF-8
LOCALE: ('en_CA', 'UTF-8')
libhdf5: 1.12.1
libnetcdf: 4.8.1
xarray: 2022.6.0
pandas: 1.3.5
numpy: 1.22.4
scipy: 1.8.1
netCDF4: 1.6.0
pydap: None
h5netcdf: None
h5py: None
Nio: None
zarr: None
cftime: 1.6.2
nc_time_axis: 1.4.1
PseudoNetCDF: None
rasterio: None
cfgrib: None
iris: None
bottleneck: 1.3.5
dask: 2022.6.1
distributed: 2022.6.1
matplotlib: 3.5.2
cartopy: None
seaborn: None
numbagg: None
fsspec: 2022.7.1
cupy: None
pint: 0.19.2
sparse: 0.13.0
flox: 0.5.10.dev8+gfbc2af8
numpy_groupies: 0.9.19
setuptools: 59.8.0
pip: 22.2.1
conda: None
pytest: 7.1.2
IPython: 8.4.0
sphinx: 5.1.1
The text was updated successfully, but these errors were encountered: