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

Method test_constructor

xarray/tests/test_dataset.py:475–495  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

473 buf.close()
474
475 def test_constructor(self) -> None:
476 x1 = ("x", 2 * np.arange(100))
477 x2 = ("x", np.arange(1000))
478 z = (["x", "y"], np.arange(1000).reshape(100, 10))
479
480 with pytest.raises(ValueError, match=r"conflicting sizes"):
481 Dataset({"a": x1, "b": x2})
482 with pytest.raises(TypeError, match=r"tuple of form"):
483 Dataset({"x": (1, 2, 3, 4, 5, 6, 7)})
484 with pytest.raises(ValueError, match=r"already exists as a scalar"):
485 Dataset({"x": 0, "y": ("x", [1, 2, 3])})
486
487 # nD coordinate variable "x" sharing name with dimension
488 actual = Dataset({"a": x1, "x": z})
489 assert "x" not in actual.xindexes
490 _assert_internal_invariants(actual, check_default_indexes=True)
491
492 # verify handling of DataArrays
493 expected = Dataset({"x": x1, "z": z})
494 actual = Dataset({"z": expected["z"]})
495 assert_identical(expected, actual)
496
497 def test_constructor_dataset_as_data_vars_raises(self) -> None:
498 ds = Dataset({"x": ("x", [1, 2, 3])}, attrs={"key": "value"})

Callers

nothing calls this directly

Calls 4

DatasetClass · 0.90
assert_identicalFunction · 0.90
arangeMethod · 0.80

Tested by

no test coverage detected