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

Method test_to_dataset_split

xarray/tests/test_dataarray.py:4099–4122  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

4097 actual = named.to_dataset("bar")
4098
4099 def test_to_dataset_split(self) -> None:
4100 array = DataArray(
4101 [[1, 2], [3, 4], [5, 6]],
4102 coords=[("x", list("abc")), ("y", [0.0, 0.1])],
4103 attrs={"a": 1},
4104 )
4105 expected = Dataset(
4106 {"a": ("y", [1, 2]), "b": ("y", [3, 4]), "c": ("y", [5, 6])},
4107 coords={"y": [0.0, 0.1]},
4108 attrs={"a": 1},
4109 )
4110 actual = array.to_dataset("x")
4111 assert_identical(expected, actual)
4112
4113 with pytest.raises(TypeError):
4114 array.to_dataset("x", name="foo")
4115
4116 roundtripped = actual.to_dataarray(dim="x")
4117 assert_identical(array, roundtripped)
4118
4119 array = DataArray([1, 2, 3], dims="x")
4120 expected = Dataset({0: 1, 1: 2, 2: 3})
4121 actual = array.to_dataset("x")
4122 assert_identical(expected, actual)
4123
4124 def test_to_dataset_retains_keys(self) -> None:
4125 # use dates as convenient non-str objects. Not a specific date test

Callers

nothing calls this directly

Calls 5

to_datasetMethod · 0.95
DataArrayClass · 0.90
DatasetClass · 0.90
assert_identicalFunction · 0.90
to_dataarrayMethod · 0.45

Tested by

no test coverage detected