Skip to content

Commit c538a23

Browse files
committed
MRC -- Selecting with string for cftime
See discussion in #9138 This commit and pull request mostly serves as a staging group for a potential fix. Test with: ``` pytest xarray/tests/test_cftimeindex.py::test_cftime_noleap_with_str ```
1 parent 42ed6d3 commit c538a23

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

xarray/tests/test_cftimeindex.py

+29
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,35 @@ def test_cftimeindex_calendar_property(calendar, expected):
988988
assert index.calendar == expected
989989

990990

991+
def test_cftime_noleap_with_str():
992+
# https://github.com/pydata/xarray/issues/9138
993+
time=xr.cftime_range('2000-01-01','2006-01-01', freq='D', calendar='noleap')
994+
temperature = np.ones(len(time))
995+
da = xr.DataArray(
996+
data=temperature,
997+
dims=["time"],
998+
coords=dict(time=time,),
999+
)
1000+
# works if array is built with cftime
1001+
out=da.sel(time=slice('2001','2002'))
1002+
da1=da.convert_calendar('noleap')
1003+
# works if array is built with cftime and converted
1004+
out1=da1.sel(time=slice('2001','2002'))
1005+
1006+
time=pd.date_range('2000-01-01','2006-01-01', freq='D',)
1007+
temperature = np.ones(len(time))
1008+
da2 = xr.DataArray(
1009+
data=temperature,
1010+
dims=["time"],
1011+
coords=dict(time=time,),
1012+
)
1013+
# works if array is built with pandas time
1014+
out2=da2.sel(time=slice('2001','2002'))
1015+
da3=da2.convert_calendar('noleap')
1016+
# fails if array is built with pandas time and convert to noleap
1017+
out3=da3.sel(time=slice('2001','2002'))
1018+
1019+
9911020
@requires_cftime
9921021
def test_empty_cftimeindex_calendar_property():
9931022
index = CFTimeIndex([])

0 commit comments

Comments
 (0)