Skip to content

Commit

Permalink
fix: Skip previous encoding workaround for fixed xarray versions
Browse files Browse the repository at this point in the history
see reported issue pydata/xarray#7691 and pr
pydata/xarray#8713 which was included into xarray v2024.03.0
  • Loading branch information
Jonas Hoersch committed Nov 1, 2024
1 parent 5d974d1 commit 9bd3014
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions atlite/datasets/era5.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import os
import warnings
import weakref
from importlib.metadata import version
from tempfile import mkstemp

import cdsapi
Expand All @@ -21,6 +22,7 @@
from dask import compute, delayed
from dask.array import arctan2, sqrt
from numpy import atleast_1d
from packaging.version import parse

from atlite.gis import maybe_swap_spatial_dims
from atlite.pv.solar_position import SolarPosition
Expand Down Expand Up @@ -365,10 +367,12 @@ def retrieve_data(product, chunks=None, tmpdir=None, lock=None, **updates):
# 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()
# see https://github.com/pydata/xarray/issues/7691 and https://github.com/pydata/xarray/pull/8713
# Fix was included in v2024.03.0
if parse(version("xarray")) < parse("2024.03.0"):
for v in ds.data_vars:
if ds[v].encoding["dtype"] == "int16":
ds[v].encoding.clear()

return ds

Expand Down

0 comments on commit 9bd3014

Please sign in to comment.