Skip to content

Commit 34c26c7

Browse files
liang3zy22Yi Wei
authored and
Yi Wei
committed
resampler with non_naive index test GH#25411 (pandas-dev#52956)
Signed-off-by: Liang Yan <[email protected]>
1 parent aae0e16 commit 34c26c7

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

pandas/tests/resample/test_resampler_grouper.py

+19
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,25 @@ def test_apply_columns_multilevel():
327327
tm.assert_frame_equal(result, expected)
328328

329329

330+
def test_apply_non_naive_index():
331+
def weighted_quantile(series, weights, q):
332+
series = series.sort_values()
333+
cumsum = weights.reindex(series.index).fillna(0).cumsum()
334+
cutoff = cumsum.iloc[-1] * q
335+
return series[cumsum >= cutoff].iloc[0]
336+
337+
times = date_range("2017-6-23 18:00", periods=8, freq="15T", tz="UTC")
338+
data = Series([1.0, 1, 1, 1, 1, 2, 2, 0], index=times)
339+
weights = Series([160.0, 91, 65, 43, 24, 10, 1, 0], index=times)
340+
341+
result = data.resample("D").apply(weighted_quantile, weights=weights, q=0.5)
342+
ind = date_range(
343+
"2017-06-23 00:00:00+00:00", "2017-06-23 00:00:00+00:00", freq="D", tz="UTC"
344+
)
345+
expected = Series([1.0], index=ind)
346+
tm.assert_series_equal(result, expected)
347+
348+
330349
def test_resample_groupby_with_label():
331350
# GH 13235
332351
index = date_range("2000-01-01", freq="2D", periods=5)

0 commit comments

Comments
 (0)