Skip to content

Commit d26d626

Browse files
author
MomIsBestFriend
committed
Merge remote-tracking branch 'upstream/master' into STY-repr-batch-3
2 parents 15d0334 + 21c93fc commit d26d626

File tree

12 files changed

+27
-40
lines changed

12 files changed

+27
-40
lines changed

pandas/errors/__init__.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,7 @@ class AbstractMethodError(NotImplementedError):
167167
def __init__(self, class_instance, methodtype="method"):
168168
types = {"method", "classmethod", "staticmethod", "property"}
169169
if methodtype not in types:
170-
msg = "methodtype must be one of {}, got {} instead.".format(
171-
methodtype, types
172-
)
170+
msg = f"methodtype must be one of {methodtype}, got {types} instead."
173171
raise ValueError(msg)
174172
self.methodtype = methodtype
175173
self.class_instance = class_instance
@@ -179,5 +177,5 @@ def __str__(self) -> str:
179177
name = self.class_instance.__name__
180178
else:
181179
name = type(self.class_instance).__name__
182-
msg = "This {methodtype} must be defined in the concrete class {name}"
180+
msg = f"This {self.methodtype} must be defined in the concrete class {name}"
183181
return msg.format(methodtype=self.methodtype, name=name)

pandas/tests/arrays/interval/test_ops.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,6 @@ def test_overlaps_na(self, constructor, start_shift):
8383
)
8484
def test_overlaps_invalid_type(self, constructor, other):
8585
interval_container = constructor.from_breaks(range(5))
86-
msg = "`other` must be Interval-like, got {other}".format(
87-
other=type(other).__name__
88-
)
86+
msg = f"`other` must be Interval-like, got {type(other).__name__}"
8987
with pytest.raises(TypeError, match=msg):
9088
interval_container.overlaps(other)

pandas/tests/arrays/sparse/test_array.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ def test_cumsum(self, data, expected, numpy):
10071007
np.cumsum(SparseArray(data), out=out)
10081008
else:
10091009
axis = 1 # SparseArray currently 1-D, so only axis = 0 is valid.
1010-
msg = "axis\\(={axis}\\) out of bounds".format(axis=axis)
1010+
msg = re.escape(f"axis(={axis}) out of bounds")
10111011
with pytest.raises(ValueError, match=msg):
10121012
SparseArray(data).cumsum(axis=axis)
10131013

pandas/tests/arrays/sparse/test_libsparse.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,6 @@ def _check_case(xloc, xlen, yloc, ylen, eloc, elen):
596596

597597
@pytest.mark.parametrize("opname", ["add", "sub", "mul", "truediv", "floordiv"])
598598
def test_op(self, opname):
599-
sparse_op = getattr(splib, "sparse_{opname}_float64".format(opname=opname))
599+
sparse_op = getattr(splib, f"sparse_{opname}_float64")
600600
python_op = getattr(operator, opname)
601601
self._op_tests(sparse_op, python_op)

pandas/tests/extension/arrow/arrays.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def construct_from_string(cls, string):
3333
if string == cls.name:
3434
return cls()
3535
else:
36-
raise TypeError("Cannot construct a '{}' from '{}'".format(cls, string))
36+
raise TypeError(f"Cannot construct a '{cls}' from '{string}'")
3737

3838
@classmethod
3939
def construct_array_type(cls):
@@ -56,7 +56,7 @@ def construct_from_string(cls, string):
5656
if string == cls.name:
5757
return cls()
5858
else:
59-
raise TypeError("Cannot construct a '{}' from '{}'".format(cls, string))
59+
raise TypeError(f"Cannot construct a '{cls}' from '{string}'")
6060

6161
@classmethod
6262
def construct_array_type(cls):
@@ -79,7 +79,7 @@ def _from_sequence(cls, scalars, dtype=None, copy=False):
7979
return cls.from_scalars(scalars)
8080

8181
def __repr__(self):
82-
return "{cls}({data})".format(cls=type(self).__name__, data=repr(self._data))
82+
return f"{type(self).__name__}({repr(self._data)})"
8383

8484
def __getitem__(self, item):
8585
if pd.api.types.is_scalar(item):

pandas/tests/extension/base/printing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_array_repr(self, data, size):
1919

2020
result = repr(data)
2121
assert type(data).__name__ in result
22-
assert "Length: {}".format(len(data)) in result
22+
assert f"Length: {len(data)}" in result
2323
assert str(data.dtype) in result
2424
if size == "big":
2525
assert "..." in result

pandas/tests/extension/decimal/array.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def __init__(self, context=None):
2323
self.context = context or decimal.getcontext()
2424

2525
def __repr__(self) -> str:
26-
return "DecimalDtype(context={})".format(self.context)
26+
return f"DecimalDtype(context={self.context})"
2727

2828
@classmethod
2929
def construct_array_type(cls):
@@ -40,7 +40,7 @@ def construct_from_string(cls, string):
4040
if string == cls.name:
4141
return cls()
4242
else:
43-
raise TypeError("Cannot construct a '{}' from '{}'".format(cls, string))
43+
raise TypeError(f"Cannot construct a '{cls}' from '{string}'")
4444

4545
@property
4646
def _is_numeric(self):
@@ -178,9 +178,7 @@ def _reduce(self, name, skipna=True, **kwargs):
178178
try:
179179
op = getattr(self.data, name)
180180
except AttributeError:
181-
raise NotImplementedError(
182-
"decimal does not support the {} operation".format(name)
183-
)
181+
raise NotImplementedError(f"decimal does not support the {name} operation")
184182
return op(axis=0)
185183

186184

pandas/tests/resample/test_datetime_index.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,7 @@ def test_resample_basic_grouper(series):
146146
def test_resample_string_kwargs(series, keyword, value):
147147
# see gh-19303
148148
# Check that wrong keyword argument strings raise an error
149-
msg = "Unsupported value {value} for `{keyword}`".format(
150-
value=value, keyword=keyword
151-
)
149+
msg = f"Unsupported value {value} for `{keyword}`"
152150
with pytest.raises(ValueError, match=msg):
153151
series.resample("5min", **({keyword: value}))
154152

pandas/tests/resample/test_time_grouper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def test_fails_on_no_datetime_index(name, func):
8989

9090
msg = (
9191
"Only valid with DatetimeIndex, TimedeltaIndex "
92-
"or PeriodIndex, but got an instance of '{}'".format(name)
92+
f"or PeriodIndex, but got an instance of '{name}'"
9393
)
9494
with pytest.raises(TypeError, match=msg):
9595
df.groupby(Grouper(freq="D"))

pandas/tests/scalar/test_nat.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ def test_round_nat(klass, method, freq):
141141
)
142142
def test_nat_methods_raise(method):
143143
# see gh-9513, gh-17329
144-
msg = "NaTType does not support {method}".format(method=method)
144+
msg = f"NaTType does not support {method}"
145145

146146
with pytest.raises(ValueError, match=msg):
147147
getattr(NaT, method)()

0 commit comments

Comments
 (0)