1515
1616import pandas as pd
1717from pandas import NaT , Period , Timedelta , Timestamp , offsets
18- import pandas .core .indexes .period as period
1918import pandas .util .testing as tm
2019
2120
@@ -942,7 +941,7 @@ def test_equal(self):
942941 assert self .january1 == self .january2
943942
944943 def test_equal_Raises_Value (self ):
945- with pytest .raises (period . IncompatibleFrequency ):
944+ with pytest .raises (IncompatibleFrequency ):
946945 self .january1 == self .day
947946
948947 def test_notEqual (self ):
@@ -953,7 +952,7 @@ def test_greater(self):
953952 assert self .february > self .january1
954953
955954 def test_greater_Raises_Value (self ):
956- with pytest .raises (period . IncompatibleFrequency ):
955+ with pytest .raises (IncompatibleFrequency ):
957956 self .january1 > self .day
958957
959958 def test_greater_Raises_Type (self ):
@@ -964,7 +963,7 @@ def test_greaterEqual(self):
964963 assert self .january1 >= self .january2
965964
966965 def test_greaterEqual_Raises_Value (self ):
967- with pytest .raises (period . IncompatibleFrequency ):
966+ with pytest .raises (IncompatibleFrequency ):
968967 self .january1 >= self .day
969968
970969 with pytest .raises (TypeError ):
@@ -974,7 +973,7 @@ def test_smallerEqual(self):
974973 assert self .january1 <= self .january2
975974
976975 def test_smallerEqual_Raises_Value (self ):
977- with pytest .raises (period . IncompatibleFrequency ):
976+ with pytest .raises (IncompatibleFrequency ):
978977 self .january1 <= self .day
979978
980979 def test_smallerEqual_Raises_Type (self ):
@@ -985,7 +984,7 @@ def test_smaller(self):
985984 assert self .january1 < self .february
986985
987986 def test_smaller_Raises_Value (self ):
988- with pytest .raises (period . IncompatibleFrequency ):
987+ with pytest .raises (IncompatibleFrequency ):
989988 self .january1 < self .day
990989
991990 def test_smaller_Raises_Type (self ):
@@ -1026,7 +1025,7 @@ def test_sub_delta(self):
10261025 result = left - right
10271026 assert result == 4 * right .freq
10281027
1029- with pytest .raises (period . IncompatibleFrequency ):
1028+ with pytest .raises (IncompatibleFrequency ):
10301029 left - Period ("2007-01" , freq = "M" )
10311030
10321031 def test_add_integer (self ):
@@ -1097,16 +1096,16 @@ def test_sub(self):
10971096 assert per2 - per1 == 14 * off
10981097
10991098 msg = r"Input has different freq=M from Period\(freq=D\)"
1100- with pytest .raises (period . IncompatibleFrequency , match = msg ):
1099+ with pytest .raises (IncompatibleFrequency , match = msg ):
11011100 per1 - Period ("2011-02" , freq = "M" )
11021101
11031102 @pytest .mark .parametrize ("n" , [1 , 2 , 3 , 4 ])
11041103 def test_sub_n_gt_1_ticks (self , tick_classes , n ):
11051104 # GH 23878
1106- p1 = pd . Period ("19910905" , freq = tick_classes (n ))
1107- p2 = pd . Period ("19920406" , freq = tick_classes (n ))
1105+ p1 = Period ("19910905" , freq = tick_classes (n ))
1106+ p2 = Period ("19920406" , freq = tick_classes (n ))
11081107
1109- expected = pd . Period (str (p2 ), freq = p2 .freq .base ) - pd . Period (
1108+ expected = Period (str (p2 ), freq = p2 .freq .base ) - Period (
11101109 str (p1 ), freq = p1 .freq .base
11111110 )
11121111
@@ -1117,23 +1116,21 @@ def test_sub_n_gt_1_ticks(self, tick_classes, n):
11171116 @pytest .mark .parametrize (
11181117 "offset, kwd_name" ,
11191118 [
1120- (pd . offsets .YearEnd , "month" ),
1121- (pd . offsets .QuarterEnd , "startingMonth" ),
1122- (pd . offsets .MonthEnd , None ),
1123- (pd . offsets .Week , "weekday" ),
1119+ (offsets .YearEnd , "month" ),
1120+ (offsets .QuarterEnd , "startingMonth" ),
1121+ (offsets .MonthEnd , None ),
1122+ (offsets .Week , "weekday" ),
11241123 ],
11251124 )
11261125 def test_sub_n_gt_1_offsets (self , offset , kwd_name , n , normalize ):
11271126 # GH 23878
11281127 kwds = {kwd_name : 3 } if kwd_name is not None else {}
11291128 p1_d = "19910905"
11301129 p2_d = "19920406"
1131- p1 = pd . Period (p1_d , freq = offset (n , normalize , ** kwds ))
1132- p2 = pd . Period (p2_d , freq = offset (n , normalize , ** kwds ))
1130+ p1 = Period (p1_d , freq = offset (n , normalize , ** kwds ))
1131+ p2 = Period (p2_d , freq = offset (n , normalize , ** kwds ))
11331132
1134- expected = pd .Period (p2_d , freq = p2 .freq .base ) - pd .Period (
1135- p1_d , freq = p1 .freq .base
1136- )
1133+ expected = Period (p2_d , freq = p2 .freq .base ) - Period (p1_d , freq = p1 .freq .base )
11371134
11381135 assert (p2 - p1 ) == expected
11391136
@@ -1152,14 +1149,14 @@ def test_add_offset(self):
11521149 np .timedelta64 (365 , "D" ),
11531150 timedelta (365 ),
11541151 ]:
1155- with pytest .raises (period . IncompatibleFrequency ):
1152+ with pytest .raises (IncompatibleFrequency ):
11561153 p + o
11571154
11581155 if isinstance (o , np .timedelta64 ):
11591156 with pytest .raises (TypeError ):
11601157 o + p
11611158 else :
1162- with pytest .raises (period . IncompatibleFrequency ):
1159+ with pytest .raises (IncompatibleFrequency ):
11631160 o + p
11641161
11651162 for freq in ["M" , "2M" , "3M" ]:
@@ -1179,14 +1176,14 @@ def test_add_offset(self):
11791176 np .timedelta64 (365 , "D" ),
11801177 timedelta (365 ),
11811178 ]:
1182- with pytest .raises (period . IncompatibleFrequency ):
1179+ with pytest .raises (IncompatibleFrequency ):
11831180 p + o
11841181
11851182 if isinstance (o , np .timedelta64 ):
11861183 with pytest .raises (TypeError ):
11871184 o + p
11881185 else :
1189- with pytest .raises (period . IncompatibleFrequency ):
1186+ with pytest .raises (IncompatibleFrequency ):
11901187 o + p
11911188
11921189 # freq is Tick
@@ -1226,14 +1223,14 @@ def test_add_offset(self):
12261223 np .timedelta64 (4 , "h" ),
12271224 timedelta (hours = 23 ),
12281225 ]:
1229- with pytest .raises (period . IncompatibleFrequency ):
1226+ with pytest .raises (IncompatibleFrequency ):
12301227 p + o
12311228
12321229 if isinstance (o , np .timedelta64 ):
12331230 with pytest .raises (TypeError ):
12341231 o + p
12351232 else :
1236- with pytest .raises (period . IncompatibleFrequency ):
1233+ with pytest .raises (IncompatibleFrequency ):
12371234 o + p
12381235
12391236 for freq in ["H" , "2H" , "3H" ]:
@@ -1272,14 +1269,14 @@ def test_add_offset(self):
12721269 np .timedelta64 (3200 , "s" ),
12731270 timedelta (hours = 23 , minutes = 30 ),
12741271 ]:
1275- with pytest .raises (period . IncompatibleFrequency ):
1272+ with pytest .raises (IncompatibleFrequency ):
12761273 p + o
12771274
12781275 if isinstance (o , np .timedelta64 ):
12791276 with pytest .raises (TypeError ):
12801277 o + p
12811278 else :
1282- with pytest .raises (period . IncompatibleFrequency ):
1279+ with pytest .raises (IncompatibleFrequency ):
12831280 o + p
12841281
12851282 def test_add_offset_nat (self ):
@@ -1376,7 +1373,7 @@ def test_sub_offset(self):
13761373 np .timedelta64 (365 , "D" ),
13771374 timedelta (365 ),
13781375 ]:
1379- with pytest .raises (period . IncompatibleFrequency ):
1376+ with pytest .raises (IncompatibleFrequency ):
13801377 p - o
13811378
13821379 for freq in ["M" , "2M" , "3M" ]:
@@ -1391,7 +1388,7 @@ def test_sub_offset(self):
13911388 np .timedelta64 (365 , "D" ),
13921389 timedelta (365 ),
13931390 ]:
1394- with pytest .raises (period . IncompatibleFrequency ):
1391+ with pytest .raises (IncompatibleFrequency ):
13951392 p - o
13961393
13971394 # freq is Tick
@@ -1411,7 +1408,7 @@ def test_sub_offset(self):
14111408 np .timedelta64 (4 , "h" ),
14121409 timedelta (hours = 23 ),
14131410 ]:
1414- with pytest .raises (period . IncompatibleFrequency ):
1411+ with pytest .raises (IncompatibleFrequency ):
14151412 p - o
14161413
14171414 for freq in ["H" , "2H" , "3H" ]:
@@ -1434,7 +1431,7 @@ def test_sub_offset(self):
14341431 np .timedelta64 (3200 , "s" ),
14351432 timedelta (hours = 23 , minutes = 30 ),
14361433 ]:
1437- with pytest .raises (period . IncompatibleFrequency ):
1434+ with pytest .raises (IncompatibleFrequency ):
14381435 p - o
14391436
14401437 def test_sub_offset_nat (self ):
@@ -1530,10 +1527,10 @@ def test_period_ops_offset(self):
15301527 assert result == exp
15311528
15321529 msg = r"Input cannot be converted to Period\(freq=D\)"
1533- with pytest .raises (period . IncompatibleFrequency , match = msg ):
1530+ with pytest .raises (IncompatibleFrequency , match = msg ):
15341531 p + offsets .Hour (2 )
15351532
1536- with pytest .raises (period . IncompatibleFrequency , match = msg ):
1533+ with pytest .raises (IncompatibleFrequency , match = msg ):
15371534 p - offsets .Hour (2 )
15381535
15391536
0 commit comments