Repository navigation
Description
What happened?
I was trying to combine two data arrays with misaligned coordinates using xr.combine_by_coords(..., join="outer"). One of the coordinates has datetime objects with time zone information in it. However, in this case, combine_by_coords crashes with TypeError: Cannot interpret 'datetime64[us, UTC]' as a data type.
What did you expect to happen?
The data arrays should be combined successfully.
Minimal Complete Verifiable Example
# /// script
# requires-python = ">=3.11"
# dependencies = [
# "xarray[complete]@git+https://github.com/pydata/xarray.git@main",
# "pytz>=2026.1.post1",
# ]
# ///
import datetime
import pytz
import xarray as xr
arrs = []
for i in range(2):
# leaving out the .astimezone(...) works
t = datetime.datetime(2026, 3, 1, hour=i).astimezone(pytz.timezone("UTC"))
da = xr.DataArray().expand_dims(
time=[t],
dummy=[i], # changing to dummy=[0] or leaving this out works
)
arrs.append(da)
xr.combine_by_coords(arrs, join="outer")Steps to reproduce
Run the MCVE script using uv run.
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
Traceback (most recent call last):
File ".../code/misc/bug-reports/2026-03-16-xarray-combine_by_coords-timezone/main-standalone.py", line 25, in <module>
xr.combine_by_coords(arrs, join="outer")
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/combine.py", line 1097, in combine_by_coords
combined_temp_dataset = _combine_single_variable_hypercube(
temp_datasets,
...<5 lines>...
combine_attrs=combine_attrs,
)
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/combine.py", line 775, in _combine_single_variable_hypercube
concatenated = _combine_nd(
combined_ids,
...<6 lines>...
combine_attrs=combine_attrs,
)
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/combine.py", line 262, in _combine_nd
combined_ids = _combine_all_along_first_dim(
combined_ids,
...<6 lines>...
combine_attrs=combine_attrs,
)
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/combine.py", line 294, in _combine_all_along_first_dim
new_combined_ids[new_id] = _combine_1d(
~~~~~~~~~~~^
datasets,
^^^^^^^^^
...<6 lines>...
combine_attrs=combine_attrs,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/combine.py", line 324, in _combine_1d
combined = concat(
datasets,
...<6 lines>...
combine_attrs=combine_attrs,
)
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/concat.py", line 325, in concat
return _dataset_concat(
objs,
...<8 lines>...
create_index_for_new_dim=create_index_for_new_dim,
)
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/concat.py", line 645, in _dataset_concat
align(
~~~~~^
*datasets, join=join, copy=False, exclude=[dim_name], fill_value=fill_value
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/alignment.py", line 967, in align
aligner.align()
~~~~~~~~~~~~~^^
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/alignment.py", line 659, in align
self.align_indexes()
~~~~~~~~~~~~~~~~~~^^
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/structure/alignment.py", line 485, in align_indexes
joined_index = joiner(matching_indexes)
File ".../.cache/uv/environments-v2/main-standalone-c4d81dcd74734a38/lib/python3.13/site-packages/xarray/core/indexes.py", line 907, in join
coord_dtype = np.result_type(self.coord_dtype, other.coord_dtype)
TypeError: Cannot interpret 'datetime64[us, UTC]' as a data typeAnything else we need to know?
If there is no time zone information (i.e. no .astimezone(...) in the MVCE), the crash doesn't occur. If the join is one-dimensional (i.e. the dummy coordinate is equal or left out in the MVCE), the crash doesn't occur.
Environment
Details
INSTALLED VERSIONS
commit: None
python: 3.13.5 (main, Jun 12 2025, 12:40:22) [Clang 20.1.4 ]
python-bits: 64
OS: Linux
OS-release: 6.18.16-100.fc42.x86_64
machine: x86_64
processor:
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: ('en_US', 'UTF-8')
libhdf5: 1.14.6
libnetcdf: 4.9.3
xarray: 2026.2.1.dev23+g885e8d111
pandas: 3.0.1
numpy: 2.4.3
scipy: 1.17.1
netCDF4: 1.7.4
pydap: 3.5.9
h5netcdf: 1.8.1
h5py: 3.16.0
zarr: 3.1.5
cftime: 1.6.5
nc_time_axis: 1.4.1
iris: None
bottleneck: 1.6.0
dask: 2026.1.2
distributed: 2026.1.2
matplotlib: 3.10.8
cartopy: 0.25.0
seaborn: 0.13.2
numbagg: 0.9.4
fsspec: 2026.2.0
cupy: None
pint: None
sparse: 0.18.0
flox: 0.11.2
numpy_groupies: 0.11.3
setuptools: None
pip: None
conda: None
pytest: None
mypy: None
IPython: None
sphinx: None
Activity
FocusMode-coder commentedon Mar 16, 2026
mgunyho commentedon Mar 17, 2026
Probably the same issue, but there is also an exception when combining datasets with variables that have disjoint coordinates:
jsignell commentedon Mar 17, 2026
Thanks for taking the time to write this up @mgunyho. It looks like a bug having to do with the handling of pandas.arrays.DatetimeArray (which is the type of
da.time.dataonce the DataArray is constructed).@ilan-gold I tried to dig through the code and figure out what the intention is for this case, but I can't quite tell.
dcherian commentedon Mar 17, 2026
We shouldn't be hanging on to timezone in
.data. I fail to understand how this keep happening!Alternatively, maybe we should just bite the bullet and get timezones working with pandas'
DatetimeArrayilan-gold commentedon Mar 17, 2026
I am happy to fix :) Should have something posted by tomorrow!
ilan-gold commentedon Mar 18, 2026
Why not?
dcherian commentedon Mar 18, 2026
Is
DatetimeArrayan allowed type already? I didn't think so but haven't followed closely in a while.ilan-gold commentedon Mar 18, 2026
We disallowed it on incoming
pandas.DataFrameobjects a while back to preserve some baked-in behavior that used to exist inxarray. I asked in the PR description of doing that what was going on there, but didn't follow up to try to find out.But otherwise, it's allowed i.e., you are allowed to construct an
xarrayobject directly using them. Otherwise I think a lot of the datetime preservation for coords would probably start failing (a guess).amotl commentedon May 15, 2026
Hi. We don't know if this is related, but we are observing similar problems starting with xarray 2025.1.2. Any suggestion how to improve is much welcome.