Skip to content

Commit 56f2933

Browse files
committed
CLN: replace variations of "..." + str(...) with f-strings
This was done by hand.
1 parent 3f71b1d commit 56f2933

File tree

15 files changed

+63
-124
lines changed

15 files changed

+63
-124
lines changed

pandas/_testing/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -569,7 +569,7 @@ def makeCustomIndex(
569569

570570
if names is True:
571571
# build default names
572-
names = [prefix + str(i) for i in range(nlevels)]
572+
names = [f"{prefix}{i}" for i in range(nlevels)]
573573
if names is False:
574574
# pass None to index constructor for no name
575575
names = None

pandas/core/dtypes/dtypes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1137,7 +1137,7 @@ def __new__(cls, subtype=None, closed: str_type | None = None):
11371137
)
11381138
raise TypeError(msg)
11391139

1140-
key = str(subtype) + str(closed)
1140+
key = f"{subtype}{closed}"
11411141
try:
11421142
return cls._cache_dtypes[key]
11431143
except KeyError:

pandas/core/interchange/buffer.py

+6-11
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,9 @@ def __dlpack_device__(self) -> tuple[DlpackDeviceType, int | None]:
6464
return (DlpackDeviceType.CPU, None)
6565

6666
def __repr__(self) -> str:
67-
return (
68-
"PandasBuffer("
69-
+ str(
70-
{
71-
"bufsize": self.bufsize,
72-
"ptr": self.ptr,
73-
"device": self.__dlpack_device__()[0].name,
74-
}
75-
)
76-
+ ")"
77-
)
67+
spec = {
68+
"bufsize": self.bufsize,
69+
"ptr": self.ptr,
70+
"device": self.__dlpack_device__()[0].name,
71+
}
72+
return f"PandasBuffer({spec})"

pandas/core/ops/docstrings.py

+14-56
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,7 @@ def make_flex_doc(op_name: str, typ: str) -> str:
9999
f 1.0
100100
dtype: float64"""
101101

102-
_add_example_SERIES = (
103-
_common_examples_algebra_SERIES
104-
+ """
102+
_add_example_SERIES = f"""{_common_examples_algebra_SERIES}
105103
>>> a.add(b, fill_value=0)
106104
a 2.0
107105
b 1.0
@@ -110,11 +108,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
110108
e NaN
111109
dtype: float64
112110
"""
113-
)
114111

115-
_sub_example_SERIES = (
116-
_common_examples_algebra_SERIES
117-
+ """
112+
_sub_example_SERIES = f"""{_common_examples_algebra_SERIES}
118113
>>> a.subtract(b, fill_value=0)
119114
a 0.0
120115
b 1.0
@@ -123,11 +118,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
123118
e NaN
124119
dtype: float64
125120
"""
126-
)
127121

128-
_mul_example_SERIES = (
129-
_common_examples_algebra_SERIES
130-
+ """
122+
_mul_example_SERIES = f"""{_common_examples_algebra_SERIES}
131123
>>> a.multiply(b, fill_value=0)
132124
a 1.0
133125
b 0.0
@@ -136,11 +128,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
136128
e NaN
137129
dtype: float64
138130
"""
139-
)
140131

141-
_div_example_SERIES = (
142-
_common_examples_algebra_SERIES
143-
+ """
132+
_div_example_SERIES = f"""{_common_examples_algebra_SERIES}
144133
>>> a.divide(b, fill_value=0)
145134
a 1.0
146135
b inf
@@ -149,11 +138,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
149138
e NaN
150139
dtype: float64
151140
"""
152-
)
153141

154-
_floordiv_example_SERIES = (
155-
_common_examples_algebra_SERIES
156-
+ """
142+
_floordiv_example_SERIES = f"""{_common_examples_algebra_SERIES}
157143
>>> a.floordiv(b, fill_value=0)
158144
a 1.0
159145
b NaN
@@ -162,11 +148,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
162148
e NaN
163149
dtype: float64
164150
"""
165-
)
166151

