Skip to content

Commit b85e5ee

Browse files
ganevgvproost
authored andcommitted
CLN: f-string in pandas/core/accessor.py and pandas/core/algorithms.py (pandas-dev#30120)
1 parent 8e36374 commit b85e5ee

File tree

2 files changed

+11
-18
lines changed

2 files changed

+11
-18
lines changed

pandas/core/accessor.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ class PandasDelegate:
4949
"""
5050

5151
def _delegate_property_get(self, name, *args, **kwargs):
52-
raise TypeError("You cannot access the property {name}".format(name=name))
52+
raise TypeError(f"You cannot access the property {name}")
5353

5454
def _delegate_property_set(self, name, value, *args, **kwargs):
55-
raise TypeError("The property {name} cannot be set".format(name=name))
55+
raise TypeError(f"The property {name} cannot be set")
5656

5757
def _delegate_method(self, name, *args, **kwargs):
58-
raise TypeError("You cannot call method {name}".format(name=name))
58+
raise TypeError(f"You cannot call method {name}")
5959

6060
@classmethod
6161
def _add_delegate_accessors(

pandas/core/algorithms.py

+8-15
Original file line numberDiff line numberDiff line change
@@ -395,16 +395,12 @@ def isin(comps, values) -> np.ndarray:
395395
if not is_list_like(comps):
396396
raise TypeError(
397397
"only list-like objects are allowed to be passed"
398-
" to isin(), you passed a [{comps_type}]".format(
399-
comps_type=type(comps).__name__
400-
)
398+
f" to isin(), you passed a [{type(comps).__name__}]"
401399
)
402400
if not is_list_like(values):
403401
raise TypeError(
404402
"only list-like objects are allowed to be passed"
405-
" to isin(), you passed a [{values_type}]".format(
406-
values_type=type(values).__name__
407-
)
403+
f" to isin(), you passed a [{type(values).__name__}]"
408404
)
409405

410406
if not isinstance(values, (ABCIndex, ABCSeries, np.ndarray)):
@@ -601,7 +597,7 @@ def _factorize_array(
601597
)
602598
@Appender(_shared_docs["factorize"])
603599
def factorize(
604-
values, sort: bool = False, na_sentinel: int = -1, size_hint: Optional[int] = None,
600+
values, sort: bool = False, na_sentinel: int = -1, size_hint: Optional[int] = None
605601
) -> Tuple[np.ndarray, Union[np.ndarray, ABCIndex]]:
606602
# Implementation notes: This method is responsible for 3 things
607603
# 1.) coercing data to array-like (ndarray, Index, extension array)
@@ -758,7 +754,7 @@ def _value_counts_arraylike(values, dropna: bool):
758754
# ndarray like
759755

760756
# TODO: handle uint8
761-
f = getattr(htable, "value_count_{dtype}".format(dtype=ndtype))
757+
f = getattr(htable, f"value_count_{ndtype}")
762758
keys, counts = f(values, dropna)
763759

764760
mask = isna(values)
@@ -794,7 +790,7 @@ def duplicated(values, keep="first") -> np.ndarray:
794790

795791
values, _ = _ensure_data(values)
796792
ndtype = values.dtype.name
797-
f = getattr(htable, "duplicated_{dtype}".format(dtype=ndtype))
793+
f = getattr(htable, f"duplicated_{ndtype}")
798794
return f(values, keep=keep)
799795

800796

@@ -833,12 +829,12 @@ def mode(values, dropna: bool = True) -> ABCSeries:
833829
values, _ = _ensure_data(values)
834830
ndtype = values.dtype.name
835831

836-
f = getattr(htable, "mode_{dtype}".format(dtype=ndtype))
832+
f = getattr(htable, f"mode_{ndtype}")
837833
result = f(values, dropna=dropna)
838834
try:
839835
result = np.sort(result)
840836
except TypeError as e:
841-
warn("Unable to sort modes: {error}".format(error=e))
837+
warn(f"Unable to sort modes: {e}")
842838

843839
result = _reconstruct_data(result, original.dtype, original)
844840
return Series(result)
@@ -1110,10 +1106,7 @@ def compute(self, method):
11101106
n = self.n
11111107
dtype = self.obj.dtype
11121108
if not self.is_valid_dtype_n_method(dtype):
1113-
raise TypeError(
1114-
"Cannot use method '{method}' with "
1115-
"dtype {dtype}".format(method=method, dtype=dtype)
1116-
)
1109+
raise TypeError(f"Cannot use method '{method}' with dtype {dtype}")
11171110

11181111
if n <= 0:
11191112
return self.obj[[]]

0 commit comments

Comments
 (0)