MCPcopy Index your code
hub / github.com/pydata/xarray / test_resample_first_last

Method test_resample_first_last

xarray/tests/test_groupby.py:1982–2026  ·  view source on GitHub ↗
(self, use_cftime)

Source from the content-addressed store, hash-verified

1980 assert_identical(actual, expected)
1981
1982 def test_resample_first_last(self, use_cftime) -> None:
1983 times = xr.date_range(
1984 "2000-01-01", freq="6h", periods=10, use_cftime=use_cftime
1985 )
1986 array = DataArray(np.arange(10), [("time", times)])
1987
1988 # resample to same frequency
1989 actual = array.resample(time="6h").first()
1990 assert_identical(array, actual)
1991
1992 actual = array.resample(time="1D").first()
1993 expected = DataArray([0, 4, 8], [("time", times[::4])])
1994 assert_identical(expected, actual)
1995
1996 # verify that labels don't use the first value
1997 actual = array.resample(time="24h").first()
1998 expected = array.isel(time=[0, 4, 8])
1999 assert_identical(expected, actual)
2000
2001 # missing values
2002 array = array.astype(float)
2003 array[:2] = np.nan
2004 actual = array.resample(time="1D").first()
2005 expected = DataArray([2, 4, 8], [("time", times[::4])])
2006 assert_identical(expected, actual)
2007
2008 actual = array.resample(time="1D").first(skipna=False)
2009 expected = DataArray([np.nan, 4, 8], [("time", times[::4])])
2010 assert_identical(expected, actual)
2011
2012 # regression test for https://stackoverflow.com/questions/33158558/
2013 array = Dataset({"time": times})["time"]
2014 actual = array.resample(time="1D").last()
2015 expected = array.isel(time=[3, 7, 9]).assign_coords(time=times[::4])
2016 assert_identical(expected, actual)
2017
2018 # missing periods, GH10169
2019 actual = array.isel(time=[0, 1, 2, 3, 8, 9]).resample(time="1D").last()
2020 expected = DataArray(
2021 np.array([times[3], np.datetime64("NaT", "us"), times[9]]),
2022 dims="time",
2023 coords={"time": times[::4]},
2024 name="time",
2025 )
2026 assert_identical(expected, actual)
2027
2028 def test_resample_bad_resample_dim(self) -> None:
2029 times = pd.date_range("2000-01-01", freq="6h", periods=10)

Callers

nothing calls this directly

Calls 11

resampleMethod · 0.95
iselMethod · 0.95
DataArrayClass · 0.90
assert_identicalFunction · 0.90
DatasetClass · 0.90
arangeMethod · 0.80
firstMethod · 0.80
lastMethod · 0.80
astypeMethod · 0.45
assign_coordsMethod · 0.45
resampleMethod · 0.45

Tested by

no test coverage detected