167-
_divmod_example_SERIES = (
168-
_common_examples_algebra_SERIES
169-
+ """
152+
_divmod_example_SERIES = f"""{_common_examples_algebra_SERIES}
170153
>>> a.divmod(b, fill_value=0)
171154
(a 1.0
172155
b NaN
@@ -181,11 +164,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
181164
e NaN
182165
dtype: float64)
183166
"""
184-
)
185167

186-
_mod_example_SERIES = (
187-
_common_examples_algebra_SERIES
188-
+ """
168+
_mod_example_SERIES = f"""{_common_examples_algebra_SERIES}
189169
>>> a.mod(b, fill_value=0)
190170
a 0.0
191171
b NaN
@@ -194,10 +174,7 @@ def make_flex_doc(op_name: str, typ: str) -> str:
194174
e NaN
195175
dtype: float64
196176
"""
197-
)
198-
_pow_example_SERIES = (
199-
_common_examples_algebra_SERIES
200-
+ """
177+
_pow_example_SERIES = f"""{_common_examples_algebra_SERIES}
201178
>>> a.pow(b, fill_value=0)
202179
a 1.0
203180
b 1.0
@@ -206,11 +183,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
206183
e NaN
207184
dtype: float64
208185
"""
209-
)
210186

211-
_ne_example_SERIES = (
212-
_common_examples_algebra_SERIES
213-
+ """
187+
_ne_example_SERIES = f"""{_common_examples_algebra_SERIES}
214188
>>> a.ne(b, fill_value=0)
215189
a False
216190
b True
@@ -219,11 +193,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
219193
e True
220194
dtype: bool
221195
"""
222-
)
223196

224-
_eq_example_SERIES = (
225-
_common_examples_algebra_SERIES
226-
+ """
197+
_eq_example_SERIES = f"""{_common_examples_algebra_SERIES}
227198
>>> a.eq(b, fill_value=0)
228199
a True
229200
b False
@@ -232,11 +203,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
232203
e False
233204
dtype: bool
234205
"""
235-
)
236206

237-
_lt_example_SERIES = (
238-
_common_examples_comparison_SERIES
239-
+ """
207+
_lt_example_SERIES = f"""{_common_examples_comparison_SERIES}
240208
>>> a.lt(b, fill_value=0)
241209
a False
242210
b False
@@ -246,11 +214,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
246214
f True
247215
dtype: bool
248216
"""
249-
)
250217

251-
_le_example_SERIES = (
252-
_common_examples_comparison_SERIES
253-
+ """
218+
_le_example_SERIES = f"""{_common_examples_comparison_SERIES}
254219
>>> a.le(b, fill_value=0)
255220
a False
256221
b True
@@ -260,11 +225,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
260225
f True
261226
dtype: bool
262227
"""
263-
)
264228

265-
_gt_example_SERIES = (
266-
_common_examples_comparison_SERIES
267-
+ """
229+
_gt_example_SERIES = f"""{_common_examples_comparison_SERIES}
268230
>>> a.gt(b, fill_value=0)
269231
a True
270232
b False
@@ -274,11 +236,8 @@ def make_flex_doc(op_name: str, typ: str) -> str:
274236
f False
275237
dtype: bool
276238
"""
277-
)
278239

