(use_flox)
| 2919 | |
| 2920 | @pytest.mark.parametrize("use_flox", [True, False]) |
| 2921 | def test_weather_data_resample(use_flox): |
| 2922 | # from the docs |
| 2923 | times = pd.date_range("2000-01-01", "2001-12-31", name="time") |
| 2924 | annual_cycle = np.sin(2 * np.pi * (times.dayofyear.values / 365.25 - 0.28)) |
| 2925 | |
| 2926 | base = 10 + 15 * annual_cycle.reshape(-1, 1) |
| 2927 | tmin_values = base + 3 * np.random.randn(annual_cycle.size, 3) |
| 2928 | tmax_values = base + 10 + 3 * np.random.randn(annual_cycle.size, 3) |
| 2929 | |
| 2930 | ds = xr.Dataset( |
| 2931 | { |
| 2932 | "tmin": (("time", "location"), tmin_values), |
| 2933 | "tmax": (("time", "location"), tmax_values), |
| 2934 | }, |
| 2935 | { |
| 2936 | "time": ("time", times, {"time_key": "time_values"}), |
| 2937 | "location": ("location", ["IA", "IN", "IL"], {"loc_key": "loc_value"}), |
| 2938 | }, |
| 2939 | ) |
| 2940 | |
| 2941 | with xr.set_options(use_flox=use_flox): |
| 2942 | actual = ds.resample(time="1MS").mean() |
| 2943 | assert "location" in actual._indexes |
| 2944 | |
| 2945 | gb = ds.groupby(time=TimeResampler(freq="1MS"), location=UniqueGrouper()) |
| 2946 | with xr.set_options(use_flox=use_flox): |
| 2947 | actual = gb.mean() |
| 2948 | expected = ds.resample(time="1MS").mean().sortby("location") |
| 2949 | assert_allclose(actual, expected) |
| 2950 | assert actual.time.attrs == ds.time.attrs |
| 2951 | assert actual.location.attrs == ds.location.attrs |
| 2952 | |
| 2953 | assert expected.time.attrs == ds.time.attrs |
| 2954 | assert expected.location.attrs == ds.location.attrs |
| 2955 | |
| 2956 | |
| 2957 | @pytest.mark.parametrize("as_dataset", [True, False]) |
nothing calls this directly
no test coverage detected
searching dependent graphs…