Skip to content

Commit d5a9e5e

Browse files
committed
REF: extract test_errorbar_plot_different_kinds
Extract test_errorbar_plot_different_kinds from test_errorbar_plot and parametrize it.
1 parent 73bf910 commit d5a9e5e

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

pandas/tests/plotting/test_frame.py

+41-35
Original file line numberDiff line numberDiff line change
@@ -2658,8 +2658,6 @@ def test_pie_df_nan(self):
26582658

26592659
@pytest.mark.slow
26602660
def test_errorbar_plot(self):
2661-
import matplotlib.pyplot as plt
2662-
26632661
d = {"x": np.arange(12), "y": np.arange(12, 0, -1)}
26642662
df = DataFrame(d)
26652663
d_err = {"x": np.ones(12) * 0.2, "y": np.ones(12) * 0.4}
@@ -2675,39 +2673,6 @@ def test_errorbar_plot(self):
26752673
ax = _check_plot_works(df.plot, yerr=df_err, loglog=True)
26762674
self._check_has_errorbars(ax, xerr=0, yerr=2)
26772675

2678-
kinds = ["line", "bar", "barh"]
2679-
for kind in kinds:
2680-
ax = _check_plot_works(df.plot, yerr=df_err["x"], kind=kind)
2681-
self._check_has_errorbars(ax, xerr=0, yerr=2)
2682-
2683-
ax = _check_plot_works(df.plot, yerr=d_err, kind=kind)
2684-
self._check_has_errorbars(ax, xerr=0, yerr=2)
2685-
2686-
ax = _check_plot_works(df.plot, yerr=df_err, xerr=df_err, kind=kind)
2687-
self._check_has_errorbars(ax, xerr=2, yerr=2)
2688-
2689-
ax = _check_plot_works(
2690-
df.plot, yerr=df_err["x"], xerr=df_err["x"], kind=kind
2691-
)
2692-
self._check_has_errorbars(ax, xerr=2, yerr=2)
2693-
2694-
ax = _check_plot_works(df.plot, xerr=0.2, yerr=0.2, kind=kind)
2695-
self._check_has_errorbars(ax, xerr=2, yerr=2)
2696-
2697-
with tm.assert_produces_warning(UserWarning):
2698-
# _check_plot_works as this function creates
2699-
# subplots inside, which leads to warnings like this:
2700-
# UserWarning: To output multiple subplots,
2701-
# the figure containing the passed axes is being cleared
2702-
# Similar warnings were observed in GH #13188
2703-
_check_plot_works(
2704-
df.plot, yerr=df_err, xerr=df_err, subplots=True, kind=kind
2705-
)
2706-
fig = plt.gcf()
2707-
axes = fig.get_axes()
2708-
for ax in axes:
2709-
self._check_has_errorbars(ax, xerr=1, yerr=1)
2710-
27112676
ax = _check_plot_works(
27122677
(df + 1).plot, yerr=df_err, xerr=df_err, kind="bar", log=True
27132678
)
@@ -2724,8 +2689,10 @@ def test_errorbar_plot(self):
27242689
for yerr in ["yerr", "誤差"]:
27252690
s_df = df.copy()
27262691
s_df[yerr] = np.ones(12) * 0.2
2692+
27272693
ax = _check_plot_works(s_df.plot, yerr=yerr)
27282694
self._check_has_errorbars(ax, xerr=0, yerr=2)
2695+
27292696
ax = _check_plot_works(s_df.plot, y="y", x="x", yerr=yerr)
27302697
self._check_has_errorbars(ax, xerr=0, yerr=1)
27312698

@@ -2736,6 +2703,45 @@ def test_errorbar_plot(self):
27362703
with pytest.raises((ValueError, TypeError)):
27372704
df.plot(yerr=df_err)
27382705

2706+
@pytest.mark.slow
2707+
@pytest.mark.parametrize("kind", ["line", "bar", "barh"])
2708+
def test_errorbar_plot_different_kinds(self, kind):
2709+
import matplotlib.pyplot as plt
2710+
2711+
d = {"x": np.arange(12), "y": np.arange(12, 0, -1)}
2712+
df = DataFrame(d)
2713+
d_err = {"x": np.ones(12) * 0.2, "y": np.ones(12) * 0.4}
2714+
df_err = DataFrame(d_err)
2715+
2716+
ax = _check_plot_works(df.plot, yerr=df_err["x"], kind=kind)
2717+
self._check_has_errorbars(ax, xerr=0, yerr=2)
2718+
2719+
ax = _check_plot_works(df.plot, yerr=d_err, kind=kind)
2720+
self._check_has_errorbars(ax, xerr=0, yerr=2)
2721+
2722+
ax = _check_plot_works(df.plot, yerr=df_err, xerr=df_err, kind=kind)
2723+
self._check_has_errorbars(ax, xerr=2, yerr=2)
2724+
2725+
ax = _check_plot_works(df.plot, yerr=df_err["x"], xerr=df_err["x"], kind=kind)
2726+
self._check_has_errorbars(ax, xerr=2, yerr=2)
2727+
2728+
ax = _check_plot_works(df.plot, xerr=0.2, yerr=0.2, kind=kind)
2729+
self._check_has_errorbars(ax, xerr=2, yerr=2)
2730+
2731+
with tm.assert_produces_warning(UserWarning):
2732+
# _check_plot_works as this function creates
2733+
# subplots inside, which leads to warnings like this:
2734+
# UserWarning: To output multiple subplots,
2735+
# the figure containing the passed axes is being cleared
2736+
# Similar warnings were observed in GH #13188
2737+
_check_plot_works(
2738+
df.plot, yerr=df_err, xerr=df_err, subplots=True, kind=kind
2739+
)
2740+
fig = plt.gcf()
2741+
axes = fig.get_axes()
2742+
for ax in axes:
2743+
self._check_has_errorbars(ax, xerr=1, yerr=1)
2744+
27392745
@pytest.mark.xfail(reason="Iterator is consumed", raises=ValueError)
27402746
@pytest.mark.slow
27412747
def test_errorbar_plot_iterator(self):

0 commit comments

Comments
 (0)