Skip to content

convert_calendar adds a time dimension to all variables #10266

@RondeauG

Description

@RondeauG

What happened?

ds.convert_calendar will add a time dimension to all data_vars, even those that did not depend on it.

What did you expect to happen?

No response

Minimal Complete Verifiable Example

import xarray as xr
ds = xr.tutorial.open_dataset("air_temperature")
# Create a non-time dependent variable
ds["other"] = ds["air"].isel(time=0).drop_vars("time")
out = ds.convert_calendar("standard")


`ds`

<xarray.Dataset> Size: 31MB
Dimensions:  (lat: 25, time: 2920, lon: 53)
Coordinates:
  * lat      (lat) float32 100B 75.0 72.5 70.0 67.5 65.0 ... 22.5 20.0 17.5 15.0
  * lon      (lon) float32 212B 200.0 202.5 205.0 207.5 ... 325.0 327.5 330.0
  * time     (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00
Data variables:
    air      (time, lat, lon) float64 31MB 241.2 242.5 243.5 ... 296.2 295.7
    other    (lat, lon) float64 11kB 241.2 242.5 243.5 ... 296.9 296.8 296.6
Attributes:
    Conventions:  COARDS
    title:        4x daily NMC reanalysis (1948)
    description:  Data is from NMC initialized reanalysis\n(4x/day).  These a...
    platform:     Model
    references:   http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly...


`out`

<xarray.Dataset> Size: 62MB
Dimensions:  (time: 2920, lat: 25, lon: 53)
Coordinates:
  * lat      (lat) float32 100B 75.0 72.5 70.0 67.5 65.0 ... 22.5 20.0 17.5 15.0
  * lon      (lon) float32 212B 200.0 202.5 205.0 207.5 ... 325.0 327.5 330.0
  * time     (time) datetime64[ns] 23kB 2013-01-01 ... 2014-12-31T18:00:00
Data variables:
    air      (time, lat, lon) float64 31MB 241.2 242.5 243.5 ... 296.2 295.7
    other    (lat, lon, time) float64 31MB 241.2 241.2 241.2 ... 296.6 296.6
Attributes:
    Conventions:  COARDS
    title:        4x daily NMC reanalysis (1948)
    description:  Data is from NMC initialized reanalysis\n(4x/day).  These a...
    platform:     Model
    references:   http://www.esrl.noaa.gov/psd/data/gridded/data.ncep.reanaly...

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?

No response

Environment

INSTALLED VERSIONS ------------------ commit: None python: 3.12.10 | packaged by conda-forge | (main, Apr 10 2025, 22:21:13) [GCC 13.3.0] python-bits: 64 OS: Linux OS-release: 3.10.0-1160.105.1.el7.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.14.3 libnetcdf: 4.9.2 xarray: 2025.3.0 pandas: 2.2.3 numpy: 2.2.5 scipy: 1.15.2 netCDF4: 1.7.2 pydap: 3.5.4 h5netcdf: 1.6.1 h5py: 3.13.0 zarr: 2.18.7 cftime: 1.6.4 nc_time_axis: 1.4.1 iris: None bottleneck: 1.4.2 dask: 2025.4.0 distributed: 2025.4.0 matplotlib: 3.10.1 cartopy: 0.24.0 seaborn: None numbagg: None fsspec: 2025.3.2 cupy: None pint: 0.24.4 sparse: 0.16.0 flox: 0.10.1 numpy_groupies: 0.11.2 setuptools: 79.0.1 pip: 25.0.1 conda: None pytest: 8.3.5 mypy: 1.15.0 IPython: 9.1.0 sphinx: 8.1.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugneeds triageIssue that has not been reviewed by xarray team member

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions