From 5a72666b7d6423f01519e798eb12e0c6ed03d720 Mon Sep 17 00:00:00 2001 From: Ilan Gold Date: Fri, 20 Mar 2026 10:44:11 +0100 Subject: [PATCH] fix: handle `PandasIndex` promotion of dtypes (#11244) * ffix: handle `PandasIndex` promotion of dtypes * chore: mypy --- xarray/core/indexes.py | 3 ++- xarray/tests/test_combine.py | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/xarray/core/indexes.py b/xarray/core/indexes.py index 664afc83590..d06951bd527 100644 --- a/xarray/core/indexes.py +++ b/xarray/core/indexes.py @@ -903,7 +903,8 @@ def join( else: # how = "inner" index = self.index.intersection(other.index) - + if is_allowed_extension_array_dtype(index.dtype): + return type(self)(index, self.dim) coord_dtype = np.result_type(self.coord_dtype, other.coord_dtype) return type(self)(index, self.dim, coord_dtype=coord_dtype) diff --git a/xarray/tests/test_combine.py b/xarray/tests/test_combine.py index 2883187e096..df2a45dc64c 100644 --- a/xarray/tests/test_combine.py +++ b/xarray/tests/test_combine.py @@ -1,10 +1,13 @@ from __future__ import annotations +import datetime import re from itertools import product import numpy as np +import pandas as pd import pytest +import pytz from xarray import ( DataArray, @@ -1155,6 +1158,22 @@ def test_combine_by_coords_override_order(self) -> None: actual = combine_by_coords([x2, x1], compat="override") assert_equal(actual["a"], x2["a"]) + def test_combine_by_coords_extension_array(self) -> None: + # regression test for https://github.com/pydata/xarray/issues/11235 + arrs = [] + expected_vals = [] + for i in range(2): + t = datetime.datetime(2026, 3, 1, hour=i).astimezone(pytz.timezone("UTC")) + expected_vals += [t] + da = DataArray().expand_dims( + time=[t], + dummy=[i], + ) + arrs.append(da) + expected = pd.array(expected_vals) + result = combine_by_coords(arrs, join="outer") + pd.testing.assert_extension_array_equal(result["time"].data, expected) + class TestCombineMixedObjectsbyCoords: def test_combine_by_coords_mixed_unnamed_dataarrays(self):