Skip to content

Commit 0d46877

Browse files
mroeschkeim-vinicius
authored and
im-vinicius
committed
TST: Clean tests/plotting/test_frame.py misc (pandas-dev#53914)
1 parent 223ed54 commit 0d46877

File tree

2 files changed

+200
-149
lines changed

2 files changed

+200
-149
lines changed

pandas/tests/plotting/frame/test_frame_legend.py

+31-17
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class TestFrameLegend:
2626
)
2727
def test_mixed_yerr(self):
2828
# https://github.com/pandas-dev/pandas/issues/39522
29-
import matplotlib as mpl
3029
from matplotlib.collections import LineCollection
3130
from matplotlib.lines import Line2D
3231

@@ -46,8 +45,6 @@ def test_mixed_yerr(self):
4645

4746
def test_legend_false(self):
4847
# https://github.com/pandas-dev/pandas/issues/40044
49-
import matplotlib as mpl
50-
5148
df = DataFrame({"a": [1, 1], "b": [2, 3]})
5249
df2 = DataFrame({"d": [2.5, 2.5]})
5350

@@ -63,27 +60,31 @@ def test_legend_false(self):
6360
assert result == expected
6461

6562
@td.skip_if_no_scipy
66-
def test_df_legend_labels(self):
67-
kinds = ["line", "bar", "barh", "kde", "area", "hist"]
63+
@pytest.mark.parametrize("kind", ["line", "bar", "barh", "kde", "area", "hist"])
64+
def test_df_legend_labels(self, kind):
6865
df = DataFrame(np.random.rand(3, 3), columns=["a", "b", "c"])
6966
df2 = DataFrame(np.random.rand(3, 3), columns=["d", "e", "f"])
7067
df3 = DataFrame(np.random.rand(3, 3), columns=["g", "h", "i"])
7168
df4 = DataFrame(np.random.rand(3, 3), columns=["j", "k", "l"])
7269

73-
for kind in kinds:
74-
ax = df.plot(kind=kind, legend=True)
75-
_check_legend_labels(ax, labels=df.columns)
70+
ax = df.plot(kind=kind, legend=True)
71+
_check_legend_labels(ax, labels=df.columns)
7672

77-
ax = df2.plot(kind=kind, legend=False, ax=ax)
78-
_check_legend_labels(ax, labels=df.columns)
73+
ax = df2.plot(kind=kind, legend=False, ax=ax)
74+
_check_legend_labels(ax, labels=df.columns)
7975

80-
ax = df3.plot(kind=kind, legend=True, ax=ax)
81-
_check_legend_labels(ax, labels=df.columns.union(df3.columns))
76+
ax = df3.plot(kind=kind, legend=True, ax=ax)
77+
_check_legend_labels(ax, labels=df.columns.union(df3.columns))
8278

83-
ax = df4.plot(kind=kind, legend="reverse", ax=ax)
84-
expected = list(df.columns.union(df3.columns)) + list(reversed(df4.columns))
85-
_check_legend_labels(ax, labels=expected)
79+
ax = df4.plot(kind=kind, legend="reverse", ax=ax)
80+
expected = list(df.columns.union(df3.columns)) + list(reversed(df4.columns))
81+
_check_legend_labels(ax, labels=expected)
8682

83+
@td.skip_if_no_scipy
84+
def test_df_legend_labels_secondary_y(self):
85+
df = DataFrame(np.random.rand(3, 3), columns=["a", "b", "c"])
86+
df2 = DataFrame(np.random.rand(3, 3), columns=["d", "e", "f"])
87+
df3 = DataFrame(np.random.rand(3, 3), columns=["g", "h", "i"])
8788
# Secondary Y
8889
ax = df.plot(legend=True, secondary_y="b")
8990
_check_legend_labels(ax, labels=["a", "b (right)", "c"])
@@ -92,6 +93,8 @@ def test_df_legend_labels(self):
9293
ax = df3.plot(kind="bar", legend=True, secondary_y="h", ax=ax)
9394
_check_legend_labels(ax, labels=["a", "b (right)", "c", "g", "h (right)", "i"])
9495

96+
@td.skip_if_no_scipy
97+
def test_df_legend_labels_time_series(self):
9598
# Time Series
9699
ind = date_range("1/1/2014", periods=3)
97100
df = DataFrame(np.random.randn(3, 3), columns=["a", "b", "c"], index=ind)
@@ -104,6 +107,13 @@ def test_df_legend_labels(self):
104107
ax = df3.plot(legend=True, ax=ax)
105108
_check_legend_labels(ax, labels=["a", "b (right)", "c", "g", "h", "i"])
106109

110+
@td.skip_if_no_scipy
111+
def test_df_legend_labels_time_series_scatter(self):
112+
# Time Series
113+
ind = date_range("1/1/2014", periods=3)
114+
df = DataFrame(np.random.randn(3, 3), columns=["a", "b", "c"], index=ind)
115+
df2 = DataFrame(np.random.randn(3, 3), columns=["d", "e", "f"], index=ind)
116+
df3 = DataFrame(np.random.randn(3, 3), columns=["g", "h", "i"], index=ind)
107117
# scatter
108118
ax = df.plot.scatter(x="a", y="b", label="data1")
109119
_check_legend_labels(ax, labels=["data1"])
@@ -112,6 +122,10 @@ def test_df_legend_labels(self):
112122
ax = df3.plot.scatter(x="g", y="h", label="data3", ax=ax)
113123
_check_legend_labels(ax, labels=["data1", "data3"])
114124

125+
@td.skip_if_no_scipy
126+
def test_df_legend_labels_time_series_no_mutate(self):
127+
ind = date_range("1/1/2014", periods=3)
128+
df = DataFrame(np.random.randn(3, 3), columns=["a", "b", "c"], index=ind)
115129
# ensure label args pass through and
116130
# index name does not mutate
117131
# column names don't mutate
@@ -128,7 +142,7 @@ def test_df_legend_labels(self):
128142
def test_missing_marker_multi_plots_on_same_ax(self):
129143
# GH 18222
130144
df = DataFrame(data=[[1, 1, 1, 1], [2, 2, 4, 8]], columns=["x", "r", "g", "b"])
131-
fig, ax = mpl.pyplot.subplots(nrows=1, ncols=3)
145+
_, ax = mpl.pyplot.subplots(nrows=1, ncols=3)
132146
# Left plot
133147
df.plot(x="x", y="r", linewidth=0, marker="o", color="r", ax=ax[0])
134148
df.plot(x="x", y="g", linewidth=1, marker="x", color="g", ax=ax[0])
@@ -210,7 +224,7 @@ def test_missing_markers_legend_using_style(self):
210224
}
211225
)
212226

213-
fig, ax = mpl.pyplot.subplots()
227+
_, ax = mpl.pyplot.subplots()
214228
for kind in "ABC":
215229
df.plot("X", kind, label=kind, ax=ax, style=".")
216230

0 commit comments

Comments
 (0)