(self)
| 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 |
nothing calls this directly
no test coverage detected