Skip to content

FutureWarning: decode_timedelta will default to False rather than None #10382

Open
@ygoe

Description

@ygoe

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

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: None

xarray: 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs mcvehttps://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions