@@ -1557,24 +1557,28 @@ def test_groupby_with_dst_time_change():
1557
1557
tm .assert_frame_equal (result , expected )
1558
1558
1559
1559
1560
- def test_resample_dst_anchor ():
1560
+ def test_resample_dst_anchor (unit ):
1561
1561
# 5172
1562
- dti = DatetimeIndex ([datetime (2012 , 11 , 4 , 23 )], tz = "US/Eastern" )
1562
+ dti = DatetimeIndex ([datetime (2012 , 11 , 4 , 23 )], tz = "US/Eastern" ). as_unit ( unit )
1563
1563
df = DataFrame ([5 ], index = dti )
1564
1564
1565
- dti = DatetimeIndex (df .index .normalize (), freq = "D" )
1565
+ dti = DatetimeIndex (df .index .normalize (), freq = "D" ). as_unit ( unit )
1566
1566
expected = DataFrame ([5 ], index = dti )
1567
1567
tm .assert_frame_equal (df .resample (rule = "D" ).sum (), expected )
1568
1568
df .resample (rule = "MS" ).sum ()
1569
1569
tm .assert_frame_equal (
1570
1570
df .resample (rule = "MS" ).sum (),
1571
1571
DataFrame (
1572
1572
[5 ],
1573
- index = DatetimeIndex ([datetime (2012 , 11 , 1 )], tz = "US/Eastern" , freq = "MS" ),
1573
+ index = DatetimeIndex (
1574
+ [datetime (2012 , 11 , 1 )], tz = "US/Eastern" , freq = "MS"
1575
+ ).as_unit (unit ),
1574
1576
),
1575
1577
)
1576
1578
1577
- dti = date_range ("2013-09-30" , "2013-11-02" , freq = "30Min" , tz = "Europe/Paris" )
1579
+ dti = date_range (
1580
+ "2013-09-30" , "2013-11-02" , freq = "30Min" , tz = "Europe/Paris"
1581
+ ).as_unit (unit )
1578
1582
values = range (dti .size )
1579
1583
df = DataFrame ({"a" : values , "b" : values , "c" : values }, index = dti , dtype = "int64" )
1580
1584
how = {"a" : "min" , "b" : "max" , "c" : "count" }
@@ -1587,7 +1591,9 @@ def test_resample_dst_anchor():
1587
1591
"b" : [47 , 383 , 719 , 1055 , 1393 , 1586 ],
1588
1592
"c" : [48 , 336 , 336 , 336 , 338 , 193 ],
1589
1593
},
1590
- index = date_range ("9/30/2013" , "11/4/2013" , freq = "W-MON" , tz = "Europe/Paris" ),
1594
+ index = date_range (
1595
+ "9/30/2013" , "11/4/2013" , freq = "W-MON" , tz = "Europe/Paris"
1596
+ ).as_unit (unit ),
1591
1597
),
1592
1598
"W-MON Frequency" ,
1593
1599
)
@@ -1602,7 +1608,7 @@ def test_resample_dst_anchor():
1602
1608
},
1603
1609
index = date_range (
1604
1610
"9/30/2013" , "11/11/2013" , freq = "2W-MON" , tz = "Europe/Paris"
1605
- ),
1611
+ ). as_unit ( unit ) ,
1606
1612
),
1607
1613
"2W-MON Frequency" ,
1608
1614
)
@@ -1611,7 +1617,9 @@ def test_resample_dst_anchor():
1611
1617
df .resample ("MS" ).agg (how )[["a" , "b" , "c" ]],
1612
1618
DataFrame (
1613
1619
{"a" : [0 , 48 , 1538 ], "b" : [47 , 1537 , 1586 ], "c" : [48 , 1490 , 49 ]},
1614
- index = date_range ("9/1/2013" , "11/1/2013" , freq = "MS" , tz = "Europe/Paris" ),
1620
+ index = date_range (
1621
+ "9/1/2013" , "11/1/2013" , freq = "MS" , tz = "Europe/Paris"
1622
+ ).as_unit (unit ),
1615
1623
),
1616
1624
"MS Frequency" ,
1617
1625
)
@@ -1620,7 +1628,9 @@ def test_resample_dst_anchor():
1620
1628
df .resample ("2MS" ).agg (how )[["a" , "b" , "c" ]],
1621
1629
DataFrame (
1622
1630
{"a" : [0 , 1538 ], "b" : [1537 , 1586 ], "c" : [1538 , 49 ]},
1623
- index = date_range ("9/1/2013" , "11/1/2013" , freq = "2MS" , tz = "Europe/Paris" ),
1631
+ index = date_range (
1632
+ "9/1/2013" , "11/1/2013" , freq = "2MS" , tz = "Europe/Paris"
1633
+ ).as_unit (unit ),
1624
1634
),
1625
1635
"2MS Frequency" ,
1626
1636
)
@@ -1636,61 +1646,67 @@ def test_resample_dst_anchor():
1636
1646
"b" : [1295 , 1345 , 1393 , 1441 ],
1637
1647
"c" : [48 , 50 , 48 , 48 ],
1638
1648
},
1639
- index = date_range ("10/26/2013" , "10/29/2013" , freq = "D" , tz = "Europe/Paris" ),
1649
+ index = date_range (
1650
+ "10/26/2013" , "10/29/2013" , freq = "D" , tz = "Europe/Paris"
1651
+ ).as_unit (unit ),
1640
1652
),
1641
1653
"D Frequency" ,
1642
1654
)
1643
1655
1644
1656
1645
- def test_downsample_across_dst ():
1657
+ def test_downsample_across_dst (unit ):
1646
1658
# GH 8531
1647
1659
tz = pytz .timezone ("Europe/Berlin" )
1648
1660
dt = datetime (2014 , 10 , 26 )
1649
- dates = date_range (tz .localize (dt ), periods = 4 , freq = "2H" )
1661
+ dates = date_range (tz .localize (dt ), periods = 4 , freq = "2H" ). as_unit ( unit )
1650
1662
result = Series (5 , index = dates ).resample ("H" ).mean ()
1651
1663
expected = Series (
1652
1664
[5.0 , np .nan ] * 3 + [5.0 ],
1653
- index = date_range (tz .localize (dt ), periods = 7 , freq = "H" ),
1665
+ index = date_range (tz .localize (dt ), periods = 7 , freq = "H" ). as_unit ( unit ) ,
1654
1666
)
1655
1667
tm .assert_series_equal (result , expected )
1656
1668
1657
1669
1658
- def test_downsample_across_dst_weekly ():
1670
+ def test_downsample_across_dst_weekly (unit ):
1659
1671
# GH 9119, GH 21459
1660
1672
df = DataFrame (
1661
1673
index = DatetimeIndex (
1662
1674
["2017-03-25" , "2017-03-26" , "2017-03-27" , "2017-03-28" , "2017-03-29" ],
1663
1675
tz = "Europe/Amsterdam" ,
1664
- ),
1676
+ ). as_unit ( unit ) ,
1665
1677
data = [11 , 12 , 13 , 14 , 15 ],
1666
1678
)
1667
1679
result = df .resample ("1W" ).sum ()
1668
1680
expected = DataFrame (
1669
1681
[23 , 42 ],
1670
1682
index = DatetimeIndex (
1671
1683
["2017-03-26" , "2017-04-02" ], tz = "Europe/Amsterdam" , freq = "W"
1672
- ),
1684
+ ). as_unit ( unit ) ,
1673
1685
)
1674
1686
tm .assert_frame_equal (result , expected )
1675
1687
1676
1688
1677
- def test_downsample_across_dst_weekly_2 ():
1689
+ def test_downsample_across_dst_weekly_2 (unit ):
1678
1690
# GH 9119, GH 21459
1679
- idx = date_range ("2013-04-01" , "2013-05-01" , tz = "Europe/London" , freq = "H" )
1691
+ idx = date_range ("2013-04-01" , "2013-05-01" , tz = "Europe/London" , freq = "H" ).as_unit (
1692
+ unit
1693
+ )
1680
1694
s = Series (index = idx , dtype = np .float64 )
1681
1695
result = s .resample ("W" ).mean ()
1682
1696
expected = Series (
1683
- index = date_range ("2013-04-07" , freq = "W" , periods = 5 , tz = "Europe/London" ),
1697
+ index = date_range ("2013-04-07" , freq = "W" , periods = 5 , tz = "Europe/London" ).as_unit (
1698
+ unit
1699
+ ),
1684
1700
dtype = np .float64 ,
1685
1701
)
1686
1702
tm .assert_series_equal (result , expected )
1687
1703
1688
1704
1689
- def test_downsample_dst_at_midnight ():
1705
+ def test_downsample_dst_at_midnight (unit ):
1690
1706
# GH 25758
1691
1707
start = datetime (2018 , 11 , 3 , 12 )
1692
1708
end = datetime (2018 , 11 , 5 , 12 )
1693
- index = date_range (start , end , freq = "1H" )
1709
+ index = date_range (start , end , freq = "1H" ). as_unit ( unit )
1694
1710
index = index .tz_localize ("UTC" ).tz_convert ("America/Havana" )
1695
1711
data = list (range (len (index )))
1696
1712
dataframe = DataFrame (data , index = index )
@@ -1699,7 +1715,7 @@ def test_downsample_dst_at_midnight():
1699
1715
dti = date_range ("2018-11-03" , periods = 3 ).tz_localize (
1700
1716
"America/Havana" , ambiguous = True
1701
1717
)
1702
- dti = DatetimeIndex (dti , freq = "D" )
1718
+ dti = DatetimeIndex (dti , freq = "D" ). as_unit ( unit )
1703
1719
expected = DataFrame ([7.5 , 28.0 , 44.5 ], index = dti )
1704
1720
tm .assert_frame_equal (result , expected )
1705
1721
0 commit comments