Skip to content

CLN: f-string in pandas/core/accessor.py and pandas/core/algorithms.py #30120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions pandas/core/accessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ class PandasDelegate:
"""

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

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

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

@classmethod
def _add_delegate_accessors(
Expand Down
23 changes: 8 additions & 15 deletions pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,12 @@ def isin(comps, values) -> np.ndarray:
if not is_list_like(comps):
raise TypeError(
"only list-like objects are allowed to be passed"
" to isin(), you passed a [{comps_type}]".format(
comps_type=type(comps).__name__
)
f" to isin(), you passed a [{type(comps).__name__}]"
)
if not is_list_like(values):
raise TypeError(
"only list-like objects are allowed to be passed"
" to isin(), you passed a [{values_type}]".format(
values_type=type(values).__name__
)
f" to isin(), you passed a [{type(values).__name__}]"
)

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

# TODO: handle uint8
f = getattr(htable, "value_count_{dtype}".format(dtype=ndtype))
f = getattr(htable, f"value_count_{ndtype}")
keys, counts = f(values, dropna)

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

values, _ = _ensure_data(values)
ndtype = values.dtype.name
f = getattr(htable, "duplicated_{dtype}".format(dtype=ndtype))
f = getattr(htable, f"duplicated_{ndtype}")
return f(values, keep=keep)


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

f = getattr(htable, "mode_{dtype}".format(dtype=ndtype))
f = getattr(htable, f"mode_{ndtype}")
result = f(values, dropna=dropna)
try:
result = np.sort(result)
except TypeError as e:
warn("Unable to sort modes: {error}".format(error=e))
warn(f"Unable to sort modes: {e}")

result = _reconstruct_data(result, original.dtype, original)
return Series(result)
Expand Down Expand Up @@ -1110,10 +1106,7 @@ def compute(self, method):
n = self.n
dtype = self.obj.dtype
if not self.is_valid_dtype_n_method(dtype):
raise TypeError(
"Cannot use method '{method}' with "
"dtype {dtype}".format(method=method, dtype=dtype)
)
raise TypeError(f"Cannot use method '{method}' with dtype {dtype}")

if n <= 0:
return self.obj[[]]
Expand Down