-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN: Old string formatting: .format() -> f"" #30328
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
Changes from 4 commits
01645eb
0c07186
dc0195c
9c106db
f3b9992
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -232,7 +232,7 @@ def _has_valid_tuple(self, key: Tuple): | |
except ValueError: | ||
raise ValueError( | ||
"Location based indexing can only have " | ||
"[{types}] types".format(types=self._valid_types) | ||
f"[{self._valid_types}] types" | ||
) | ||
|
||
def _is_nested_tuple_indexer(self, tup: Tuple) -> bool: | ||
|
@@ -286,7 +286,7 @@ def _has_valid_positional_setitem_indexer(self, indexer) -> bool: | |
bool | ||
""" | ||
if isinstance(indexer, dict): | ||
raise IndexError("{0} cannot enlarge its target object".format(self.name)) | ||
raise IndexError(f"{self.name} cannot enlarge its target object") | ||
else: | ||
if not isinstance(indexer, tuple): | ||
indexer = _tuplify(self.ndim, indexer) | ||
|
@@ -300,13 +300,10 @@ def _has_valid_positional_setitem_indexer(self, indexer) -> bool: | |
elif is_integer(i): | ||
if i >= len(ax): | ||
raise IndexError( | ||
"{name} cannot enlarge its target " | ||
"object".format(name=self.name) | ||
f"{self.name} cannot enlarge its target object" | ||
) | ||
elif isinstance(i, dict): | ||
raise IndexError( | ||
"{name} cannot enlarge its target object".format(name=self.name) | ||
) | ||
raise IndexError(f"{self.name} cannot enlarge its target object") | ||
|
||
return True | ||
|
||
|
@@ -1167,16 +1164,14 @@ def _validate_read_indexer( | |
if missing: | ||
if missing == len(indexer): | ||
raise KeyError( | ||
"None of [{key}] are in the [{axis}]".format( | ||
key=key, axis=self.obj._get_axis_name(axis) | ||
) | ||
f"None of [{key}] are in the [{self.obj._get_axis_name(axis)}]" | ||
) | ||
|
||
# We (temporarily) allow for some missing keys with .loc, except in | ||
# some cases (e.g. setting) in which "raise_missing" will be False | ||
if not (self.name == "loc" and not raise_missing): | ||
not_found = list(set(key) - set(ax)) | ||
raise KeyError("{} not in index".format(not_found)) | ||
raise KeyError(f"{not_found} not in index") | ||
|
||
# we skip the warning on Categorical/Interval | ||
# as this check is actually done (check for | ||
|
@@ -1905,17 +1900,14 @@ def _validate_key(self, key, axis: int): | |
|
||
# check that the key has a numeric dtype | ||
if not is_numeric_dtype(arr.dtype): | ||
raise IndexError( | ||
".iloc requires numeric indexers, got {arr}".format(arr=arr) | ||
) | ||
raise IndexError(f".iloc requires numeric indexers, got {arr}") | ||
|
||
# check that the key does not exceed the maximum size of the index | ||
if len(arr) and (arr.max() >= len_axis or arr.min() < -len_axis): | ||
raise IndexError("positional indexers are out-of-bounds") | ||
else: | ||
raise ValueError( | ||
"Can only index by location with " | ||
"a [{types}]".format(types=self._valid_types) | ||
"Can only index by location with " f"a [{self._valid_types}]" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extra space crept in, also down on 2059 (im going to stop pointing those out now) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My fault. Missed them. Working... Expected such things to be fixed by a linter |
||
) | ||
|
||
def _has_valid_setitem_indexer(self, indexer): | ||
|
@@ -2064,8 +2056,7 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False): | |
return obj | ||
except ValueError: | ||
raise ValueError( | ||
"Can only index by location with " | ||
"a [{types}]".format(types=self._valid_types) | ||
"Can only index by location with " f"a [{self._valid_types}]" | ||
) | ||
|
||
|
||
|
@@ -2327,7 +2318,7 @@ def check_bool_indexer(index: Index, key) -> np.ndarray: | |
# GH26658 | ||
if len(result) != len(index): | ||
raise IndexError( | ||
"Item wrong length {} instead of {}.".format(len(result), len(index)) | ||
f"Item wrong length {len(result)} instead of {len(index)}." | ||
) | ||
|
||
return result | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nitpick: can you define
axis_name = self.obj._get_axis_name(axis)
on the previous line and useaxis_name
inside the fstring?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.