|
4 | 4 | import pandas as pd |
5 | 5 | import pytest |
6 | 6 |
|
7 | | -from xarray import CFTimeIndex, DataArray, infer_freq |
| 7 | +from xarray import CFTimeIndex, DataArray, Dataset, infer_freq |
8 | 8 | from xarray.coding.calendar_ops import convert_calendar, interp_calendar |
9 | 9 | from xarray.coding.cftime_offsets import date_range |
10 | 10 | from xarray.testing import assert_identical |
@@ -63,6 +63,24 @@ def test_convert_calendar(source, target, use_cftime, freq): |
63 | 63 | np.testing.assert_array_equal(conv.time, expected_times) |
64 | 64 |
|
65 | 65 |
|
| 66 | +def test_convert_calendar_dataset(): |
| 67 | + # Check that variables without a time dimension are not modified |
| 68 | + src = DataArray( |
| 69 | + date_range("2004-01-01", "2004-12-31", freq="D", calendar="standard"), |
| 70 | + dims=("time",), |
| 71 | + name="time", |
| 72 | + ) |
| 73 | + da_src = DataArray( |
| 74 | + np.linspace(0, 1, src.size), dims=("time",), coords={"time": src} |
| 75 | + ).expand_dims(lat=[0, 1]) |
| 76 | + ds_src = Dataset({"hastime": da_src, "notime": (("lat",), [0, 1])}) |
| 77 | + |
| 78 | + conv = convert_calendar(ds_src, "360_day", align_on="date") |
| 79 | + |
| 80 | + assert conv.time.dt.calendar == "360_day" |
| 81 | + assert_identical(ds_src.notime, conv.notime) |
| 82 | + |
| 83 | + |
66 | 84 | @pytest.mark.parametrize( |
67 | 85 | "source,target,freq", |
68 | 86 | [ |
|
0 commit comments