Skip to content

Commit 5a72666

Browse files
authored
fix: handle PandasIndex promotion of dtypes (#11244)
* ffix: handle `PandasIndex` promotion of dtypes * chore: mypy
1 parent a1c0617 commit 5a72666

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

xarray/core/indexes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -903,7 +903,8 @@ def join(
903903
else:
904904
# how = "inner"
905905
index = self.index.intersection(other.index)
906-
906+
if is_allowed_extension_array_dtype(index.dtype):
907+
return type(self)(index, self.dim)
907908
coord_dtype = np.result_type(self.coord_dtype, other.coord_dtype)
908909
return type(self)(index, self.dim, coord_dtype=coord_dtype)
909910

xarray/tests/test_combine.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
from __future__ import annotations
22

3+
import datetime
34
import re
45
from itertools import product
56

67
import numpy as np
8+
import pandas as pd
79
import pytest
10+
import pytz
811

912
from xarray import (
1013
DataArray,
@@ -1155,6 +1158,22 @@ def test_combine_by_coords_override_order(self) -> None:
11551158
actual = combine_by_coords([x2, x1], compat="override")
11561159
assert_equal(actual["a"], x2["a"])
11571160

1161+
def test_combine_by_coords_extension_array(self) -> None:
1162+
# regression test for https://github.com/pydata/xarray/issues/11235
1163+
arrs = []
1164+
expected_vals = []
1165+
for i in range(2):
1166+
t = datetime.datetime(2026, 3, 1, hour=i).astimezone(pytz.timezone("UTC"))
1167+
expected_vals += [t]
1168+
da = DataArray().expand_dims(
1169+
time=[t],
1170+
dummy=[i],
1171+
)
1172+
arrs.append(da)
1173+
expected = pd.array(expected_vals)
1174+
result = combine_by_coords(arrs, join="outer")
1175+
pd.testing.assert_extension_array_equal(result["time"].data, expected)
1176+
11581177

11591178
class TestCombineMixedObjectsbyCoords:
11601179
def test_combine_by_coords_mixed_unnamed_dataarrays(self):

0 commit comments

Comments
 (0)