Skip to content

Commit

Permalink
fix: Skip previous encoding workaround for fixed xarray versions (#401)
Browse files Browse the repository at this point in the history
* fix: Skip previous encoding workaround for fixed xarray versions

see reported issue pydata/xarray#7691 and pr
pydata/xarray#8713 which was included into xarray v2024.03.0

* Replace workaround by a new xarray lower bound

---------

Co-authored-by: Jonas Hoersch <[email protected]>
  • Loading branch information
coroa and Jonas Hoersch authored Nov 11, 2024
1 parent 8bdae17 commit 481f3af
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
9 changes: 0 additions & 9 deletions atlite/datasets/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,15 +361,6 @@ def retrieve_data(product, chunks=None, tmpdir=None, lock=None, **updates):
logger.debug(f"Adding finalizer for {target}")
weakref.finalize(ds._file_obj._manager, noisy_unlink, target)

# Remove default encoding we get from CDSAPI, which can lead to NaN values after loading with subsequent
# saving due to how xarray handles netcdf compression (only float encoded as short int seem affected)
# Fixes issue by keeping "float32" encoded as "float32" instead of internally saving as "short int", see:
# https://stackoverflow.com/questions/75755441/why-does-saving-to-netcdf-without-encoding-change-some-values-to-nan
# and hopefully fixed soon (could then remove), see https://github.com/pydata/xarray/issues/7691
for v in ds.data_vars:
if ds[v].encoding["dtype"] == "int16":
ds[v].encoding.clear()

return ds


Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ dependencies = [
"pandas>=0.25",
"bottleneck",
"numexpr",
"xarray>=0.20",
"xarray>=2024.03.0",
"netcdf4",
"dask>=2021.10.0",
"toolz",
Expand Down Expand Up @@ -116,4 +116,4 @@ ignore = [
'D415', # First line should end with a period, question mark, or exclamation point
'D417', # Missing argument descriptions in the docstring

]
]

0 comments on commit 481f3af

Please sign in to comment.