From d47822cc011f62825cb5e961afef21315a9cee4b Mon Sep 17 00:00:00 2001 From: Joseph Lamborn Date: Thu, 12 Dec 2019 18:09:07 -0500 Subject: [PATCH 1/3] CLN changed .format to f-string for test_converter.py, test_datetimelike.py, test_series.py #29547 --- pandas/tests/plotting/test_converter.py | 2 +- pandas/tests/plotting/test_datetimelike.py | 2 +- pandas/tests/plotting/test_series.py | 8 ++++---- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/pandas/tests/plotting/test_converter.py b/pandas/tests/plotting/test_converter.py index fb9ad57626600..5cea4fb5acca0 100644 --- a/pandas/tests/plotting/test_converter.py +++ b/pandas/tests/plotting/test_converter.py @@ -268,7 +268,7 @@ def _assert_less(ts1, ts2): val1 = self.dtc.convert(ts1, None, None) val2 = self.dtc.convert(ts2, None, None) if not val1 < val2: - raise AssertionError("{0} is not less than {1}.".format(val1, val2)) + raise AssertionError(f"{val1} is not less than {val2}.") # Matplotlib's time representation using floats cannot distinguish # intervals smaller than ~10 microsecond in the common range of years. diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index f5161b481ca50..8456f095e5868 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -1352,7 +1352,7 @@ def test_plot_outofbounds_datetime(self): def test_format_timedelta_ticks_narrow(self): - expected_labels = ["00:00:00.0000000{:0>2d}".format(i) for i in np.arange(10)] + expected_labels = [f"00:00:00.0000000{i:0>2d}" for i in np.arange(10)] rng = timedelta_range("0", periods=10, freq="ns") df = DataFrame(np.random.randn(len(rng), 3), rng) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 766b1f61e9c1b..2df04ebb156d1 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -330,7 +330,7 @@ def test_pie_series(self): ax = _check_plot_works( series.plot.pie, colors=color_args, autopct="%.2f", fontsize=7 ) - pcts = ["{0:.2f}".format(s * 100) for s in series.values / float(series.sum())] + pcts = [f"{s:.2f}" (s * 100) for s in series.values / float(series.sum())] expected_texts = list(chain.from_iterable(zip(series.index, pcts))) self._check_text_labels(ax.texts, expected_texts) for t in ax.texts: @@ -865,15 +865,15 @@ def test_time_series_plot_color_with_empty_kwargs(self): def test_xticklabels(self): # GH11529 - s = Series(np.arange(10), index=["P{i:02d}".format(i=i) for i in range(10)]) + s = Series(np.arange(10), index=[f"P{i:02d}" for i in range(10)]) _, ax = self.plt.subplots() ax = s.plot(xticks=[0, 3, 5, 9], ax=ax) - exp = ["P{i:02d}".format(i=i) for i in [0, 3, 5, 9]] + exp = [f"P{i:02d}" for i in [0, 3, 5, 9]] self._check_text_labels(ax.get_xticklabels(), exp) def test_xtick_barPlot(self): # GH28172 - s = pd.Series(range(10), index=["P{i:02d}".format(i=i) for i in range(10)]) + s = pd.Series(range(10), index=[f"P{i:02d}" for i in range(10)]) ax = s.plot.bar(xticks=range(0, 11, 2)) exp = np.array(list(range(0, 11, 2))) tm.assert_numpy_array_equal(exp, ax.get_xticks()) From c8929e402be3f0f3f8f066171b19724bd149840c Mon Sep 17 00:00:00 2001 From: Joseph Lamborn Date: Thu, 12 Dec 2019 18:45:16 -0500 Subject: [PATCH 2/3] ran black to reformat test_series.py --- pandas/tests/plotting/test_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 2df04ebb156d1..f6b78cba25d4a 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -330,7 +330,7 @@ def test_pie_series(self): ax = _check_plot_works( series.plot.pie, colors=color_args, autopct="%.2f", fontsize=7 ) - pcts = [f"{s:.2f}" (s * 100) for s in series.values / float(series.sum())] + pcts = [f"{s:.2f}"(s * 100) for s in series.values / float(series.sum())] expected_texts = list(chain.from_iterable(zip(series.index, pcts))) self._check_text_labels(ax.texts, expected_texts) for t in ax.texts: From c7de07cf6b4eba4539ddbf4704a600838911e922 Mon Sep 17 00:00:00 2001 From: Joseph Lamborn Date: Thu, 12 Dec 2019 19:54:33 -0500 Subject: [PATCH 3/3] Fixed str not callable error in test_series.py --- pandas/tests/plotting/test_series.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index f6b78cba25d4a..61722d726b28b 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -330,7 +330,7 @@ def test_pie_series(self): ax = _check_plot_works( series.plot.pie, colors=color_args, autopct="%.2f", fontsize=7 ) - pcts = [f"{s:.2f}"(s * 100) for s in series.values / float(series.sum())] + pcts = [f"{s*100:.2f}" for s in series.values / float(series.sum())] expected_texts = list(chain.from_iterable(zip(series.index, pcts))) self._check_text_labels(ax.texts, expected_texts) for t in ax.texts: