Skip to content

Commit 009b154

Browse files
authored
Fix concat scalar coord dtype (#6418)
1 parent 728b648 commit 009b154

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

xarray/core/concat.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ def get_indexes(name):
532532
elif name == dim:
533533
var = ds._variables[name]
534534
if not var.dims:
535-
yield PandasIndex([var.values.item()], dim)
535+
yield PandasIndex([var.values.item()], dim, coord_dtype=var.dtype)
536536

537537
# stack up each variable and/or index to fill-out the dataset (in order)
538538
# n.b. this loop preserves variable order, needed for groupby.

xarray/tests/test_concat.py

+11
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,17 @@ def test_concat_promote_shape(self) -> None:
456456
)
457457
assert_identical(actual, expected)
458458

459+
# regression GH6416 (coord dtype)
460+
time_data1 = np.array(["2022-01-01", "2022-02-01"], dtype="datetime64[ns]")
461+
time_data2 = np.array("2022-03-01", dtype="datetime64[ns]")
462+
time_expected = np.array(
463+
["2022-01-01", "2022-02-01", "2022-03-01"], dtype="datetime64[ns]"
464+
)
465+
objs = [Dataset({}, {"time": time_data1}), Dataset({}, {"time": time_data2})]
466+
actual = concat(objs, "time")
467+
expected = Dataset({}, {"time": time_expected})
468+
assert_identical(actual, expected)
469+
459470
def test_concat_do_not_promote(self) -> None:
460471
# GH438
461472
objs = [

0 commit comments

Comments
 (0)