Repository navigation
FutureWarning: decode_timedelta will default to False rather than None #10382
Description
What happened?
I followed some tutorial/generated code to try out accessing weather forecast data. It does seem to work but prints a long warning message in the middle of my program output:
C:\Users...\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\cfgrib\xarray_plugin.py:131: FutureWarning: In a future version of xarray decode_timedelta will default to False rather than None. To silence this warning, set decode_timedelta to True, False, or a 'CFTimedeltaCoder' instance.
What did you expect to happen?
Nothing?
Minimal Complete Verifiable Example
import os
import bz2
import requests
import xarray as xr
import numpy as np
import pandas as pd
from scipy.interpolate import griddata
# Parameter
run_date = "20250601"
run_hour = "09"
forecast_hour = "001"
base_url = f"https://opendata.dwd.de/weather/nwp/icon-d2/grib/{run_hour}/t_2m/"
filename = f"icon-d2_germany_regular-lat-lon_single-level_{run_date}{run_hour}_{forecast_hour}_2d_t_2m.grib2.bz2"
grib_bz2_url = base_url + filename
grib_outfile = "t2m.grib2"
# Koordinaten der Orte (Breite, Länge)
locations = {
"Berlin": (52.52, 13.405),
"München": (48.137, 11.575),
}
# Download und Dekomprimierung
def download_grib_bz2(url, outfile):
print(f"Lade herunter: {url}")
r = requests.get(url)
if r.status_code != 200:
raise Exception(f"Fehler beim Download: {r.status_code}")
decompressed = bz2.decompress(r.content)
with open(outfile, "wb") as f:
f.write(decompressed)
print(f"Gespeichert als: {outfile}")
# Extrahiere Temperatur für Koordinaten
def extract_temperature(gribfile, coords):
ds = xr.open_dataset(gribfile, engine="cfgrib")
lat = ds.latitude.values
lon = ds.longitude.values
temp = ds.t2m.values - 273.15 # Kelvin -> Celsius
lon_grid, lat_grid = np.meshgrid(lon, lat)
flat_points = np.column_stack((lat_grid.ravel(), lon_grid.ravel()))
flat_values = temp.ravel()
results = {}
for city, (la, lo) in coords.items():
val = griddata(flat_points, flat_values, (la, lo), method='linear')
results[city] = round(float(val), 2)
return results
# Ausführen
download_grib_bz2(grib_bz2_url, grib_outfile)
temperatures = extract_temperature(grib_outfile, locations)
df = pd.DataFrame.from_dict(temperatures, orient="index", columns=["Temp (°C)"])
print(df)MVCE confirmation
- Minimal example — the example is as focused as reasonably possible to demonstrate the underlying issue in xarray.
- Complete example — the example is self-contained, including all data and the text of any traceback.
- Verifiable example — the example copy & pastes into an IPython prompt or Binder notebook, returning the result.
- New issue — a search of GitHub Issues suggests this is not a duplicate.
- Recent environment — the issue occurs with the latest version of xarray and its dependencies.
Relevant log output
Anything else we need to know?
I have no idea whether the code is minimal. I don't know where the issue comes from so I cannot trim it down.
It should run as-is. Maybe the PIP packages xarray, requests, scipy, cfgrib need to be installed.
Python version is 3.13.3 on Windows 11. Nothing newer is available now.
Environment
Details
INSTALLED VERSIONS ------------------ commit: None python: 3.13.3 (tags/v3.13.3:6280bb5, Apr 8 2025, 14:47:33) [MSC v.1943 64 bit (AMD64)] python-bits: 64 OS: Windows OS-release: 11 machine: AMD64 processor: AMD64 Family 25 Model 97 Stepping 2, AuthenticAMD byteorder: little LC_ALL: None LANG: None LOCALE: ('de_DE', 'cp1252') libhdf5: None libnetcdf: Nonexarray: 2025.4.0
pandas: 2.2.3
numpy: 2.2.6
scipy: 1.15.3
netCDF4: None
pydap: None
h5netcdf: None
h5py: None
zarr: None
cftime: 1.6.4.post1
nc_time_axis: None
iris: None
bottleneck: None
dask: None
distributed: None
matplotlib: None
cartopy: None
seaborn: None
numbagg: None
fsspec: None
cupy: None
pint: None
sparse: None
flox: None
numpy_groupies: None
setuptools: None
pip: 25.1.1
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None
Activity
max-sixty commentedon Jun 1, 2025
check out https://stackoverflow.com/help/minimal-reproducible-example
spencerkclark commentedon Jun 1, 2025
The warning stems from the fact that the file contains a variable that contains a timedelta-like units attribute—in this case
stephas aunitsattribute of"hours". It is emitted during thexr.open_datasetcall.We are in the process of changing xarray's default behavior upon opening datasets with these variables. Xarray currently automatically decodes them into
np.timedelta64values, which has been deemed undesirable (#1621). In the future we are planning to leave these variables alone by default, hence the warning.In the next version of xarray, the warning will be a bit more informative (though perhaps it could be improved further by calling out at least one variable that triggered the warning):
If the
dtypeof this particular variable is unimportant, you are free to ignore the warning. You can also silence the warning by settingdecode_timedeltato something other thanNoneinxr.open_dataset. For example, if you would like to persist the existing default behavior you could usexr.open_dataset(..., decode_timedelta=True).kmuehlbauer commentedon Jun 3, 2025
@ygoe Please let us know whether @spencerkclark's comment helps in your case or if we can improve the warning message beyond his suggestion.
ygoe commentedon Jun 8, 2025
Yes, the suggestion in the last sentence resolved the issue. But then I stopped using it again because the whole weather forecast data thing grew over my head very quickly. Met offices make it really hard to use their publicly provided data.☹️ So I won't be able to observe the future behaviour.
Explicitly pass decode_timedelta=True to decode_cf, to fix a FutureWa…
kmuehlbauer commentedon Feb 11, 2026
@spencerkclark Would it make sense to finalize the deprecation?
spencerkclark commentedon Feb 12, 2026
Indeed it has been a year! It would be nice to remove this noisy warning. I will try to take care of it in the next couple days.
Human gold patch for pydata__xarray-11173