@@ -150,7 +150,9 @@ def test_annual_upsample_cases(
150
150
if period == "B"
151
151
else "Resampling with a PeriodIndex is deprecated"
152
152
)
153
- with tm .assert_produces_warning (FutureWarning , match = msg ):
153
+ with tm .assert_produces_warning (
154
+ FutureWarning , match = msg , check_stacklevel = False
155
+ ):
154
156
result = getattr (ts .resample (period , convention = conv ), meth )()
155
157
expected = result .to_timestamp (period , how = conv )
156
158
expected = expected .asfreq (offset , meth ).to_period ()
@@ -193,7 +195,9 @@ def test_basic_upsample(self, freq, simple_period_range_series):
193
195
result = ts .resample ("Y-DEC" ).mean ()
194
196
195
197
msg = "The 'convention' keyword in Series.resample is deprecated"
196
- with tm .assert_produces_warning (FutureWarning , match = msg ):
198
+ with tm .assert_produces_warning (
199
+ FutureWarning , match = msg , check_stacklevel = False
200
+ ):
197
201
resampled = result .resample (freq , convention = "end" ).ffill ()
198
202
expected = result .to_timestamp (freq , how = "end" )
199
203
expected = expected .asfreq (freq , "ffill" ).to_period (freq )
@@ -204,7 +208,9 @@ def test_upsample_with_limit(self):
204
208
ts = Series (np .random .default_rng (2 ).standard_normal (len (rng )), rng )
205
209
206
210
msg = "The 'convention' keyword in Series.resample is deprecated"
207
- with tm .assert_produces_warning (FutureWarning , match = msg ):
211
+ with tm .assert_produces_warning (
212
+ FutureWarning , match = msg , check_stacklevel = False
213
+ ):
208
214
result = ts .resample ("M" , convention = "end" ).ffill (limit = 2 )
209
215
expected = ts .asfreq ("M" ).reindex (result .index , method = "ffill" , limit = 2 )
210
216
tm .assert_series_equal (result , expected )
@@ -249,7 +255,9 @@ def test_quarterly_upsample(
249
255
if period == "B"
250
256
else "Resampling with a PeriodIndex is deprecated"
251
257
)
252
- with tm .assert_produces_warning (FutureWarning , match = msg ):
258
+ with tm .assert_produces_warning (
259
+ FutureWarning , match = msg , check_stacklevel = False
260
+ ):
253
261
result = ts .resample (period , convention = convention ).ffill ()
254
262
expected = result .to_timestamp (period , how = convention )
255
263
expected = expected .asfreq (offset , "ffill" ).to_period ()
@@ -265,7 +273,9 @@ def test_monthly_upsample(self, target, convention, simple_period_range_series):
265
273
if target == "D"
266
274
else r"PeriodDtype\[B\] is deprecated"
267
275
)
268
- with tm .assert_produces_warning (FutureWarning , match = msg ):
276
+ with tm .assert_produces_warning (
277
+ FutureWarning , match = msg , check_stacklevel = False
278
+ ):
269
279
result = ts .resample (target , convention = convention ).ffill ()
270
280
expected = result .to_timestamp (target , how = convention )
271
281
expected = expected .asfreq (target , "ffill" ).to_period ()
@@ -346,7 +356,7 @@ def test_with_local_timezone(self, tz):
346
356
series = Series (1 , index = index )
347
357
series = series .tz_convert (local_timezone )
348
358
msg = "Converting to PeriodArray/Index representation will drop timezone"
349
- with tm .assert_produces_warning (UserWarning , match = msg ):
359
+ with tm .assert_produces_warning (UserWarning , match = msg , check_stacklevel = False ):
350
360
result = series .resample ("D" ).mean ().to_period ()
351
361
352
362
# Create the expected series
@@ -438,7 +448,7 @@ def test_weekly_upsample(self, day, target, convention, simple_period_range_seri
438
448
if warn is None :
439
449
msg = "Resampling with a PeriodIndex is deprecated"
440
450
warn = FutureWarning
441
- with tm .assert_produces_warning (warn , match = msg ):
451
+ with tm .assert_produces_warning (warn , match = msg , check_stacklevel = False ):
442
452
result = ts .resample (target , convention = convention ).ffill ()
443
453
expected = result .to_timestamp (target , how = convention )
444
454
expected = expected .asfreq (target , "ffill" ).to_period ()
@@ -473,7 +483,9 @@ def test_resample_to_quarterly_start_end(self, simple_period_range_series, how):
473
483
# conforms, but different month
474
484
ts = simple_period_range_series ("1990" , "1992" , freq = "Y-JUN" )
475
485
msg = "The 'convention' keyword in Series.resample is deprecated"
476
- with tm .assert_produces_warning (FutureWarning , match = msg ):
486
+ with tm .assert_produces_warning (
487
+ FutureWarning , match = msg , check_stacklevel = False
488
+ ):
477
489
result = ts .resample ("Q-MAR" , convention = how ).ffill ()
478
490
expected = ts .asfreq ("Q-MAR" , how = how )
479
491
expected = expected .reindex (result .index , method = "ffill" )
@@ -523,7 +535,9 @@ def test_upsample_daily_business_daily(self, simple_period_range_series):
523
535
524
536
ts = simple_period_range_series ("1/1/2000" , "2/1/2000" )
525
537
msg = "The 'convention' keyword in Series.resample is deprecated"
526
- with tm .assert_produces_warning (FutureWarning , match = msg ):
538
+ with tm .assert_produces_warning (
539
+ FutureWarning , match = msg , check_stacklevel = False
540
+ ):
527
541
result = ts .resample ("h" , convention = "s" ).asfreq ()
528
542
exp_rng = period_range ("1/1/2000" , "2/1/2000 23:00" , freq = "h" )
529
543
expected = ts .asfreq ("h" , how = "s" ).reindex (exp_rng )
@@ -586,7 +600,7 @@ def test_resample_tz_localized2(self):
586
600
587
601
# for good measure
588
602
msg = "Converting to PeriodArray/Index representation will drop timezone "
589
- with tm .assert_produces_warning (UserWarning , match = msg ):
603
+ with tm .assert_produces_warning (UserWarning , match = msg , check_stacklevel = False ):
590
604
result = s .resample ("D" ).mean ().to_period ()
591
605
ex_index = period_range ("2001-09-20" , periods = 1 , freq = "D" )
592
606
expected = Series ([1.5 ], index = ex_index )
@@ -885,7 +899,9 @@ def test_resample_with_nat(self, periods, values, freq, expected_values):
885
899
)
886
900
expected = DataFrame (expected_values , index = expected_index )
887
901
msg = "Resampling with a PeriodIndex is deprecated"
888
- with tm .assert_produces_warning (FutureWarning , match = msg ):
902
+ with tm .assert_produces_warning (
903
+ FutureWarning , match = msg , check_stacklevel = False
904
+ ):
889
905
rs = frame .resample (freq )
890
906
result = rs .mean ()
891
907
tm .assert_frame_equal (result , expected )
@@ -924,7 +940,9 @@ def test_resample_with_offset(self, start, end, start_freq, end_freq, offset):
924
940
pi = period_range (start , end , freq = start_freq )
925
941
ser = Series (np .arange (len (pi )), index = pi )
926
942
msg = "Resampling with a PeriodIndex is deprecated"
927
- with tm .assert_produces_warning (FutureWarning , match = msg ):
943
+ with tm .assert_produces_warning (
944
+ FutureWarning , match = msg , check_stacklevel = False
945
+ ):
928
946
rs = ser .resample (end_freq , offset = offset )
929
947
result = rs .mean ()
930
948
result = result .to_timestamp (end_freq )
@@ -937,7 +955,9 @@ def test_resample_with_offset_month(self):
937
955
pi = period_range ("19910905 12:00" , "19910909 1:00" , freq = "h" )
938
956
ser = Series (np .arange (len (pi )), index = pi )
939
957
msg = "Resampling with a PeriodIndex is deprecated"
940
- with tm .assert_produces_warning (FutureWarning , match = msg ):
958
+ with tm .assert_produces_warning (
959
+ FutureWarning , match = msg , check_stacklevel = False
960
+ ):
941
961
rs = ser .resample ("M" , offset = "3h" )
942
962
result = rs .mean ()
943
963
result = result .to_timestamp ("M" )
@@ -985,7 +1005,9 @@ def test_sum_min_count(self):
985
1005
data [3 :6 ] = np .nan
986
1006
s = Series (data , index ).to_period ()
987
1007
msg = "Resampling with a PeriodIndex is deprecated"
988
- with tm .assert_produces_warning (FutureWarning , match = msg ):
1008
+ with tm .assert_produces_warning (
1009
+ FutureWarning , match = msg , check_stacklevel = False
1010
+ ):
989
1011
rs = s .resample ("Q" )
990
1012
result = rs .sum (min_count = 1 )
991
1013
expected = Series (
@@ -1073,7 +1095,7 @@ def test_corner_cases_period(simple_period_range_series):
1073
1095
len0pts = simple_period_range_series ("2007-01" , "2010-05" , freq = "M" )[:0 ]
1074
1096
# it works
1075
1097
msg = "Resampling with a PeriodIndex is deprecated"
1076
- with tm .assert_produces_warning (FutureWarning , match = msg ):
1098
+ with tm .assert_produces_warning (FutureWarning , match = msg , check_stacklevel = False ):
1077
1099
result = len0pts .resample ("Y-DEC" ).mean ()
1078
1100
assert len (result ) == 0
1079
1101
0 commit comments