279-
_ge_example_SERIES = (
280-
_common_examples_comparison_SERIES
281-
+ """
240+
_ge_example_SERIES = f"""{_common_examples_comparison_SERIES}
282241
>>> a.ge(b, fill_value=0)
283242
a True
284243
b True
@@ -288,7 +247,6 @@ def make_flex_doc(op_name: str, typ: str) -> str:
288247
f False
289248
dtype: bool
290249
"""
291-
)
292250

293251
_returns_series = """Series\n The result of the operation."""
294252

pandas/core/window/doc.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
def create_section_header(header: str) -> str:
1212
"""Create numpydoc section header"""
13-
return "\n".join((header, "-" * len(header))) + "\n"
13+
return f"{header}\n{'-' * len(header)}\n"
1414

1515

1616
template_header = "\nCalculate the {window_method} {aggregation_description}.\n\n"

pandas/io/formats/style.py

+4-7
Original file line numberDiff line numberDiff line change
@@ -2422,9 +2422,8 @@ def set_sticky(
24222422
}
24232423
]
24242424
if not self.index.names[0] is None:
2425-
styles[0]["props"] = (
2426-
f"{props}top:0px; z-index:2; height:{pixel_size}px;"
2427-
)
2425+
style = f"{props}top:0px; z-index:2; height:{pixel_size}px;"
2426+
styles[0]["props"] = style
24282427
styles.append(
24292428
{
24302429
"selector": "thead tr:nth-child(2) th",
@@ -2627,7 +2626,7 @@ def set_table_styles(
26272626

26282627
table_styles = [
26292628
{
2630-
"selector": str(s["selector"]) + idf + str(idx),
2629+
"selector": f"{s['selector']}{idf}{idx}",
26312630
"props": maybe_convert_css_to_tuples(s["props"]),
26322631
}
26332632
for key, styles in table_styles.items()
@@ -4188,9 +4187,7 @@ def css_calc(x, left: float, right: float, align: str, color: str | list | tuple
41884187

41894188
ret = css_bar(start * width, end * width, color)
41904189
if height < 1 and "background: linear-gradient(" in ret:
4191-
return (
4192-
f"{ret} no-repeat center; background-size: 100% {height * 100:.1f}%;"
4193-
)
4190+
return f"{ret} no-repeat center; background-size: 100% {height * 100:.1f}%;"
41944191
else:
41954192
return ret
41964193

pandas/io/sql.py

+8-16
Original file line numberDiff line numberDiff line change
@@ -1350,7 +1350,7 @@ def get_engine(engine: str) -> BaseEngine:
13501350
try:
13511351
return engine_class()
13521352
except ImportError as err:
1353-
error_msgs += "\n - " + str(err)
1353+
error_msgs += f"\n - {err}"
13541354

13551355
raise ImportError(
13561356
"Unable to find a usable engine; "
@@ -1911,7 +1911,7 @@ def _create_table_setup(self):
19111911
escape = _get_valid_sqlite_name
19121912

19131913
create_tbl_stmts = [
1914-
escape(cname) + " " + ctype for cname, ctype, _ in column_names_and_types
1914+
f"{escape(cname)} {ctype}" for cname, ctype, _ in column_names_and_types
19151915
]
19161916

19171917
if self.keys is not None and len(self.keys):
@@ -1924,30 +1924,22 @@ def _create_table_setup(self):
19241924
f"CONSTRAINT {self.name}_pk PRIMARY KEY ({cnames_br})"
19251925
)
19261926
if self.schema:
1927-
schema_name = self.schema + "."
1927+
schema_name = f"{self.schema}."
19281928
else:
19291929
schema_name = ""
1930+
create_tbl_stmts_str = ",\n ".join(create_tbl_stmts)
19301931
create_stmts = [
1931-
"CREATE TABLE "
1932-
+ schema_name
1933-
+ escape(self.name)
1934-
+ " (\n"
1935-
+ ",\n ".join(create_tbl_stmts)
1936-
+ "\n)"
1932+
f"CREATE TABLE {schema_name}{escape(self.name)} "
1933+
f"(\n{create_tbl_stmts_str}\n)"
19371934
]
19381935

19391936
ix_cols = [cname for cname, _, is_index in column_names_and_types if is_index]
19401937
if len(ix_cols):
19411938
cnames = "_".join(ix_cols)
19421939
cnames_br = ",".join([escape(c) for c in ix_cols])
1940+
ix_name = f"ix_{self.name}_{cnames}"
19431941
create_stmts.append(
1944-
"CREATE INDEX "
1945-
+ escape("ix_" + self.name + "_" + cnames)
1946-
+ "ON "
1947-
+ escape(self.name)
1948-
+ " ("
1949-
+ cnames_br
1950-
+ ")"
1942+
f"CREATE INDEX {escape(ix_name)} ON {escape(self.name)} ({cnames_br})"
19511943
)
19521944

19531945
return create_stmts

0 commit comments

Comments
 (0)