MCPcopy Index your code
hub / github.com/pydata/xarray / test_concat_join_kwarg

Method test_concat_join_kwarg

xarray/tests/test_concat.py:734–773  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

732 concat([Dataset({"x": 0}), Dataset({}, {"x": 1})], dim="z")
733
734 def test_concat_join_kwarg(self) -> None:
735 ds1 = Dataset({"a": (("x", "y"), [[0]])}, coords={"x": [0], "y": [0]})
736 ds2 = Dataset({"a": (("x", "y"), [[0]])}, coords={"x": [1], "y": [0.0001]})
737
738 expected: dict[JoinOptions, Any] = {}
739 expected["outer"] = Dataset(
740 {"a": (("x", "y"), [[0, np.nan], [np.nan, 0]])},
741 {"x": [0, 1], "y": [0, 0.0001]},
742 )
743 expected["inner"] = Dataset(
744 {"a": (("x", "y"), [[], []])}, {"x": [0, 1], "y": []}
745 )
746 expected["left"] = Dataset(
747 {"a": (("x", "y"), np.array([0, np.nan], ndmin=2).T)},
748 coords={"x": [0, 1], "y": [0]},
749 )
750 expected["right"] = Dataset(
751 {"a": (("x", "y"), np.array([np.nan, 0], ndmin=2).T)},
752 coords={"x": [0, 1], "y": [0.0001]},
753 )
754 expected["override"] = Dataset(
755 {"a": (("x", "y"), np.array([0, 0], ndmin=2).T)},
756 coords={"x": [0, 1], "y": [0]},
757 )
758
759 with pytest.raises(ValueError, match=r"cannot align.*exact.*dimensions.*'y'"):
760 actual = concat([ds1, ds2], join="exact", dim="x")
761
762 for join, expected_item in expected.items():
763 actual = concat([ds1, ds2], join=join, dim="x")
764 assert_equal(actual, expected_item)
765
766 # regression test for #3681
767 actual = concat(
768 [ds1.drop_vars("x"), ds2.drop_vars("x")], join="override", dim="y"
769 )
770 expected2 = Dataset(
771 {"a": (("x", "y"), np.array([0, 0], ndmin=2))}, coords={"y": [0, 0.0001]}
772 )
773 assert_identical(actual, expected2)
774
775 @pytest.mark.parametrize(
776 "combine_attrs, var1_attrs, var2_attrs, expected_attrs, expect_exception",

Callers

nothing calls this directly

Calls 6

drop_varsMethod · 0.95
DatasetClass · 0.90
concatFunction · 0.90
assert_equalFunction · 0.90
assert_identicalFunction · 0.90
itemsMethod · 0.80

Tested by

no test coverage detected