@@ -359,8 +359,8 @@ def apply_index(self, i):
359
359
kwd = set (kwds ) - relativedelta_fast
360
360
raise NotImplementedError (
361
361
"DateOffset with relativedelta "
362
- "keyword(s) {kwd} not able to be "
363
- "applied vectorized" . format ( kwd = kwd )
362
+ f "keyword(s) { kwd } not able to be "
363
+ "applied vectorized"
364
364
)
365
365
366
366
def isAnchored (self ):
@@ -379,7 +379,7 @@ def _repr_attrs(self):
379
379
continue
380
380
elif attr not in exclude :
381
381
value = getattr (self , attr )
382
- attrs .append ("{attr}={value}" . format ( attr = attr , value = value ) )
382
+ attrs .append (f "{ attr } ={ value } " )
383
383
384
384
out = ""
385
385
if attrs :
@@ -449,7 +449,7 @@ def freqstr(self):
449
449
return repr (self )
450
450
451
451
if self .n != 1 :
452
- fstr = "{ n}{code}". format ( n = self . n , code = code )
452
+ fstr = f" { self . n } { code } "
453
453
else :
454
454
fstr = code
455
455
@@ -467,15 +467,15 @@ def _offset_str(self):
467
467
468
468
@property
469
469
def nanos (self ):
470
- raise ValueError ("{name } is a non-fixed frequency". format ( name = self ) )
470
+ raise ValueError (f" { self } is a non-fixed frequency" )
471
471
472
472
473
473
class SingleConstructorOffset (DateOffset ):
474
474
@classmethod
475
475
def _from_name (cls , suffix = None ):
476
476
# default _from_name calls cls with no args
477
477
if suffix :
478
- raise ValueError ("Bad freq suffix {suffix}" . format ( suffix = suffix ) )
478
+ raise ValueError (f "Bad freq suffix { suffix } " )
479
479
return cls ()
480
480
481
481
@@ -513,7 +513,7 @@ def offset(self):
513
513
514
514
def _repr_attrs (self ):
515
515
if self .offset :
516
- attrs = ["offset={offset!r}" . format ( offset = self .offset )]
516
+ attrs = [f "offset={ repr ( self .offset )} " ]
517
517
else :
518
518
attrs = None
519
519
out = ""
@@ -966,10 +966,10 @@ def _onOffset(self, dt):
966
966
def _repr_attrs (self ):
967
967
out = super ()._repr_attrs ()
968
968
hours = "," .join (
969
- "{}-{}" . format ( st .strftime ("%H:%M" ), en .strftime ("%H:%M" ))
969
+ f' { st .strftime ("%H:%M" )} - { en .strftime ("%H:%M" )} '
970
970
for st , en in zip (self .start , self .end )
971
971
)
972
- attrs = ["{prefix }={hours}". format ( prefix = self . _prefix , hours = hours ) ]
972
+ attrs = [f" { self . _prefix } ={ hours } " ]
973
973
out += ": " + ", " .join (attrs )
974
974
return out
975
975
@@ -1113,7 +1113,7 @@ def name(self):
1113
1113
return self .rule_code
1114
1114
else :
1115
1115
month = ccalendar .MONTH_ALIASES [self .n ]
1116
- return "{code }-{month}". format ( code = self . rule_code , month = month )
1116
+ return f" { self . code_rule } -{ month } "
1117
1117
1118
1118
def onOffset (self , dt ):
1119
1119
if self .normalize and not _is_normalized (dt ):
@@ -1296,9 +1296,10 @@ def __init__(self, n=1, normalize=False, day_of_month=None):
1296
1296
else :
1297
1297
object .__setattr__ (self , "day_of_month" , int (day_of_month ))
1298
1298
if not self ._min_day_of_month <= self .day_of_month <= 27 :
1299
- msg = "day_of_month must be {min}<=day_of_month<=27, got {day}"
1300
1299
raise ValueError (
1301
- msg .format (min = self ._min_day_of_month , day = self .day_of_month )
1300
+ "day_of_month must be "
1301
+ f"{ self ._min_day_of_month } <=day_of_month<=27, "
1302
+ f"got { self .day_of_month } "
1302
1303
)
1303
1304
1304
1305
@classmethod
@@ -1307,7 +1308,7 @@ def _from_name(cls, suffix=None):
1307
1308
1308
1309
@property
1309
1310
def rule_code (self ):
1310
- suffix = "-{day_of_month}" . format ( day_of_month = self .day_of_month )
1311
+ suffix = f "-{ self .day_of_month } "
1311
1312
return self ._prefix + suffix
1312
1313
1313
1314
@apply_wraps
@@ -1527,9 +1528,7 @@ def __init__(self, n=1, normalize=False, weekday=None):
1527
1528
1528
1529
if self .weekday is not None :
1529
1530
if self .weekday < 0 or self .weekday > 6 :
1530
- raise ValueError (
1531
- "Day must be 0<=day<=6, got {day}" .format (day = self .weekday )
1532
- )
1531
+ raise ValueError (f"Day must be 0<=day<=6, got { self .weekday } " )
1533
1532
1534
1533
def isAnchored (self ):
1535
1534
return self .n == 1 and self .weekday is not None
@@ -1541,9 +1540,7 @@ def apply(self, other):
1541
1540
1542
1541
if not isinstance (other , datetime ):
1543
1542
raise TypeError (
1544
- "Cannot add {typ} to {cls}" .format (
1545
- typ = type (other ).__name__ , cls = type (self ).__name__
1546
- )
1543
+ f"Cannot add { type (other ).__name__ } to { type (self ).__name__ } "
1547
1544
)
1548
1545
1549
1546
k = self .n
@@ -1621,7 +1618,7 @@ def rule_code(self):
1621
1618
suffix = ""
1622
1619
if self .weekday is not None :
1623
1620
weekday = ccalendar .int_to_weekday [self .weekday ]
1624
- suffix = "-{weekday}" . format ( weekday = weekday )
1621
+ suffix = f "-{ weekday } "
1625
1622
return self ._prefix + suffix
1626
1623
1627
1624
@classmethod
@@ -1690,13 +1687,9 @@ def __init__(self, n=1, normalize=False, week=0, weekday=0):
1690
1687
object .__setattr__ (self , "week" , week )
1691
1688
1692
1689
if self .weekday < 0 or self .weekday > 6 :
1693
- raise ValueError (
1694
- "Day must be 0<=day<=6, got {day}" .format (day = self .weekday )
1695
- )
1690
+ raise ValueError (f"Day must be 0<=day<=6, got { self .weekday } " )
1696
1691
if self .week < 0 or self .week > 3 :
1697
- raise ValueError (
1698
- "Week must be 0<=week<=3, got {week}" .format (week = self .week )
1699
- )
1692
+ raise ValueError (f"Week must be 0<=week<=3, got { self .week } " )
1700
1693
1701
1694
def _get_offset_day (self , other ):
1702
1695
"""
@@ -1719,16 +1712,12 @@ def _get_offset_day(self, other):
1719
1712
@property
1720
1713
def rule_code (self ):
1721
1714
weekday = ccalendar .int_to_weekday .get (self .weekday , "" )
1722
- return "{prefix}-{week}{weekday}" .format (
1723
- prefix = self ._prefix , week = self .week + 1 , weekday = weekday
1724
- )
1715
+ return f"{ self ._prefix } -{ self .week + 1 } { weekday } "
1725
1716
1726
1717
@classmethod
1727
1718
def _from_name (cls , suffix = None ):
1728
1719
if not suffix :
1729
- raise ValueError (
1730
- "Prefix {prefix!r} requires a suffix." .format (prefix = cls ._prefix )
1731
- )
1720
+ raise ValueError (f"Prefix { repr (cls ._prefix )} requires a suffix." )
1732
1721
# TODO: handle n here...
1733
1722
# only one digit weeks (1 --> week 0, 2 --> week 1, etc.)
1734
1723
week = int (suffix [0 ]) - 1
@@ -1768,9 +1757,7 @@ def __init__(self, n=1, normalize=False, weekday=0):
1768
1757
raise ValueError ("N cannot be 0" )
1769
1758
1770
1759
if self .weekday < 0 or self .weekday > 6 :
1771
- raise ValueError (
1772
- "Day must be 0<=day<=6, got {day}" .format (day = self .weekday )
1773
- )
1760
+ raise ValueError (f"Day must be 0<=day<=6, got { self .weekday } " )
1774
1761
1775
1762
def _get_offset_day (self , other ):
1776
1763
"""
@@ -1794,14 +1781,12 @@ def _get_offset_day(self, other):
1794
1781
@property
1795
1782
def rule_code (self ):
1796
1783
weekday = ccalendar .int_to_weekday .get (self .weekday , "" )
1797
- return "{prefix }-{weekday}". format ( prefix = self . _prefix , weekday = weekday )
1784
+ return f" { self . _prefix } -{ weekday } "
1798
1785
1799
1786
@classmethod
1800
1787
def _from_name (cls , suffix = None ):
1801
1788
if not suffix :
1802
- raise ValueError (
1803
- "Prefix {prefix!r} requires a suffix." .format (prefix = cls ._prefix )
1804
- )
1789
+ raise ValueError (f"Prefix { repr (cls ._prefix )} requires a suffix." )
1805
1790
# TODO: handle n here...
1806
1791
weekday = ccalendar .weekday_to_int [suffix ]
1807
1792
return cls (weekday = weekday )
@@ -1847,7 +1832,7 @@ def _from_name(cls, suffix=None):
1847
1832
@property
1848
1833
def rule_code (self ):
1849
1834
month = ccalendar .MONTH_ALIASES [self .startingMonth ]
1850
- return "{prefix }-{month}". format ( prefix = self . _prefix , month = month )
1835
+ return f" { self . _prefix } -{ month } "
1851
1836
1852
1837
@apply_wraps
1853
1838
def apply (self , other ):
@@ -1990,7 +1975,7 @@ def _from_name(cls, suffix=None):
1990
1975
@property
1991
1976
def rule_code (self ):
1992
1977
month = ccalendar .MONTH_ALIASES [self .month ]
1993
- return "{prefix }-{month}". format ( prefix = self . _prefix , month = month )
1978
+ return f" { self . _prefix } -{ month } "
1994
1979
1995
1980
1996
1981
class BYearEnd (YearOffset ):
@@ -2104,9 +2089,7 @@ def __init__(
2104
2089
raise ValueError ("N cannot be 0" )
2105
2090
2106
2091
if self .variation not in ["nearest" , "last" ]:
2107
- raise ValueError (
2108
- "{variation} is not a valid variation" .format (variation = self .variation )
2109
- )
2092
+ raise ValueError (f"{ self .variation } is not a valid variation" )
2110
2093
2111
2094
def isAnchored (self ):
2112
2095
return (
@@ -2211,7 +2194,7 @@ def get_year_end(self, dt):
2211
2194
def rule_code (self ):
2212
2195
prefix = self ._prefix
2213
2196
suffix = self .get_rule_code_suffix ()
2214
- return "{prefix}-{suffix}" . format ( prefix = prefix , suffix = suffix )
2197
+ return f "{ prefix } -{ suffix } "
2215
2198
2216
2199
def _get_suffix_prefix (self ):
2217
2200
if self .variation == "nearest" :
@@ -2223,9 +2206,7 @@ def get_rule_code_suffix(self):
2223
2206
prefix = self ._get_suffix_prefix ()
2224
2207
month = ccalendar .MONTH_ALIASES [self .startingMonth ]
2225
2208
weekday = ccalendar .int_to_weekday [self .weekday ]
2226
- return "{prefix}-{month}-{weekday}" .format (
2227
- prefix = prefix , month = month , weekday = weekday
2228
- )
2209
+ return f"{ prefix } -{ month } -{ weekday } "
2229
2210
2230
2211
@classmethod
2231
2212
def _parse_suffix (cls , varion_code , startingMonth_code , weekday_code ):
@@ -2234,9 +2215,7 @@ def _parse_suffix(cls, varion_code, startingMonth_code, weekday_code):
2234
2215
elif varion_code == "L" :
2235
2216
variation = "last"
2236
2217
else :
2237
- raise ValueError (
2238
- "Unable to parse varion_code: {code}" .format (code = varion_code )
2239
- )
2218
+ raise ValueError (f"Unable to parse varion_code: { varion_code } " )
2240
2219
2241
2220
startingMonth = ccalendar .MONTH_TO_CAL_NUM [startingMonth_code ]
2242
2221
weekday = ccalendar .weekday_to_int [weekday_code ]
@@ -2461,9 +2440,7 @@ def onOffset(self, dt):
2461
2440
def rule_code (self ):
2462
2441
suffix = self ._offset .get_rule_code_suffix ()
2463
2442
qtr = self .qtr_with_extra_week
2464
- return "{prefix}-{suffix}-{qtr}" .format (
2465
- prefix = self ._prefix , suffix = suffix , qtr = qtr
2466
- )
2443
+ return f"{ self ._prefix } -{ suffix } -{ qtr } "
2467
2444
2468
2445
@classmethod
2469
2446
def _from_name (cls , * args ):
@@ -2532,12 +2509,11 @@ def f(self, other):
2532
2509
except AttributeError :
2533
2510
# comparing with a non-Tick object
2534
2511
raise TypeError (
2535
- "Invalid comparison between {cls} and {typ}" .format (
2536
- cls = type (self ).__name__ , typ = type (other ).__name__
2537
- )
2512
+ f"Invalid comparison between { type (self ).__name__ } "
2513
+ f"and { type (other ).__name__ } "
2538
2514
)
2539
2515
2540
- f .__name__ = "__{opname}__" . format ( opname = op .__name__ )
2516
+ f .__name__ = f "__{ op .__name__ } __"
2541
2517
return f
2542
2518
2543
2519
@@ -2572,8 +2548,7 @@ def __add__(self, other):
2572
2548
return NotImplemented
2573
2549
except OverflowError :
2574
2550
raise OverflowError (
2575
- "the add operation between {self} and {other} "
2576
- "will overflow" .format (self = self , other = other )
2551
+ f"the add operation between { self } and { other } will overflow"
2577
2552
)
2578
2553
2579
2554
def __eq__ (self , other ) -> bool :
@@ -2645,9 +2620,7 @@ def apply(self, other):
2645
2620
elif isinstance (other , type (self )):
2646
2621
return type (self )(self .n + other .n )
2647
2622
2648
- raise ApplyTypeError (
2649
- "Unhandled type: {type_str}" .format (type_str = type (other ).__name__ )
2650
- )
2623
+ raise ApplyTypeError (f"Unhandled type: { type (other ).__name__ } " )
2651
2624
2652
2625
def isAnchored (self ):
2653
2626
return False
@@ -2783,9 +2756,7 @@ def generate_range(start=None, end=None, periods=None, offset=BDay()):
2783
2756
# faster than cur + offset
2784
2757
next_date = offset .apply (cur )
2785
2758
if next_date <= cur :
2786
- raise ValueError (
2787
- "Offset {offset} did not increment date" .format (offset = offset )
2788
- )
2759
+ raise ValueError (f"Offset { offset } did not increment date" )
2789
2760
cur = next_date
2790
2761
else :
2791
2762
while cur >= end :
@@ -2799,9 +2770,7 @@ def generate_range(start=None, end=None, periods=None, offset=BDay()):
2799
2770
# faster than cur + offset
2800
2771
next_date = offset .apply (cur )
2801
2772
if next_date >= cur :
2802
- raise ValueError (
2803
- "Offset {offset} did not decrement date" .format (offset = offset )
2804
- )
2773
+ raise ValueError (f"Offset { offset } did not decrement date" )
2805
2774
cur = next_date
2806
2775
2807
2776
0 commit comments