@@ -1204,14 +1204,14 @@ def test_resample_anchored_multiday(label, sec):
1204
1204
assert result .index [- 1 ] == Timestamp (f"2014-10-15 23:00:{ sec } 00" )
1205
1205
1206
1206
1207
- def test_corner_cases ():
1207
+ def test_corner_cases (unit ):
1208
1208
# miscellaneous test coverage
1209
1209
1210
- rng = date_range ("1/1/2000" , periods = 12 , freq = "t" )
1210
+ rng = date_range ("1/1/2000" , periods = 12 , freq = "t" ). as_unit ( unit )
1211
1211
ts = Series (np .random .randn (len (rng )), index = rng )
1212
1212
1213
1213
result = ts .resample ("5t" , closed = "right" , label = "left" ).mean ()
1214
- ex_index = date_range ("1999-12-31 23:55" , periods = 4 , freq = "5t" )
1214
+ ex_index = date_range ("1999-12-31 23:55" , periods = 4 , freq = "5t" ). as_unit ( unit )
1215
1215
tm .assert_index_equal (result .index , ex_index )
1216
1216
1217
1217
@@ -1223,33 +1223,34 @@ def test_corner_cases_period(simple_period_range_series):
1223
1223
assert len (result ) == 0
1224
1224
1225
1225
1226
- def test_corner_cases_date (simple_date_range_series ):
1226
+ def test_corner_cases_date (simple_date_range_series , unit ):
1227
1227
# resample to periods
1228
1228
ts = simple_date_range_series ("2000-04-28" , "2000-04-30 11:00" , freq = "h" )
1229
+ ts .index = ts .index .as_unit (unit )
1229
1230
result = ts .resample ("M" , kind = "period" ).mean ()
1230
1231
assert len (result ) == 1
1231
1232
assert result .index [0 ] == Period ("2000-04" , freq = "M" )
1232
1233
1233
1234
1234
- def test_anchored_lowercase_buglet ():
1235
- dates = date_range ("4/16/2012 20:00" , periods = 50000 , freq = "s" )
1235
+ def test_anchored_lowercase_buglet (unit ):
1236
+ dates = date_range ("4/16/2012 20:00" , periods = 50000 , freq = "s" ). as_unit ( unit )
1236
1237
ts = Series (np .random .randn (len (dates )), index = dates )
1237
1238
# it works!
1238
1239
ts .resample ("d" ).mean ()
1239
1240
1240
1241
1241
- def test_upsample_apply_functions ():
1242
+ def test_upsample_apply_functions (unit ):
1242
1243
# #1596
1243
- rng = date_range ("2012-06-12" , periods = 4 , freq = "h" )
1244
+ rng = date_range ("2012-06-12" , periods = 4 , freq = "h" ). as_unit ( unit )
1244
1245
1245
1246
ts = Series (np .random .randn (len (rng )), index = rng )
1246
1247
1247
1248
result = ts .resample ("20min" ).aggregate (["mean" , "sum" ])
1248
1249
assert isinstance (result , DataFrame )
1249
1250
1250
1251
1251
- def test_resample_not_monotonic ():
1252
- rng = date_range ("2012-06-12" , periods = 200 , freq = "h" )
1252
+ def test_resample_not_monotonic (unit ):
1253
+ rng = date_range ("2012-06-12" , periods = 200 , freq = "h" ). as_unit ( unit )
1253
1254
ts = Series (np .random .randn (len (rng )), index = rng )
1254
1255
1255
1256
ts = ts .take (np .random .permutation (len (ts )))
@@ -1401,7 +1402,7 @@ def test_resample_timegrouper(dates):
1401
1402
tm .assert_frame_equal (result , expected )
1402
1403
1403
1404
1404
- def test_resample_nunique ():
1405
+ def test_resample_nunique (unit ):
1405
1406
1406
1407
# GH 12352
1407
1408
df = DataFrame (
@@ -1416,6 +1417,7 @@ def test_resample_nunique():
1416
1417
},
1417
1418
}
1418
1419
)
1420
+ df .index = df .index .as_unit (unit )
1419
1421
r = df .resample ("D" )
1420
1422
g = df .groupby (Grouper (freq = "D" ))
1421
1423
expected = df .groupby (Grouper (freq = "D" )).ID .apply (lambda x : x .nunique ())
@@ -1432,9 +1434,10 @@ def test_resample_nunique():
1432
1434
tm .assert_series_equal (result , expected )
1433
1435
1434
1436
1435
- def test_resample_nunique_preserves_column_level_names ():
1437
+ def test_resample_nunique_preserves_column_level_names (unit ):
1436
1438
# see gh-23222
1437
1439
df = tm .makeTimeDataFrame (freq = "1D" ).abs ()
1440
+ df .index = df .index .as_unit (unit )
1438
1441
df .columns = pd .MultiIndex .from_arrays (
1439
1442
[df .columns .tolist ()] * 2 , names = ["lev0" , "lev1" ]
1440
1443
)
@@ -1540,17 +1543,19 @@ def test_resample_across_dst():
1540
1543
tm .assert_frame_equal (result , expected )
1541
1544
1542
1545
1543
- def test_groupby_with_dst_time_change ():
1546
+ def test_groupby_with_dst_time_change (unit ):
1544
1547
# GH 24972
1545
- index = DatetimeIndex (
1546
- [1478064900001000000 , 1480037118776792000 ], tz = "UTC"
1547
- ).tz_convert ("America/Chicago" )
1548
+ index = (
1549
+ DatetimeIndex ([1478064900001000000 , 1480037118776792000 ], tz = "UTC" )
1550
+ .tz_convert ("America/Chicago" )
1551
+ .as_unit (unit )
1552
+ )
1548
1553
1549
1554
df = DataFrame ([1 , 2 ], index = index )
1550
1555
result = df .groupby (Grouper (freq = "1d" )).last ()
1551
1556
expected_index_values = date_range (
1552
1557
"2016-11-02" , "2016-11-24" , freq = "d" , tz = "America/Chicago"
1553
- )
1558
+ ). as_unit ( unit )
1554
1559
1555
1560
index = DatetimeIndex (expected_index_values )
1556
1561
expected = DataFrame ([1.0 ] + ([np .nan ] * 21 ) + [2.0 ], index = index )
0 commit comments