From 50b261c6b43ff933301d1e531a4a885947089582 Mon Sep 17 00:00:00 2001 From: Sarah Donehower Date: Tue, 3 Dec 2019 16:17:13 -0800 Subject: [PATCH 1/3] f strings in core/series --- pandas/core/series.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 11e87a4eed27f..4bc3c507f2a53 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -104,9 +104,9 @@ def _coerce_method(converter): def wrapper(self): if len(self) == 1: return converter(self.iloc[0]) - raise TypeError("cannot convert the series to {0}".format(str(converter))) + raise TypeError(f"cannot convert the series to {str(converter)}") - wrapper.__name__ = "__{name}__".format(name=converter.__name__) + wrapper.__name__ = f"__{converter.__name__}__" return wrapper @@ -274,8 +274,8 @@ def __init__( try: if len(index) != len(data): raise ValueError( - "Length of passed values is {val}, " - "index implies {ind}".format(val=len(data), ind=len(index)) + f"Length of passed values is {len(data)}, " + "index implies {len(index)}." ) except TypeError: pass @@ -1521,7 +1521,7 @@ def items(self): -------- >>> s = pd.Series(['A', 'B', 'C']) >>> for index, value in s.items(): - ... print("Index : {}, Value : {}".format(index, value)) + ... print(f"Index : {index}, Value : {value}") Index : 0, Value : A Index : 1, Value : B Index : 2, Value : C @@ -2228,7 +2228,7 @@ def corr(self, other, method="pearson", min_periods=None): raise ValueError( "method must be either 'pearson', " "'spearman', 'kendall', or a callable, " - "'{method}' was supplied".format(method=method) + f"'{method}' was supplied" ) def cov(self, other, min_periods=None): @@ -2944,7 +2944,7 @@ def _try_kind_sort(arr): sortedIdx[n:] = idx[good][argsorted] sortedIdx[:n] = idx[bad] else: - raise ValueError("invalid na_position: {!r}".format(na_position)) + raise ValueError(f"invalid na_position: {na_position}") result = self._constructor(arr[sortedIdx], index=self.index[sortedIdx]) @@ -3836,7 +3836,7 @@ def _reduce( elif isinstance(delegate, np.ndarray): if numeric_only: raise NotImplementedError( - "Series.{0} does not implement numeric_only.".format(name) + f"Series.{name} does not implement numeric_only." ) with np.errstate(all="ignore"): return op(delegate, skipna=skipna, **kwds) From 81a55036267c5185db8493daec925a2f04bdcb5a Mon Sep 17 00:00:00 2001 From: Sarah Donehower Date: Wed, 4 Dec 2019 13:56:55 -0800 Subject: [PATCH 2/3] Update pandas/core/series.py Co-Authored-By: Simon Hawkins --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 4bc3c507f2a53..9b350aec9313b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -104,7 +104,7 @@ def _coerce_method(converter): def wrapper(self): if len(self) == 1: return converter(self.iloc[0]) - raise TypeError(f"cannot convert the series to {str(converter)}") + raise TypeError(f"cannot convert the series to {converter}") wrapper.__name__ = f"__{converter.__name__}__" return wrapper From 5812f540aac6becf8ce35cfb0ab8bed9ce691c12 Mon Sep 17 00:00:00 2001 From: Sarah Donehower Date: Wed, 4 Dec 2019 13:57:12 -0800 Subject: [PATCH 3/3] Update pandas/core/series.py Co-Authored-By: Simon Hawkins --- pandas/core/series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 9b350aec9313b..0d4c69977e84b 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -275,7 +275,7 @@ def __init__( if len(index) != len(data): raise ValueError( f"Length of passed values is {len(data)}, " - "index implies {len(index)}." + f"index implies {len(index)}." ) except TypeError: pass