Skip to content

Commit 0c07186

Browse files
author
Petr Baev
committed
CLN: String formatting % -> f-strings, flake8
1 parent 01645eb commit 0c07186

File tree

5 files changed

+20
-27
lines changed

5 files changed

+20
-27
lines changed

pandas/core/indexing.py

+5-11
Original file line numberDiff line numberDiff line change
@@ -303,9 +303,7 @@ def _has_valid_positional_setitem_indexer(self, indexer) -> bool:
303303
f"{self.name} cannot enlarge its target object"
304304
)
305305
elif isinstance(i, dict):
306-
raise IndexError(
307-
f"{self.name} cannot enlarge its target object"
308-
)
306+
raise IndexError(f"{self.name} cannot enlarge its target object")
309307

310308
return True
311309

@@ -1167,7 +1165,7 @@ def _validate_read_indexer(
11671165
if missing == len(indexer):
11681166
raise KeyError(
11691167
f"None of [{key}] are in the [{self.obj._get_axis_name(axis)}]"
1170-
)
1168+
)
11711169

11721170
# We (temporarily) allow for some missing keys with .loc, except in
11731171
# some cases (e.g. setting) in which "raise_missing" will be False
@@ -1902,17 +1900,14 @@ def _validate_key(self, key, axis: int):
19021900

19031901
# check that the key has a numeric dtype
19041902
if not is_numeric_dtype(arr.dtype):
1905-
raise IndexError(
1906-
f".iloc requires numeric indexers, got {arr}"
1907-
)
1903+
raise IndexError(f".iloc requires numeric indexers, got {arr}")
19081904

19091905
# check that the key does not exceed the maximum size of the index
19101906
if len(arr) and (arr.max() >= len_axis or arr.min() < -len_axis):
19111907
raise IndexError("positional indexers are out-of-bounds")
19121908
else:
19131909
raise ValueError(
1914-
"Can only index by location with "
1915-
f"a [{self._valid_types}]"
1910+
"Can only index by location with " f"a [{self._valid_types}]"
19161911
)
19171912

19181913
def _has_valid_setitem_indexer(self, indexer):
@@ -2061,8 +2056,7 @@ def _convert_to_indexer(self, obj, axis: int, raise_missing: bool = False):
20612056
return obj
20622057
except ValueError:
20632058
raise ValueError(
2064-
"Can only index by location with "
2065-
f"a [{self._valid_types}]"
2059+
"Can only index by location with " f"a [{self._valid_types}]"
20662060
)
20672061

20682062

pandas/core/internals/blocks.py

+11-10
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,10 @@ def _check_ndim(self, values, ndim):
144144
ndim = values.ndim
145145

146146
if self._validate_ndim and values.ndim != ndim:
147-
raise ValueError("Wrong number of dimensions. "
148-
f"values.ndim != ndim [{values.ndim} != {ndim}]")
147+
raise ValueError(
148+
"Wrong number of dimensions. "
149+
f"values.ndim != ndim [{values.ndim} != {ndim}]"
150+
)
149151
return ndim
150152

151153
@property
@@ -268,8 +270,10 @@ def __repr__(self) -> str:
268270
else:
269271

270272
shape = " x ".join(pprint_thing(s) for s in self.shape)
271-
result = f"{name}: {pprint_thing(self.mgr_locs.indexer)}, " \
272-
f"{shape}, dtype: {self.dtype}"
273+
result = (
274+
f"{name}: {pprint_thing(self.mgr_locs.indexer)}, "
275+
f"{shape}, dtype: {self.dtype}"
276+
)
273277

274278
return result
275279

@@ -1032,8 +1036,7 @@ def coerce_to_target_dtype(self, other):
10321036
return self.astype(object)
10331037

10341038
raise AssertionError(
1035-
"possible recursion in "
1036-
f"coerce_to_target_dtype: {self} {other}"
1039+
"possible recursion in " f"coerce_to_target_dtype: {self} {other}"
10371040
)
10381041

10391042
elif self.is_timedelta or is_timedelta64_dtype(dtype):
@@ -1043,8 +1046,7 @@ def coerce_to_target_dtype(self, other):
10431046
return self.astype(object)
10441047

10451048
raise AssertionError(
1046-
"possible recursion in "
1047-
f"coerce_to_target_dtype: {self} {other}"
1049+
"possible recursion in " f"coerce_to_target_dtype: {self} {other}"
10481050
)
10491051

10501052
try:
@@ -1189,8 +1191,7 @@ def _interpolate(
11891191
if method in ("krogh", "piecewise_polynomial", "pchip"):
11901192
if not index.is_monotonic:
11911193
raise ValueError(
1192-
f"{method} interpolation requires that the "
1193-
"index be monotonic."
1194+
f"{method} interpolation requires that the " "index be monotonic."
11941195
)
11951196
# process 1-d slices in the axis direction
11961197

pandas/core/internals/construction.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,7 @@ def init_ndarray(values, index, columns, dtype=None, copy=False):
167167
except Exception as orig:
168168
# e.g. ValueError when trying to cast object dtype to float64
169169
raise ValueError(
170-
f"failed to cast to '{dtype}' (Exception "
171-
f"was: {orig})"
170+
f"failed to cast to '{dtype}' (Exception " f"was: {orig})"
172171
) from orig
173172

174173
index, columns = _get_axes(*values.shape, index=index, columns=columns)

pandas/core/internals/managers.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -1661,9 +1661,7 @@ def construction_error(tot_items, block_shape, axes, e=None):
16611661
raise e
16621662
if block_shape[0] == 0:
16631663
raise ValueError("Empty data passed with indices specified.")
1664-
raise ValueError(
1665-
f"Shape of passed values is {passed}, indices imply {implied}"
1666-
)
1664+
raise ValueError(f"Shape of passed values is {passed}, indices imply {implied}")
16671665

16681666

16691667
# -----------------------------------------------------------------------

pandas/core/resample.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1187,7 +1187,8 @@ def _downsample(self, how, **kwargs):
11871187

11881188
raise IncompatibleFrequency(
11891189
f"Frequency {ax.freq} cannot be resampled to {self.freq}, "
1190-
f"as they are not sub or super periods")
1190+
f"as they are not sub or super periods"
1191+
)
11911192

11921193
def _upsample(self, method, limit=None, fill_value=None):
11931194
"""

0 commit comments

Comments
 (0)