From beb665a7109bdb627aa66ee277fd87edc195356d Mon Sep 17 00:00:00 2001 From: TomNicholas Date: Wed, 27 Mar 2024 22:05:54 -0400 Subject: [PATCH] add regression tests --- xarray/tests/test_coordinates.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/xarray/tests/test_coordinates.py b/xarray/tests/test_coordinates.py index 40743194ce6..aed2f37700e 100644 --- a/xarray/tests/test_coordinates.py +++ b/xarray/tests/test_coordinates.py @@ -1,5 +1,6 @@ from __future__ import annotations +import numpy as np import pandas as pd import pytest @@ -8,7 +9,7 @@ from xarray.core.dataarray import DataArray from xarray.core.dataset import Dataset from xarray.core.indexes import PandasIndex, PandasMultiIndex -from xarray.core.variable import IndexVariable +from xarray.core.variable import IndexVariable, Variable from xarray.tests import assert_identical, source_ndarray @@ -69,6 +70,12 @@ def test_init_dim_sizes_conflict(self) -> None: with pytest.raises(ValueError): Coordinates(coords={"foo": ("x", [1, 2]), "bar": ("x", [1, 2, 3, 4])}) + def test_init_var_shares_name_with_dim(self) -> None: + # regression test for GH #8883 + var = Variable(data=np.arange(6).reshape(2, 3), dims=["x", "y"]) + with pytest.raises(ValueError): + Coordinates(coords={"x": var}, indexes={}) + def test_from_pandas_multiindex(self) -> None: midx = pd.MultiIndex.from_product([["a", "b"], [1, 2]], names=("one", "two")) coords = Coordinates.from_pandas_multiindex(midx, "x")