@@ -1845,7 +1845,6 @@ def test_groupby_fastpath_for_monotonic(self, use_flox: bool) -> None:
1845
1845
1846
1846
class TestDataArrayResample :
1847
1847
@pytest .mark .parametrize ("shuffle" , [True , False ])
1848
- @pytest .mark .parametrize ("use_cftime" , [True , False ])
1849
1848
@pytest .mark .parametrize (
1850
1849
"resample_freq" ,
1851
1850
[
@@ -1906,12 +1905,8 @@ def resample_as_pandas(array, *args, **kwargs):
1906
1905
with pytest .raises (ValueError ):
1907
1906
reverse .resample (time = resample_freq ).mean ()
1908
1907
1909
- @pytest .mark .parametrize ("use_cftime" , [True , False ])
1910
1908
def test_resample_doctest (self , use_cftime : bool ) -> None :
1911
1909
# run the doctest example here so we are not surprised
1912
- if use_cftime and not has_cftime :
1913
- pytest .skip ()
1914
-
1915
1910
da = xr .DataArray (
1916
1911
np .array ([1 , 2 , 3 , 1 , 2 , np .nan ]),
1917
1912
dims = "time" ,
@@ -1947,8 +1942,10 @@ def func(arg1, arg2, arg3=0.0):
1947
1942
actual = da .resample (time = "D" ).map (func , args = (1.0 ,), arg3 = 1.0 )
1948
1943
assert_identical (actual , expected )
1949
1944
1950
- def test_resample_first (self ) -> None :
1951
- times = pd .date_range ("2000-01-01" , freq = "6h" , periods = 10 )
1945
+ def test_resample_first_last (self , use_cftime ) -> None :
1946
+ times = xr .date_range (
1947
+ "2000-01-01" , freq = "6h" , periods = 10 , use_cftime = use_cftime
1948
+ )
1952
1949
array = DataArray (np .arange (10 ), [("time" , times )])
1953
1950
1954
1951
# resample to same frequency
@@ -1961,7 +1958,7 @@ def test_resample_first(self) -> None:
1961
1958
1962
1959
# verify that labels don't use the first value
1963
1960
actual = array .resample (time = "24h" ).first ()
1964
- expected = DataArray ( array .to_series (). resample ( "24h" ). first () )
1961
+ expected = array .isel ( time = [ 0 , 4 , 8 ] )
1965
1962
assert_identical (expected , actual )
1966
1963
1967
1964
# missing values
@@ -1978,10 +1975,17 @@ def test_resample_first(self) -> None:
1978
1975
# regression test for https://stackoverflow.com/questions/33158558/
1979
1976
array = Dataset ({"time" : times })["time" ]
1980
1977
actual = array .resample (time = "1D" ).last ()
1981
- expected_times = pd .to_datetime (
1982
- ["2000-01-01T18" , "2000-01-02T18" , "2000-01-03T06" ], unit = "ns"
1978
+ expected = array .isel (time = [3 , 7 , 9 ]).assign_coords (time = times [::4 ])
1979
+ assert_identical (expected , actual )
1980
+
1981
+ # missing periods, GH10169
1982
+ actual = array .isel (time = [0 , 1 , 2 , 3 , 8 , 9 ]).resample (time = "1D" ).last ()
1983
+ expected = DataArray (
1984
+ np .array ([times [3 ], np .datetime64 ("NaT" ), times [9 ]]),
1985
+ dims = "time" ,
1986
+ coords = {"time" : times [::4 ]},
1987
+ name = "time" ,
1983
1988
)
1984
- expected = DataArray (expected_times , [("time" , times [::4 ])], name = "time" )
1985
1989
assert_identical (expected , actual )
1986
1990
1987
1991
def test_resample_bad_resample_dim (self ) -> None :
@@ -2298,7 +2302,6 @@ def test_resample_origin(self) -> None:
2298
2302
2299
2303
2300
2304
class TestDatasetResample :
2301
- @pytest .mark .parametrize ("use_cftime" , [True , False ])
2302
2305
@pytest .mark .parametrize (
2303
2306
"resample_freq" ,
2304
2307
[
0 commit comments