Skip to content

CLN: Replace fstring in tests/groupby/*.py files #30700

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

Merged
merged 2 commits into from
Jan 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pandas/tests/groupby/aggregate/test_other.py
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,7 @@ def test_agg_timezone_round_trip():
assert result3 == ts

dates = [
pd.Timestamp("2016-01-0{i:d} 12:00:00".format(i=i), tz="US/Pacific")
for i in range(1, 5)
pd.Timestamp(f"2016-01-0{i:d} 12:00:00", tz="US/Pacific") for i in range(1, 5)
]
df = pd.DataFrame({"A": ["a", "b"] * 2, "B": dates})
grouped = df.groupby("A")
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_apply.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def desc3(group):
result = group.describe()

# names are different
result.index.name = "stat_{:d}".format(len(group))
result.index.name = f"stat_{len(group):d}"

result = result[: len(group)]
# weirdo
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_bin_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def _check(dtype):
counts = np.zeros(len(out), dtype=np.int64)
labels = ensure_int64(np.repeat(np.arange(3), np.diff(np.r_[0, bins])))

func = getattr(groupby, "group_ohlc_{dtype}".format(dtype=dtype))
func = getattr(groupby, f"group_ohlc_{dtype}")
func(out, counts, obj[:, None], labels)

def _ohlc(group):
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/groupby/test_categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,10 +497,10 @@ def test_dataframe_categorical_ordered_observed_sort(ordered, observed, sort):
aggr[aggr.isna()] = "missing"
if not all(label == aggr):
msg = (
"Labels and aggregation results not consistently sorted\n"
+ "for (ordered={}, observed={}, sort={})\n"
+ "Result:\n{}"
).format(ordered, observed, sort, result)
f"Labels and aggregation results not consistently sorted\n"
+ "for (ordered={ordered}, observed={observed}, sort={sort})\n"
+ "Result:\n{result}"
)
assert False, msg


Expand Down Expand Up @@ -805,7 +805,7 @@ def test_sort():
# self.cat.groupby(['value_group'])['value_group'].count().plot(kind='bar')

df = DataFrame({"value": np.random.randint(0, 10000, 100)})
labels = ["{0} - {1}".format(i, i + 499) for i in range(0, 10000, 500)]
labels = [f"{i} - {i+499}" for i in range(0, 10000, 500)]
cat_labels = Categorical(labels, labels)

df = df.sort_values(by=["value"], ascending=True)
Expand Down
7 changes: 2 additions & 5 deletions pandas/tests/groupby/test_counting.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,8 @@ def test_ngroup_respects_groupby_order(self):
@pytest.mark.parametrize(
"datetimelike",
[
[
Timestamp("2016-05-{i:02d} 20:09:25+00:00".format(i=i))
for i in range(1, 4)
],
[Timestamp("2016-05-{i:02d} 20:09:25".format(i=i)) for i in range(1, 4)],
[Timestamp(f"2016-05-{i:02d} 20:09:25+00:00") for i in range(1, 4)],
[Timestamp(f"2016-05-{i:02d} 20:09:25") for i in range(1, 4)],
[Timedelta(x, unit="h") for x in range(1, 4)],
[Period(freq="2W", year=2017, month=x) for x in range(1, 4)],
],
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/groupby/test_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,7 @@ def test_builtins_apply(keys, f):
result = df.groupby(keys).apply(f)
ngroups = len(df.drop_duplicates(subset=keys))

assert_msg = "invalid frame shape: {} (expected ({}, 3))".format(
result.shape, ngroups
)
assert_msg = f"invalid frame shape: {result.shape} (expected ({ngroups}, 3))"
assert result.shape == (ngroups, 3), assert_msg

tm.assert_frame_equal(
Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_groupby.py
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ def test_mutate_groups():
+ ["c"] * 2
+ ["d"] * 2
+ ["e"] * 2,
"cat3": ["g{}".format(x) for x in range(1, 15)],
"cat3": [f"g{x}" for x in range(1, 15)],
"val": np.random.randint(100, size=14),
}
)
Expand Down
4 changes: 1 addition & 3 deletions pandas/tests/groupby/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -962,9 +962,7 @@ def demean_rename(x):
if isinstance(x, pd.Series):
return result

result = result.rename(
columns={c: "{}_demeaned".format(c) for c in result.columns}
)
result = result.rename(columns={c: "{c}_demeaned" for c in result.columns})

return result

Expand Down
2 changes: 1 addition & 1 deletion pandas/tests/groupby/test_value_counts.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def seed_df(seed_nans, n, m):
keys = "1st", "2nd", ["1st", "2nd"]
for k, b in product(keys, bins):
binned.append((df, k, b, n, m))
ids.append("{}-{}-{}".format(k, n, m))
ids.append(f"{k}-{n}-{m}")


@pytest.mark.slow
Expand Down
10 changes: 5 additions & 5 deletions pandas/tests/groupby/test_whitelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ def test_all_methods_categorized(mframe):

# new public method?
if new_names:
msg = """
msg = f"""
There are uncatgeorized methods defined on the Grouper class:
{names}.

Expand All @@ -418,19 +418,19 @@ def test_all_methods_categorized(mframe):
see the comments in pandas/core/groupby/base.py for guidance on
how to fix this test.
"""
raise AssertionError(msg.format(names=names))
raise AssertionError(msg)

# removed a public method?
all_categorized = reduction_kernels | transformation_kernels | groupby_other_methods
print(names)
print(all_categorized)
if not (names == all_categorized):
msg = """
msg = f"""
Some methods which are supposed to be on the Grouper class
are missing:
{names}.
{all_categorized - names}.

They're still defined in one of the lists that live in pandas/core/groupby/base.py.
If you removed a method, you should update them
"""
raise AssertionError(msg.format(names=all_categorized - names))
raise AssertionError(msg)