15
15
16
16
import pandas as pd
17
17
from pandas import NaT , Period , Timedelta , Timestamp , offsets
18
- import pandas .core .indexes .period as period
19
18
import pandas .util .testing as tm
20
19
21
20
@@ -942,7 +941,7 @@ def test_equal(self):
942
941
assert self .january1 == self .january2
943
942
944
943
def test_equal_Raises_Value (self ):
945
- with pytest .raises (period . IncompatibleFrequency ):
944
+ with pytest .raises (IncompatibleFrequency ):
946
945
self .january1 == self .day
947
946
948
947
def test_notEqual (self ):
@@ -953,7 +952,7 @@ def test_greater(self):
953
952
assert self .february > self .january1
954
953
955
954
def test_greater_Raises_Value (self ):
956
- with pytest .raises (period . IncompatibleFrequency ):
955
+ with pytest .raises (IncompatibleFrequency ):
957
956
self .january1 > self .day
958
957
959
958
def test_greater_Raises_Type (self ):
@@ -964,7 +963,7 @@ def test_greaterEqual(self):
964
963
assert self .january1 >= self .january2
965
964
966
965
def test_greaterEqual_Raises_Value (self ):
967
- with pytest .raises (period . IncompatibleFrequency ):
966
+ with pytest .raises (IncompatibleFrequency ):
968
967
self .january1 >= self .day
969
968
970
969
with pytest .raises (TypeError ):
@@ -974,7 +973,7 @@ def test_smallerEqual(self):
974
973
assert self .january1 <= self .january2
975
974
976
975
def test_smallerEqual_Raises_Value (self ):
977
- with pytest .raises (period . IncompatibleFrequency ):
976
+ with pytest .raises (IncompatibleFrequency ):
978
977
self .january1 <= self .day
979
978
980
979
def test_smallerEqual_Raises_Type (self ):
@@ -985,7 +984,7 @@ def test_smaller(self):
985
984
assert self .january1 < self .february
986
985
987
986
def test_smaller_Raises_Value (self ):
988
- with pytest .raises (period . IncompatibleFrequency ):
987
+ with pytest .raises (IncompatibleFrequency ):
989
988
self .january1 < self .day
990
989
991
990
def test_smaller_Raises_Type (self ):
@@ -1026,7 +1025,7 @@ def test_sub_delta(self):
1026
1025
result = left - right
1027
1026
assert result == 4 * right .freq
1028
1027
1029
- with pytest .raises (period . IncompatibleFrequency ):
1028
+ with pytest .raises (IncompatibleFrequency ):
1030
1029
left - Period ("2007-01" , freq = "M" )
1031
1030
1032
1031
def test_add_integer (self ):
@@ -1097,16 +1096,16 @@ def test_sub(self):
1097
1096
assert per2 - per1 == 14 * off
1098
1097
1099
1098
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 ):
1101
1100
per1 - Period ("2011-02" , freq = "M" )
1102
1101
1103
1102
@pytest .mark .parametrize ("n" , [1 , 2 , 3 , 4 ])
1104
1103
def test_sub_n_gt_1_ticks (self , tick_classes , n ):
1105
1104
# 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 ))
1108
1107
1109
- expected = pd . Period (str (p2 ), freq = p2 .freq .base ) - pd . Period (
1108
+ expected = Period (str (p2 ), freq = p2 .freq .base ) - Period (
1110
1109
str (p1 ), freq = p1 .freq .base
1111
1110
)
1112
1111
@@ -1117,23 +1116,21 @@ def test_sub_n_gt_1_ticks(self, tick_classes, n):
1117
1116
@pytest .mark .parametrize (
1118
1117
"offset, kwd_name" ,
1119
1118
[
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" ),
1124
1123
],
1125
1124
)
1126
1125
def test_sub_n_gt_1_offsets (self , offset , kwd_name , n , normalize ):
1127
1126
# GH 23878
1128
1127
kwds = {kwd_name : 3 } if kwd_name is not None else {}
1129
1128
p1_d = "19910905"
1130
1129
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 ))
1133
1132
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 )
1137
1134
1138
1135
assert (p2 - p1 ) == expected
1139
1136
@@ -1152,14 +1149,14 @@ def test_add_offset(self):
1152
1149
np .timedelta64 (365 , "D" ),
1153
1150
timedelta (365 ),
1154
1151
]:
1155
- with pytest .raises (period . IncompatibleFrequency ):
1152
+ with pytest .raises (IncompatibleFrequency ):
1156
1153
p + o
1157
1154
1158
1155
if isinstance (o , np .timedelta64 ):
1159
1156
with pytest .raises (TypeError ):
1160
1157
o + p
1161
1158
else :
1162
- with pytest .raises (period . IncompatibleFrequency ):
1159
+ with pytest .raises (IncompatibleFrequency ):
1163
1160
o + p
1164
1161
1165
1162
for freq in ["M" , "2M" , "3M" ]:
@@ -1179,14 +1176,14 @@ def test_add_offset(self):
1179
1176
np .timedelta64 (365 , "D" ),
1180
1177
timedelta (365 ),
1181
1178
]:
1182
- with pytest .raises (period . IncompatibleFrequency ):
1179
+ with pytest .raises (IncompatibleFrequency ):
1183
1180
p + o
1184
1181
1185
1182
if isinstance (o , np .timedelta64 ):
1186
1183
with pytest .raises (TypeError ):
1187
1184
o + p
1188
1185
else :
1189
- with pytest .raises (period . IncompatibleFrequency ):
1186
+ with pytest .raises (IncompatibleFrequency ):
1190
1187
o + p
1191
1188
1192
1189
# freq is Tick
@@ -1226,14 +1223,14 @@ def test_add_offset(self):
1226
1223
np .timedelta64 (4 , "h" ),
1227
1224
timedelta (hours = 23 ),
1228
1225
]:
1229
- with pytest .raises (period . IncompatibleFrequency ):
1226
+ with pytest .raises (IncompatibleFrequency ):
1230
1227
p + o
1231
1228
1232
1229
if isinstance (o , np .timedelta64 ):
1233
1230
with pytest .raises (TypeError ):
1234
1231
o + p
1235
1232
else :
1236
- with pytest .raises (period . IncompatibleFrequency ):
1233
+ with pytest .raises (IncompatibleFrequency ):
1237
1234
o + p
1238
1235
1239
1236
for freq in ["H" , "2H" , "3H" ]:
@@ -1272,14 +1269,14 @@ def test_add_offset(self):
1272
1269
np .timedelta64 (3200 , "s" ),
1273
1270
timedelta (hours = 23 , minutes = 30 ),
1274
1271
]:
1275
- with pytest .raises (period . IncompatibleFrequency ):
1272
+ with pytest .raises (IncompatibleFrequency ):
1276
1273
p + o
1277
1274
1278
1275
if isinstance (o , np .timedelta64 ):
1279
1276
with pytest .raises (TypeError ):
1280
1277
o + p
1281
1278
else :
1282
- with pytest .raises (period . IncompatibleFrequency ):
1279
+ with pytest .raises (IncompatibleFrequency ):
1283
1280
o + p
1284
1281
1285
1282
def test_add_offset_nat (self ):
@@ -1376,7 +1373,7 @@ def test_sub_offset(self):
1376
1373
np .timedelta64 (365 , "D" ),
1377
1374
timedelta (365 ),
1378
1375
]:
1379
- with pytest .raises (period . IncompatibleFrequency ):
1376
+ with pytest .raises (IncompatibleFrequency ):
1380
1377
p - o
1381
1378
1382
1379
for freq in ["M" , "2M" , "3M" ]:
@@ -1391,7 +1388,7 @@ def test_sub_offset(self):
1391
1388
np .timedelta64 (365 , "D" ),
1392
1389
timedelta (365 ),
1393
1390
]:
1394
- with pytest .raises (period . IncompatibleFrequency ):
1391
+ with pytest .raises (IncompatibleFrequency ):
1395
1392
p - o
1396
1393
1397
1394
# freq is Tick
@@ -1411,7 +1408,7 @@ def test_sub_offset(self):
1411
1408
np .timedelta64 (4 , "h" ),
1412
1409
timedelta (hours = 23 ),
1413
1410
]:
1414
- with pytest .raises (period . IncompatibleFrequency ):
1411
+ with pytest .raises (IncompatibleFrequency ):
1415
1412
p - o
1416
1413
1417
1414
for freq in ["H" , "2H" , "3H" ]:
@@ -1434,7 +1431,7 @@ def test_sub_offset(self):
1434
1431
np .timedelta64 (3200 , "s" ),
1435
1432
timedelta (hours = 23 , minutes = 30 ),
1436
1433
]:
1437
- with pytest .raises (period . IncompatibleFrequency ):
1434
+ with pytest .raises (IncompatibleFrequency ):
1438
1435
p - o
1439
1436
1440
1437
def test_sub_offset_nat (self ):
@@ -1530,10 +1527,10 @@ def test_period_ops_offset(self):
1530
1527
assert result == exp
1531
1528
1532
1529
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 ):
1534
1531
p + offsets .Hour (2 )
1535
1532
1536
- with pytest .raises (period . IncompatibleFrequency , match = msg ):
1533
+ with pytest .raises (IncompatibleFrequency , match = msg ):
1537
1534
p - offsets .Hour (2 )
1538
1535
1539
1536
0 commit comments