Skip to content

CLN: cleanup, deduplicate plotting/test_frame #37714

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 3 commits into from
Nov 9, 2020
Merged
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
46 changes: 21 additions & 25 deletions pandas/tests/plotting/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -2047,7 +2047,6 @@ def test_no_legend(self):
df = DataFrame(np.random.rand(3, 3), columns=["a", "b", "c"])

for kind in kinds:

ax = df.plot(kind=kind, legend=False)
self._check_legend_labels(ax, visible=False)

Expand All @@ -2067,8 +2066,8 @@ def test_style_by_column(self):
fig.clf()
fig.add_subplot(111)
ax = df.plot(style=markers)
for i, l in enumerate(ax.get_lines()[: len(markers)]):
assert l.get_marker() == markers[i]
for idx, line in enumerate(ax.get_lines()[: len(markers)]):
assert line.get_marker() == markers[idx]

@pytest.mark.slow
def test_line_label_none(self):
Expand Down Expand Up @@ -2141,8 +2140,7 @@ def test_line_colors_and_styles_subplots(self):

axes = df.plot(subplots=True)
for ax, c in zip(axes, list(default_colors)):
c = [c]
self._check_colors(ax.get_lines(), linecolors=c)
self._check_colors(ax.get_lines(), linecolors=[c])
tm.close()

# single color char
Expand Down Expand Up @@ -2584,32 +2582,30 @@ def test_hexbin_with_c(self):
assert len(ax.collections) == 1

@pytest.mark.slow
def test_hexbin_cmap(self):
@pytest.mark.parametrize(
"kwargs, expected",
[
({}, "BuGn"), # default cmap
({"colormap": "cubehelix"}, "cubehelix"),
({"cmap": "YlGn"}, "YlGn"),
],
)
def test_hexbin_cmap(self, kwargs, expected):
df = self.hexbin_df

# Default to BuGn
ax = df.plot.hexbin(x="A", y="B")
assert ax.collections[0].cmap.name == "BuGn"

cm = "cubehelix"
ax = df.plot.hexbin(x="A", y="B", colormap=cm)
assert ax.collections[0].cmap.name == cm
ax = df.plot.hexbin(x="A", y="B", **kwargs)
assert ax.collections[0].cmap.name == expected

@pytest.mark.slow
def test_no_color_bar(self):
df = self.hexbin_df

ax = df.plot.hexbin(x="A", y="B", colorbar=None)
assert ax.collections[0].colorbar is None

@pytest.mark.slow
def test_allow_cmap(self):
def test_mixing_cmap_and_colormap_raises(self):
df = self.hexbin_df

ax = df.plot.hexbin(x="A", y="B", cmap="YlGn")
assert ax.collections[0].cmap.name == "YlGn"

with pytest.raises(TypeError):
msg = "Only specify one of `cmap` and `colormap`"
with pytest.raises(TypeError, match=msg):
df.plot.hexbin(x="A", y="B", cmap="YlGn", colormap="BuGn")

@pytest.mark.slow
Expand Down Expand Up @@ -2671,12 +2667,13 @@ def test_pie_df_nan(self):
expected[i] = ""
result = [x.get_text() for x in ax.texts]
assert result == expected

# legend labels
# NaN's not included in legend with subplots
# see https://github.com/pandas-dev/pandas/issues/8390
assert [x.get_text() for x in ax.get_legend().get_texts()] == base_expected[
:i
] + base_expected[i + 1 :]
result_labels = [x.get_text() for x in ax.get_legend().get_texts()]
expected_labels = base_expected[:i] + base_expected[i + 1 :]
assert result_labels == expected_labels

@pytest.mark.slow
def test_errorbar_plot(self):
Expand Down Expand Up @@ -2839,7 +2836,6 @@ def test_errorbar_timeseries(self, kind):
self._check_has_errorbars(axes, xerr=0, yerr=1)

def test_errorbar_asymmetrical(self):

np.random.seed(0)
err = np.random.rand(3, 2, 5)

Expand Down