Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmonize returned multi-indexed indexes when applying concat along new dimension #6889

Merged
merged 11 commits into from
Aug 25, 2022
2 changes: 1 addition & 1 deletion xarray/core/concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,7 @@ def _dataset_concat(
)

# determine which variables to merge, and then merge them according to compat
variables_to_merge = (coord_names | data_names) - concat_over - dim_names
variables_to_merge = (coord_names | data_names) - concat_over - unlabeled_dims

result_vars = {}
result_indexes = {}
Expand Down
8 changes: 8 additions & 0 deletions xarray/tests/test_concat.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,14 @@ def test_concat_multiindex(self) -> None:
assert expected.equals(actual)
assert isinstance(actual.x.to_index(), pd.MultiIndex)

def test_concat_along_new_dim_multiindex(self) -> None:
x = pd.MultiIndex.from_product([[1, 2, 3], ["a", "b"]])
ds = Dataset(coords={"x": x})
actual = concat([ds], "new")
assert isinstance(actual.x.to_index(), pd.MultiIndex)
for k, idx in actual.indexes.items():
assert idx is actual.indexes["x"]
FabianHofmann marked this conversation as resolved.
Show resolved Hide resolved

@pytest.mark.parametrize("fill_value", [dtypes.NA, 2, 2.0, {"a": 2, "b": 1}])
def test_concat_fill_value(self, fill_value) -> None:
datasets = [
Expand Down