Skip to content

Commit

Permalink
simplify test
Browse files Browse the repository at this point in the history
  • Loading branch information
hmaarrfk committed Jun 29, 2024
1 parent fd7a76c commit 30a01c8
Showing 1 changed file with 4 additions and 25 deletions.
29 changes: 4 additions & 25 deletions xarray/tests/test_cftimeindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -988,9 +988,10 @@ def test_cftimeindex_calendar_property(calendar, expected):
assert index.calendar == expected


@requires_cftime
def test_cftime_noleap_with_str():
# https://github.com/pydata/xarray/issues/9138
time = xr.cftime_range("2000-01-01", "2006-01-01", freq="D", calendar="noleap")
time = pd.date_range("2000-01-01", "2006-01-01", freq="D")
temperature = np.ones(len(time))
da = xr.DataArray(
data=temperature,
Expand All @@ -999,30 +1000,8 @@ def test_cftime_noleap_with_str():
time=time,
),
)
# works if array is built with cftime
out = da.sel(time=slice("2001", "2002"))
da1 = da.convert_calendar("noleap")
# works if array is built with cftime and converted
out1 = da1.sel(time=slice("2001", "2002"))

time = pd.date_range(
"2000-01-01",
"2006-01-01",
freq="D",
)
temperature = np.ones(len(time))
da2 = xr.DataArray(
data=temperature,
dims=["time"],
coords=dict(
time=time,
),
)
# works if array is built with pandas time
out2 = da2.sel(time=slice("2001", "2002"))
da3 = da2.convert_calendar("noleap")
# fails if array is built with pandas time and convert to noleap
out3 = da3.sel(time=slice("2001", "2002"))
da_noleap = da.convert_calendar("noleap")
da_noleap.sel(time=slice("2001", "2002"))


@requires_cftime
Expand Down

0 comments on commit 30a01c8

Please sign in to comment.