@@ -117,7 +117,7 @@ def validate(self):
117
117
]:
118
118
raise ValueError ("closed must be 'right', 'left', 'both' or 'neither'" )
119
119
if not isinstance (self .obj , (ABCSeries , ABCDataFrame )):
120
- raise TypeError ("invalid type: {}" . format ( type (self )) )
120
+ raise TypeError (f "invalid type: { type (self )} " )
121
121
122
122
def _create_blocks (self ):
123
123
"""
@@ -163,9 +163,7 @@ def __getattr__(self, attr):
163
163
if attr in self .obj :
164
164
return self [attr ]
165
165
166
- raise AttributeError (
167
- "%r object has no attribute %r" % (type (self ).__name__ , attr )
168
- )
166
+ raise AttributeError (f"{ type (self ).__name__ } object has no attribute { attr } " )
169
167
170
168
def _dir_additions (self ):
171
169
return self .obj ._dir_additions ()
@@ -212,17 +210,16 @@ def __repr__(self) -> str:
212
210
"""
213
211
214
212
attrs = (
215
- "{k}={v}" . format ( k = k , v = getattr (self , k ))
213
+ "{k}={getattr(self, k)}"
216
214
for k in self ._attributes
217
215
if getattr (self , k , None ) is not None
218
216
)
219
- return "{klass} [{attrs}]" .format (
220
- klass = self ._window_type , attrs = "," .join (attrs )
221
- )
217
+ attrs = "," .join (attrs )
218
+ return f"{ self ._window_type } [{ attrs } ]"
222
219
223
220
def __iter__ (self ):
224
221
url = "https://github.com/pandas-dev/pandas/issues/11704"
225
- raise NotImplementedError ("See issue #11704 {url}" . format ( url = url ) )
222
+ raise NotImplementedError (f "See issue #11704 { url } " )
226
223
227
224
def _get_index (self ) -> Optional [np .ndarray ]:
228
225
"""
@@ -250,15 +247,15 @@ def _prep_values(self, values: Optional[np.ndarray] = None) -> np.ndarray:
250
247
values = ensure_float64 (values )
251
248
elif needs_i8_conversion (values .dtype ):
252
249
raise NotImplementedError (
253
- "ops for {action } for this "
254
- "dtype {dtype} are not "
255
- "implemented" . format ( action = self . _window_type , dtype = values . dtype )
250
+ f "ops for { self . _window_type } for this "
251
+ f "dtype { values . dtype } are not "
252
+ "implemented"
256
253
)
257
254
else :
258
255
try :
259
256
values = ensure_float64 (values )
260
257
except (ValueError , TypeError ):
261
- raise TypeError ("cannot handle this type -> {0}" . format ( values .dtype ) )
258
+ raise TypeError (f "cannot handle this type -> { values .dtype } " )
262
259
263
260
# Convert inf to nan for C funcs
264
261
inf = np .isinf (values )
@@ -383,8 +380,7 @@ def _get_roll_func(self, func_name: str) -> Callable:
383
380
window_func = getattr (window_aggregations , func_name , None )
384
381
if window_func is None :
385
382
raise ValueError (
386
- "we do not support this function "
387
- "in window_aggregations.{func_name}" .format (func_name = func_name )
383
+ "we do not support this function " f"in window_aggregations.{ func_name } "
388
384
)
389
385
return window_func
390
386
@@ -395,10 +391,8 @@ def _get_cython_func_type(self, func):
395
391
Variable algorithms do not use window while fixed do.
396
392
"""
397
393
if self .is_freq_type :
398
- return self ._get_roll_func ("{}_variable" .format (func ))
399
- return partial (
400
- self ._get_roll_func ("{}_fixed" .format (func )), win = self ._get_window ()
401
- )
394
+ return self ._get_roll_func (f"{ func } _variable" )
395
+ return partial (self ._get_roll_func (f"{ func } _fixed" ), win = self ._get_window ())
402
396
403
397
def _get_window_indexer (self ):
404
398
"""
@@ -917,11 +911,11 @@ def validate(self):
917
911
import scipy .signal as sig
918
912
919
913
if not isinstance (self .win_type , str ):
920
- raise ValueError ("Invalid win_type {0}" . format ( self .win_type ) )
914
+ raise ValueError (f "Invalid win_type { self .win_type } " )
921
915
if getattr (sig , self .win_type , None ) is None :
922
- raise ValueError ("Invalid win_type {0}" . format ( self .win_type ) )
916
+ raise ValueError (f "Invalid win_type { self .win_type } " )
923
917
else :
924
- raise ValueError ("Invalid window {0}" . format ( window ) )
918
+ raise ValueError (f "Invalid window { window } " )
925
919
926
920
def _get_win_type (self , kwargs : Dict ) -> Union [str , Tuple ]:
927
921
"""
@@ -958,11 +952,10 @@ def _validate_win_type(win_type, kwargs):
958
952
return win_type
959
953
960
954
def _pop_args (win_type , arg_names , kwargs ):
961
- msg = "%s window requires %%s" % win_type
962
955
all_args = []
963
956
for n in arg_names :
964
957
if n not in kwargs :
965
- raise ValueError (msg % n )
958
+ raise ValueError (f" { win_type } window requires { n } " )
966
959
all_args .append (kwargs .pop (n ))
967
960
return all_args
968
961
@@ -1634,12 +1627,12 @@ def _get_cov(X, Y):
1634
1627
1635
1628
>>> v1 = [3, 3, 3, 5, 8]
1636
1629
>>> v2 = [3, 4, 4, 4, 8]
1637
- >>> fmt = "{0:.6f}" # limit the printed precision to 6 digits
1630
+ >>> precision = 6 # limit the printed precision to 6 digits
1638
1631
>>> # numpy returns a 2X2 array, the correlation coefficient
1639
1632
>>> # is the number at entry [0][1]
1640
- >>> print(fmt.format( np.corrcoef(v1[:-1], v2[:-1])[0][1]) )
1633
+ >>> print(f"{ np.corrcoef(v1[:-1], v2[:-1])[0][1]:.{precision}f}" )
1641
1634
0.333333
1642
- >>> print(fmt.format( np.corrcoef(v1[1:], v2[1:])[0][1]) )
1635
+ >>> print(f"{ np.corrcoef(v1[1:], v2[1:])[0][1]:.{precision}f}" )
1643
1636
0.916949
1644
1637
>>> s1 = pd.Series(v1)
1645
1638
>>> s2 = pd.Series(v2)
@@ -1729,9 +1722,9 @@ def _on(self) -> Index:
1729
1722
return Index (self .obj [self .on ])
1730
1723
else :
1731
1724
raise ValueError (
1732
- "invalid on specified as {on}, "
1725
+ f "invalid on specified as { self . on } , "
1733
1726
"must be a column (of DataFrame), an Index "
1734
- "or None" . format ( on = self . on )
1727
+ "or None"
1735
1728
)
1736
1729
1737
1730
def validate (self ):
@@ -1780,9 +1773,7 @@ def _validate_monotonic(self):
1780
1773
formatted = self .on
1781
1774
if self .on is None :
1782
1775
formatted = "index"
1783
- raise ValueError (
1784
- "{formatted} must be monotonic" .format (formatted = formatted )
1785
- )
1776
+ raise ValueError (f"{ formatted } must be monotonic" )
1786
1777
1787
1778
def _validate_freq (self ):
1788
1779
"""
@@ -1794,9 +1785,9 @@ def _validate_freq(self):
1794
1785
return to_offset (self .window )
1795
1786
except (TypeError , ValueError ):
1796
1787
raise ValueError (
1797
- "passed window {window} is not "
1788
+ f "passed window { self . window } is not "
1798
1789
"compatible with a datetimelike "
1799
- "index" . format ( window = self . window )
1790
+ "index"
1800
1791
)
1801
1792
1802
1793
_agg_see_also_doc = dedent (
@@ -1941,11 +1932,11 @@ def skew(self, **kwargs):
1941
1932
four matching the equivalent function call using `scipy.stats`.
1942
1933
1943
1934
>>> arr = [1, 2, 3, 4, 999]
1944
- >>> fmt = "{0:.6f}" # limit the printed precision to 6 digits
1935
+ >>> precision = 6 # limit the printed precision to 6 digits
1945
1936
>>> import scipy.stats
1946
- >>> print(fmt.format( scipy.stats.kurtosis(arr[:-1], bias=False)) )
1937
+ >>> print(f"{ scipy.stats.kurtosis(arr[:-1], bias=False):.{precision}f}" )
1947
1938
-1.200000
1948
- >>> print(fmt.format( scipy.stats.kurtosis(arr[1:], bias=False)) )
1939
+ >>> print(f"{ scipy.stats.kurtosis(arr[1:], bias=False):.{precision}f}" )
1949
1940
3.999946
1950
1941
>>> s = pd.Series(arr)
1951
1942
>>> s.rolling(4).kurt()
0 commit comments