@@ -1312,28 +1312,29 @@ def test_add_offset(self):
13121312 assert p + offsets .MonthEnd (12 ) == exp
13131313 assert offsets .MonthEnd (12 ) + p == exp
13141314
1315+ msg = "|" .join (
1316+ [
1317+ "Input has different freq" ,
1318+ "Input cannot be converted to Period" ,
1319+ ]
1320+ )
1321+
13151322 for o in [
13161323 offsets .YearBegin (2 ),
13171324 offsets .MonthBegin (1 ),
13181325 offsets .Minute (),
13191326 np .timedelta64 (365 , "D" ),
13201327 timedelta (365 ),
13211328 ]:
1322- msg = "Input has different freq|Input cannot be converted to Period"
1329+
13231330 with pytest .raises (IncompatibleFrequency , match = msg ):
13241331 p + o
13251332
13261333 if isinstance (o , np .timedelta64 ):
1327- msg = "cannot use operands with types"
1328- with pytest .raises (TypeError , match = msg ):
1334+ td_msg = "cannot use operands with types"
1335+ with pytest .raises (TypeError , match = td_msg ):
13291336 o + p
13301337 else :
1331- msg = "|" .join (
1332- [
1333- "Input has different freq" ,
1334- "Input cannot be converted to Period" ,
1335- ]
1336- )
13371338 with pytest .raises (IncompatibleFrequency , match = msg ):
13381339 o + p
13391340
@@ -1368,28 +1369,28 @@ def test_add_offset(self):
13681369 assert p + timedelta (hours = 48 ) == exp
13691370 assert timedelta (hours = 48 ) + p == exp
13701371
1372+ msg = "|" .join (
1373+ [
1374+ "Input has different freq" ,
1375+ "Input cannot be converted to Period" ,
1376+ ]
1377+ )
1378+
13711379 for o in [
13721380 offsets .YearBegin (2 ),
13731381 offsets .MonthBegin (1 ),
13741382 offsets .Minute (),
13751383 np .timedelta64 (4 , "h" ),
13761384 timedelta (hours = 23 ),
13771385 ]:
1378- msg = "Input has different freq|Input cannot be converted to Period"
13791386 with pytest .raises (IncompatibleFrequency , match = msg ):
13801387 p + o
13811388
13821389 if isinstance (o , np .timedelta64 ):
1383- msg = "cannot use operands with types"
1384- with pytest .raises (TypeError , match = msg ):
1390+ td_msg = "cannot use operands with types"
1391+ with pytest .raises (TypeError , match = td_msg ):
13851392 o + p
13861393 else :
1387- msg = "|" .join (
1388- [
1389- "Input has different freq" ,
1390- "Input cannot be converted to Period" ,
1391- ]
1392- )
13931394 with pytest .raises (IncompatibleFrequency , match = msg ):
13941395 o + p
13951396
@@ -1423,34 +1424,40 @@ def test_add_offset(self):
14231424 assert p + timedelta (days = 4 , minutes = 180 ) == exp
14241425 assert timedelta (days = 4 , minutes = 180 ) + p == exp
14251426
1427+ msg = "|" .join (
1428+ [
1429+ "Input has different freq" ,
1430+ "Input cannot be converted to Period" ,
1431+ ]
1432+ )
1433+
14261434 for o in [
14271435 offsets .YearBegin (2 ),
14281436 offsets .MonthBegin (1 ),
14291437 offsets .Minute (),
14301438 np .timedelta64 (3200 , "s" ),
14311439 timedelta (hours = 23 , minutes = 30 ),
14321440 ]:
1433- msg = "Input has different freq|Input cannot be converted to Period"
14341441 with pytest .raises (IncompatibleFrequency , match = msg ):
14351442 p + o
14361443
14371444 if isinstance (o , np .timedelta64 ):
1438- msg = "cannot use operands with types"
1439- with pytest .raises (TypeError , match = msg ):
1445+ td_msg = "cannot use operands with types"
1446+ with pytest .raises (TypeError , match = td_msg ):
14401447 o + p
14411448 else :
1442- msg = "|" .join (
1443- [
1444- "Input has different freq" ,
1445- "Input cannot be converted to Period" ,
1446- ]
1447- )
14481449 with pytest .raises (IncompatibleFrequency , match = msg ):
14491450 o + p
14501451
14511452 def test_sub_offset (self ):
14521453 # freq is DateOffset
1453- msg = "Input has different freq|Input cannot be converted to Period"
1454+ msg = "|" .join (
1455+ [
1456+ "Input has different freq" ,
1457+ "Input cannot be converted to Period" ,
1458+ ]
1459+ )
1460+
14541461 for freq in ["A" , "2A" , "3A" ]:
14551462 p = Period ("2011" , freq = freq )
14561463 assert p - offsets .YearEnd (2 ) == Period ("2009" , freq = freq )
0 commit comments