Skip to content

TST: Fix some plotting xfails #55440

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

Closed
wants to merge 9 commits into from
Closed
4 changes: 3 additions & 1 deletion pandas/tests/plotting/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

from __future__ import annotations

import copy
from typing import TYPE_CHECKING

import numpy as np
Expand Down Expand Up @@ -554,7 +555,8 @@ def _gen_two_subplots(f, fig, **kwargs):
"""
if "ax" not in kwargs:
fig.add_subplot(211)
yield f(**kwargs)
# Copy iterators for 2nd call, see test_errorbar_plot_iterator
yield f(**copy.deepcopy(kwargs))

if f is pd.plotting.bootstrap_plot:
assert "ax" not in kwargs
Expand Down
8 changes: 3 additions & 5 deletions pandas/tests/plotting/frame/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ def test_plot_subplots_use_index(self):
_check_ticks_props(axes, xrot=0)
_check_axes_shape(axes, axes_num=4, layout=(4, 1))

@pytest.mark.xfail(reason="Api changed in 3.6.0")
@pytest.mark.slow
def test_plot_invalid_arg(self):
df = DataFrame({"x": [1, 2], "y": [3, 4]})
msg = "'Line2D' object has no property 'blarg'"
msg = re.escape("Line2D.set() got an unexpected keyword argument 'blarg'")
with pytest.raises(AttributeError, match=msg):
df.plot.line(blarg=True)

Expand Down Expand Up @@ -659,11 +658,11 @@ def test_area_lim(self, stacked):
lines = ax.get_lines()
assert xmin <= lines[0].get_data()[0][0]
assert xmax >= lines[0].get_data()[0][-1]
assert ymin == 0
assert ymin == 0, ymin

ax = _check_plot_works(neg_df.plot.area, stacked=stacked)
ymin, ymax = ax.get_ylim()
assert ymax == 0
assert ymax == 0, ymax

def test_area_sharey_dont_overwrite(self):
# GH37942
Expand Down Expand Up @@ -1796,7 +1795,6 @@ def test_errorbar_plot_different_yerr_xerr_subplots(self, kind):
)
_check_has_errorbars(axes, xerr=1, yerr=1)

@pytest.mark.xfail(reason="Iterator is consumed", raises=ValueError)
def test_errorbar_plot_iterator(self):
d = {"x": np.arange(12), "y": np.arange(12, 0, -1)}
df = DataFrame(d)
Expand Down
15 changes: 5 additions & 10 deletions pandas/tests/plotting/test_datetimelike.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,6 @@ def test_plot_multiple_inferred_freq(self):
ser = Series(np.random.default_rng(2).standard_normal(len(dr)), index=dr)
_check_plot_works(ser.plot)

@pytest.mark.xfail(reason="Api changed in 3.6.0")
def test_uhf(self):
import pandas.plotting._matplotlib.converter as conv

Expand All @@ -309,7 +308,7 @@ def test_uhf(self):
tlocs = axis.get_ticklocs()
tlabels = axis.get_ticklabels()
for loc, label in zip(tlocs, tlabels):
xp = conv._from_ordinal(loc).strftime("%H:%M:%S.%f")
xp = conv._from_ordinal(loc).strftime("%H:%M:%S")
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Confirmed the decimal here is not shown in the label when plotting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should it be?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great question. On matplotlib 3.5, the code rs = str(label.get_text()) returns the empty string and the subsequent assert is not ran. On 3.6, we get "21:59:51" for rs. In both cases, 21:59:51 is displayed on the resulting plot. So I believe the test was incorrect on our end.

rs = str(label.get_text())
if len(rs):
assert xp == rs
Expand Down Expand Up @@ -1428,7 +1427,6 @@ def test_secondary_legend_nonts_multi_col(self):
# TODO: color cycle problems
assert len(colors) == 4

@pytest.mark.xfail(reason="Api changed in 3.6.0")
def test_format_date_axis(self):
rng = date_range("1/1/2012", periods=12, freq="ME")
df = DataFrame(np.random.default_rng(2).standard_normal((len(rng), 3)), rng)
Expand All @@ -1437,7 +1435,7 @@ def test_format_date_axis(self):
xaxis = ax.get_xaxis()
for line in xaxis.get_ticklabels():
if len(line.get_text()) > 0:
assert line.get_rotation() == 30
assert line.get_rotation() == 0.0
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The label is not rotated visually.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same, should it be?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the previous - on 3.5 line.get_text() is returning the empty string. In both 3.5 and 3.6, line.get_rotation() reports 0.0, agreeing with the resulting plot.


def test_ax_plot(self):
x = date_range(start="2012-01-02", periods=10, freq="D")
Expand Down Expand Up @@ -1652,19 +1650,16 @@ def test_overlapping_datetime(self):
s2.plot(ax=ax)
s1.plot(ax=ax)

@pytest.mark.xfail(reason="GH9053 matplotlib does not use ax.xaxis.converter")
def test_add_matplotlib_datetime64(self):
# GH9053 - ensure that a plot with PeriodConverter still understands
# datetime64 data. This still fails because matplotlib overrides the
# ax.xaxis.converter with a DatetimeConverter
# datetime64 data.
s = Series(
np.random.default_rng(2).standard_normal(10),
index=date_range("1970-01-02", periods=10),
)
ax = s.plot()
with tm.assert_produces_warning(DeprecationWarning):
# multi-dimensional indexing
ax.plot(s.index, s.values, color="g")
# multi-dimensional indexing
ax.plot(s.index, s.values, color="g")
l1, l2 = ax.lines
tm.assert_numpy_array_equal(l1.get_xydata(), l2.get_xydata())

Expand Down
6 changes: 0 additions & 6 deletions pandas/tests/plotting/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,19 +863,13 @@ def test_custom_business_day_freq(self):

_check_plot_works(s.plot)

@pytest.mark.xfail(
reason="GH#24426, see also "
"github.com/pandas-dev/pandas/commit/"
"ef1bd69fa42bbed5d09dd17f08c44fc8bfc2b685#r61470674"
)
def test_plot_accessor_updates_on_inplace(self):
ser = Series([1, 2, 3, 4])
_, ax = mpl.pyplot.subplots()
ax = ser.plot(ax=ax)
before = ax.xaxis.get_ticklocs()

ser.drop([0, 1], inplace=True)
_, ax = mpl.pyplot.subplots()
after = ax.xaxis.get_ticklocs()
tm.assert_numpy_array_equal(before, after)

Expand Down