Skip to content

Commit 83191ed

Browse files
committed
CLN: Update melt.py with fstrings (pandas-dev#29527)
All changes made for melt.py + black pandas formatting.
1 parent dc25705 commit 83191ed

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

pandas/core/reshape/melt.py

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ def melt(
4848
missing = Index(np.ravel(id_vars)).difference(cols)
4949
if not missing.empty:
5050
raise KeyError(
51-
"The following 'id_vars' are not present"
52-
" in the DataFrame: {missing}"
53-
"".format(missing=list(missing))
51+
f"The following 'id_vars' are not present"
52+
f" in the DataFrame: {list(missing)}"
5453
)
5554
else:
5655
id_vars = []
@@ -70,9 +69,8 @@ def melt(
7069
missing = Index(np.ravel(value_vars)).difference(cols)
7170
if not missing.empty:
7271
raise KeyError(
73-
"The following 'value_vars' are not present in"
74-
" the DataFrame: {missing}"
75-
"".format(missing=list(missing))
72+
f"The following 'value_vars' are not present in"
73+
f" the DataFrame: {list(missing)}"
7674
)
7775
frame = frame.loc[:, id_vars + value_vars]
7876
else:
@@ -87,9 +85,7 @@ def melt(
8785
if len(frame.columns.names) == len(set(frame.columns.names)):
8886
var_name = frame.columns.names
8987
else:
90-
var_name = [
91-
"variable_{i}".format(i=i) for i in range(len(frame.columns.names))
92-
]
88+
var_name = [f"variable_{i}" for i in range(len(frame.columns.names))]
9389
else:
9490
var_name = [
9591
frame.columns.name if frame.columns.name is not None else "variable"
@@ -413,9 +409,7 @@ def wide_to_long(df, stubnames, i, j, sep: str = "", suffix: str = r"\d+"):
413409
"""
414410

415411
def get_var_names(df, stub, sep, suffix):
416-
regex = r"^{stub}{sep}{suffix}$".format(
417-
stub=re.escape(stub), sep=re.escape(sep), suffix=suffix
418-
)
412+
regex = fr"^{re.escape(stub)}{re.escape(sep)}{suffix}$"
419413
pattern = re.compile(regex)
420414
return [col for col in df.columns if pattern.match(col)]
421415

0 commit comments

Comments
 (0)