Skip to content

f-string update for core.base. #30023

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 3 commits into from
Dec 4, 2019
Merged
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
27 changes: 8 additions & 19 deletions pandas/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,7 @@ def __setattr__(self, key, value):
or key in type(self).__dict__
or getattr(self, key, None) is not None
):
raise AttributeError(
"You cannot add any new attribute '{key}'".format(key=key)
)
raise AttributeError(f"You cannot add any new attribute '{key}'")
object.__setattr__(self, key, value)


Expand Down Expand Up @@ -220,28 +218,22 @@ def _obj_with_exclusions(self):

def __getitem__(self, key):
if self._selection is not None:
raise IndexError(
"Column(s) {selection} already selected".format(
selection=self._selection
)
)
raise IndexError(f"Column(s) {self._selection} already selected")

if isinstance(key, (list, tuple, ABCSeries, ABCIndexClass, np.ndarray)):
if len(self.obj.columns.intersection(key)) != len(key):
bad_keys = list(set(key).difference(self.obj.columns))
raise KeyError(
"Columns not found: {missing}".format(missing=str(bad_keys)[1:-1])
)
raise KeyError(f"Columns not found: {str(bad_keys)[1:-1]}")
return self._gotitem(list(key), ndim=2)

elif not getattr(self, "as_index", False):
if key not in self.obj.columns:
raise KeyError("Column not found: {key}".format(key=key))
raise KeyError(f"Column not found: {key}")
return self._gotitem(key, ndim=2)

else:
if key not in self.obj:
raise KeyError("Column not found: {key}".format(key=key))
raise KeyError(f"Column not found: {key}")
return self._gotitem(key, ndim=1)

def _gotitem(self, key, ndim, subset=None):
Expand Down Expand Up @@ -293,8 +285,7 @@ def _try_aggregate_string_function(self, arg: str, *args, **kwargs):
return f(self, *args, **kwargs)

raise AttributeError(
"'{arg}' is not a valid function for "
"'{cls}' object".format(arg=arg, cls=type(self).__name__)
f"'{arg}' is not a valid function for '{type(self).__name__}' object"
)

def _aggregate(self, arg, *args, **kwargs):
Expand Down Expand Up @@ -359,7 +350,7 @@ def _aggregate(self, arg, *args, **kwargs):
elif isinstance(obj, ABCSeries):
raise SpecificationError("nested renamer is not supported")
elif isinstance(obj, ABCDataFrame) and k not in obj.columns:
raise KeyError("Column '{col}' does not exist!".format(col=k))
raise KeyError(f"Column '{k}' does not exist!")

arg = new_arg

Expand Down Expand Up @@ -1101,9 +1092,7 @@ def _reduce(
func = getattr(self, name, None)
if func is None:
raise TypeError(
"{klass} cannot perform the operation {op}".format(
klass=type(self).__name__, op=name
)
f"{type(self).__name__} cannot perform the operation {name}"
)
return func(skipna=skipna, **kwds)

Expand Down