Skip to content

Commit

Permalink
Fix concat with scalar coordinate (wrong index type) (#6443)
Browse files Browse the repository at this point in the history
  • Loading branch information
benbovy authored Apr 6, 2022
1 parent 2eef20b commit facafac
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion xarray/core/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,8 @@ def get_indexes(name):
elif name == dim:
var = ds._variables[name]
if not var.dims:
yield PandasIndex([var.values.item()], dim, coord_dtype=var.dtype)
data = var.set_dims(dim).values
yield PandasIndex(data, dim, coord_dtype=var.dtype)

# stack up each variable and/or index to fill-out the dataset (in order)
# n.b. this loop preserves variable order, needed for groupby.
Expand Down
3 changes: 2 additions & 1 deletion xarray/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ def test_concat_promote_shape(self) -> None:
)
assert_identical(actual, expected)

# regression GH6416 (coord dtype)
# regression GH6416 (coord dtype) and GH6434
time_data1 = np.array(["2022-01-01", "2022-02-01"], dtype="datetime64[ns]")
time_data2 = np.array("2022-03-01", dtype="datetime64[ns]")
time_expected = np.array(
Expand All @@ -466,6 +466,7 @@ def test_concat_promote_shape(self) -> None:
actual = concat(objs, "time")
expected = Dataset({}, {"time": time_expected})
assert_identical(actual, expected)
assert isinstance(actual.indexes["time"], pd.DatetimeIndex)

def test_concat_do_not_promote(self) -> None:
# GH438
Expand Down

0 comments on commit facafac

Please sign in to comment.