@@ -327,6 +327,25 @@ def test_apply_columns_multilevel():
327
327
tm .assert_frame_equal (result , expected )
328
328
329
329
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
+
330
349
def test_resample_groupby_with_label ():
331
350
# GH 13235
332
351
index = date_range ("2000-01-01" , freq = "2D" , periods = 5 )
0 commit comments