MCPcopy
hub / github.com/pydata/xarray / test_virtual_variables_time

Method test_virtual_variables_time

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

Source from the content-addressed store, hash-verified

4638 assert_identical(expected2, actual2)
4639
4640 def test_virtual_variables_time(self) -> None:
4641 # access virtual variables
4642 data = create_test_data()
4643 index = data.variables["time"].to_index()
4644 assert isinstance(index, pd.DatetimeIndex)
4645 assert_array_equal(data["time.month"].values, index.month)
4646 assert_array_equal(data["time.season"].values, "DJF")
4647 # test virtual variable math
4648 assert_array_equal(data["time.dayofyear"] + 1, 2 + np.arange(20))
4649 assert_array_equal(np.sin(data["time.dayofyear"]), np.sin(1 + np.arange(20)))
4650 # ensure they become coordinates
4651 expected = Dataset({}, {"dayofyear": data["time.dayofyear"]})
4652 actual = data[["time.dayofyear"]]
4653 assert_equal(expected, actual)
4654 # non-coordinate variables
4655 ds = Dataset({"t": ("x", pd.date_range("2000-01-01", periods=3))})
4656 assert (ds["t.year"] == 2000).all()
4657
4658 def test_virtual_variable_same_name(self) -> None:
4659 # regression test for GH367

Callers

nothing calls this directly

Calls 7

create_test_dataFunction · 0.90
DatasetClass · 0.90
assert_equalFunction · 0.90
arangeMethod · 0.80
sinMethod · 0.80
to_indexMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected