@@ -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
"""
@@ -164,7 +164,7 @@ def __getattr__(self, attr):
164
164
return self [attr ]
165
165
166
166
raise AttributeError (
167
- "%r object has no attribute %r" % ( type ( self ). __name__ , attr )
167
+ f"' { type ( self ). __name__ } ' object has no attribute ' { attr } '"
168
168
)
169
169
170
170
def _dir_additions (self ):
@@ -211,18 +211,17 @@ def __repr__(self) -> str:
211
211
Provide a nice str repr of our rolling object.
212
212
"""
213
213
214
- attrs = (
215
- "{k}={v}" .format (k = k , v = getattr (self , k ))
216
- for k in self ._attributes
217
- if getattr (self , k , None ) is not None
218
- )
219
- return "{klass} [{attrs}]" .format (
220
- klass = self ._window_type , attrs = "," .join (attrs )
214
+ attrs_list = (
215
+ f"{ attr_name } ={ getattr (self , attr_name )} "
216
+ for attr_name in self ._attributes
217
+ if getattr (self , attr_name , None ) is not None
221
218
)
219
+ attrs = "," .join (attrs_list )
220
+ return f"{ self ._window_type } [{ attrs } ]"
222
221
223
222
def __iter__ (self ):
224
223
url = "https://github.com/pandas-dev/pandas/issues/11704"
225
- raise NotImplementedError ("See issue #11704 {url}" . format ( url = url ) )
224
+ raise NotImplementedError (f "See issue #11704 { url } " )
226
225
227
226
def _get_index (self ) -> Optional [np .ndarray ]:
228
227
"""
@@ -250,15 +249,14 @@ def _prep_values(self, values: Optional[np.ndarray] = None) -> np.ndarray:
250
249
values = ensure_float64 (values )
251
250
elif needs_i8_conversion (values .dtype ):
252
251
raise NotImplementedError (
253
- "ops for {action} for this "
254
- "dtype {dtype} are not "
255
- "implemented" .format (action = self ._window_type , dtype = values .dtype )
252
+ f"ops for { self ._window_type } for this "
253
+ f"dtype { values .dtype } are not implemented"
256
254
)
257
255
else :
258
256
try :
259
257
values = ensure_float64 (values )
260
258
except (ValueError , TypeError ):
261
- raise TypeError ("cannot handle this type -> {0}" . format ( values .dtype ) )
259
+ raise TypeError (f "cannot handle this type -> { values .dtype } " )
262
260
263
261
# Convert inf to nan for C funcs
264
262
inf = np .isinf (values )
@@ -383,8 +381,7 @@ def _get_roll_func(self, func_name: str) -> Callable:
383
381
window_func = getattr (window_aggregations , func_name , None )
384
382
if window_func is None :
385
383
raise ValueError (
386
- "we do not support this function "
387
- "in window_aggregations.{func_name}" .format (func_name = func_name )
384
+ f"we do not support this function in window_aggregations.{ func_name } "
388
385
)
389
386
return window_func
390
387
@@ -395,10 +392,8 @@ def _get_cython_func_type(self, func):
395
392
Variable algorithms do not use window while fixed do.
396
393
"""
397
394
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
- )
395
+ return self ._get_roll_func (f"{ func } _variable" )
396
+ return partial (self ._get_roll_func (f"{ func } _fixed" ), win = self ._get_window ())
402
397
403
398
def _get_window_indexer (self ):
404
399
"""
@@ -917,11 +912,11 @@ def validate(self):
917
912
import scipy .signal as sig
918
913
919
914
if not isinstance (self .win_type , str ):
920
- raise ValueError ("Invalid win_type {0}" . format ( self .win_type ) )
915
+ raise ValueError (f "Invalid win_type { self .win_type } " )
921
916
if getattr (sig , self .win_type , None ) is None :
922
- raise ValueError ("Invalid win_type {0}" . format ( self .win_type ) )
917
+ raise ValueError (f "Invalid win_type { self .win_type } " )
923
918
else :
924
- raise ValueError ("Invalid window {0}" . format ( window ) )
919
+ raise ValueError (f "Invalid window { window } " )
925
920
926
921
def _get_win_type (self , kwargs : Dict ) -> Union [str , Tuple ]:
927
922
"""
@@ -958,11 +953,10 @@ def _validate_win_type(win_type, kwargs):
958
953
return win_type
959
954
960
955
def _pop_args (win_type , arg_names , kwargs ):
961
- msg = "%s window requires %%s" % win_type
962
956
all_args = []
963
957
for n in arg_names :
964
958
if n not in kwargs :
965
- raise ValueError (msg % n )
959
+ raise ValueError (f" { win_type } window requires { n } " )
966
960
all_args .append (kwargs .pop (n ))
967
961
return all_args
968
962
@@ -1634,12 +1628,11 @@ def _get_cov(X, Y):
1634
1628
1635
1629
>>> v1 = [3, 3, 3, 5, 8]
1636
1630
>>> v2 = [3, 4, 4, 4, 8]
1637
- >>> fmt = "{0:.6f}" # 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]:.6f}" )
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]:.6f}" )
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,10 @@ 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
1945
1935
>>> import scipy.stats
1946
- >>> print(fmt.format( scipy.stats.kurtosis(arr[:-1], bias=False)) )
1936
+ >>> print(f"{ scipy.stats.kurtosis(arr[:-1], bias=False):.6f}" )
1947
1937
-1.200000
1948
- >>> print(fmt.format( scipy.stats.kurtosis(arr[1:], bias=False)) )
1938
+ >>> print(f"{ scipy.stats.kurtosis(arr[1:], bias=False):.6f}" )
1949
1939
3.999946
1950
1940
>>> s = pd.Series(arr)
1951
1941
>>> s.rolling(4).kurt()
0 commit comments