From 1de5ce2cf27e18b15615400efe83ba8094503bd6 Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Sat, 7 Oct 2023 13:18:39 -0400 Subject: [PATCH 1/5] TST: Fix some plotting xfails --- pandas/tests/plotting/frame/test_frame.py | 12 ++-------- .../plotting/frame/test_frame_subplots.py | 13 ----------- pandas/tests/plotting/test_datetimelike.py | 15 +++++-------- pandas/tests/plotting/test_series.py | 22 +------------------ 4 files changed, 8 insertions(+), 54 deletions(-) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 2ef1f065f603d..7be33126a57ed 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -4,7 +4,6 @@ datetime, ) import gc -import itertools import re import string import weakref @@ -83,11 +82,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) @@ -584,11 +582,6 @@ def test_line_lim_subplots(self): assert xmin <= lines[0].get_data()[0][0] assert xmax >= lines[0].get_data()[0][-1] - @pytest.mark.xfail( - strict=False, - reason="2020-12-01 this has been failing periodically on the " - "ymin==0 assertion for a week or so.", - ) @pytest.mark.parametrize("stacked", [True, False]) def test_area_lim(self, stacked): df = DataFrame( @@ -1725,13 +1718,12 @@ 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) # yerr is iterator - ax = _check_plot_works(df.plot, yerr=itertools.repeat(0.1, len(df))) + ax = _check_plot_works(df.plot, yerr=np.full(len(df), 0.1)) _check_has_errorbars(ax, xerr=0, yerr=2) def test_errorbar_with_integer_column_names(self): diff --git a/pandas/tests/plotting/frame/test_frame_subplots.py b/pandas/tests/plotting/frame/test_frame_subplots.py index 4d8d8fa4cdee3..c596b259ae980 100644 --- a/pandas/tests/plotting/frame/test_frame_subplots.py +++ b/pandas/tests/plotting/frame/test_frame_subplots.py @@ -5,9 +5,6 @@ import numpy as np import pytest -from pandas.compat import is_platform_linux -from pandas.compat.numpy import np_version_gte1p24 - import pandas as pd from pandas import ( DataFrame, @@ -422,11 +419,6 @@ def test_subplots_dup_columns_secondary_y_no_subplot(self): assert len(ax.lines) == 0 assert len(ax.right_ax.lines) == 5 - @pytest.mark.xfail( - np_version_gte1p24 and is_platform_linux(), - reason="Weird rounding problems", - strict=False, - ) def test_bar_log_no_subplots(self): # GH3254, GH3298 matplotlib/matplotlib#1882, #1892 # regressions in 1.2.1 @@ -437,11 +429,6 @@ def test_bar_log_no_subplots(self): ax = df.plot.bar(grid=True, log=True) tm.assert_numpy_array_equal(ax.yaxis.get_ticklocs(), expected) - @pytest.mark.xfail( - np_version_gte1p24 and is_platform_linux(), - reason="Weird rounding problems", - strict=False, - ) def test_bar_log_subplots(self): expected = np.array([0.1, 1.0, 10.0, 100.0, 1000.0, 1e4]) diff --git a/pandas/tests/plotting/test_datetimelike.py b/pandas/tests/plotting/test_datetimelike.py index f488ee7da87ac..d3a1819132019 100644 --- a/pandas/tests/plotting/test_datetimelike.py +++ b/pandas/tests/plotting/test_datetimelike.py @@ -287,7 +287,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 @@ -303,7 +302,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") rs = str(label.get_text()) if len(rs): assert xp == rs @@ -1330,7 +1329,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) @@ -1339,7 +1337,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 def test_ax_plot(self): x = date_range(start="2012-01-02", periods=10, freq="D") @@ -1550,19 +1548,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()) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index bf4474d085b11..393ebd6b634dc 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -5,11 +5,7 @@ import numpy as np import pytest -from pandas.compat import is_platform_linux -from pandas.compat.numpy import ( - np_long, - np_version_gte1p24, -) +from pandas.compat.numpy import np_long import pandas.util._test_decorators as td import pandas as pd @@ -276,11 +272,6 @@ def test_line_use_index_false_diff_var(self): label2 = ax2.get_xlabel() assert label2 == "" - @pytest.mark.xfail( - np_version_gte1p24 and is_platform_linux(), - reason="Weird rounding problems", - strict=False, - ) @pytest.mark.parametrize("axis, meth", [("yaxis", "bar"), ("xaxis", "barh")]) def test_bar_log(self, axis, meth): expected = np.array([1e-1, 1e0, 1e1, 1e2, 1e3, 1e4]) @@ -289,11 +280,6 @@ def test_bar_log(self, axis, meth): ax = getattr(Series([200, 500]).plot, meth)(log=True, ax=ax) tm.assert_numpy_array_equal(getattr(ax, axis).get_ticklocs(), expected) - @pytest.mark.xfail( - np_version_gte1p24 and is_platform_linux(), - reason="Weird rounding problems", - strict=False, - ) @pytest.mark.parametrize( "axis, kind, res_meth", [["yaxis", "bar", "get_ylim"], ["xaxis", "barh", "get_xlim"]], @@ -863,11 +849,6 @@ 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() @@ -875,7 +856,6 @@ def test_plot_accessor_updates_on_inplace(self): 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) From ce5535c4f5faf29b615fc4b1c317b58d74c9bac4 Mon Sep 17 00:00:00 2001 From: richard Date: Sun, 8 Oct 2023 20:15:33 -0400 Subject: [PATCH 2/5] Revert rounding xfails --- .../tests/plotting/frame/test_frame_subplots.py | 13 +++++++++++++ pandas/tests/plotting/test_series.py | 16 +++++++++++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/pandas/tests/plotting/frame/test_frame_subplots.py b/pandas/tests/plotting/frame/test_frame_subplots.py index c596b259ae980..4d8d8fa4cdee3 100644 --- a/pandas/tests/plotting/frame/test_frame_subplots.py +++ b/pandas/tests/plotting/frame/test_frame_subplots.py @@ -5,6 +5,9 @@ import numpy as np import pytest +from pandas.compat import is_platform_linux +from pandas.compat.numpy import np_version_gte1p24 + import pandas as pd from pandas import ( DataFrame, @@ -419,6 +422,11 @@ def test_subplots_dup_columns_secondary_y_no_subplot(self): assert len(ax.lines) == 0 assert len(ax.right_ax.lines) == 5 + @pytest.mark.xfail( + np_version_gte1p24 and is_platform_linux(), + reason="Weird rounding problems", + strict=False, + ) def test_bar_log_no_subplots(self): # GH3254, GH3298 matplotlib/matplotlib#1882, #1892 # regressions in 1.2.1 @@ -429,6 +437,11 @@ def test_bar_log_no_subplots(self): ax = df.plot.bar(grid=True, log=True) tm.assert_numpy_array_equal(ax.yaxis.get_ticklocs(), expected) + @pytest.mark.xfail( + np_version_gte1p24 and is_platform_linux(), + reason="Weird rounding problems", + strict=False, + ) def test_bar_log_subplots(self): expected = np.array([0.1, 1.0, 10.0, 100.0, 1000.0, 1e4]) diff --git a/pandas/tests/plotting/test_series.py b/pandas/tests/plotting/test_series.py index 393ebd6b634dc..4b485e63da75c 100644 --- a/pandas/tests/plotting/test_series.py +++ b/pandas/tests/plotting/test_series.py @@ -5,7 +5,11 @@ import numpy as np import pytest -from pandas.compat.numpy import np_long +from pandas.compat import is_platform_linux +from pandas.compat.numpy import ( + np_long, + np_version_gte1p24, +) import pandas.util._test_decorators as td import pandas as pd @@ -272,6 +276,11 @@ def test_line_use_index_false_diff_var(self): label2 = ax2.get_xlabel() assert label2 == "" + @pytest.mark.xfail( + np_version_gte1p24 and is_platform_linux(), + reason="Weird rounding problems", + strict=False, + ) @pytest.mark.parametrize("axis, meth", [("yaxis", "bar"), ("xaxis", "barh")]) def test_bar_log(self, axis, meth): expected = np.array([1e-1, 1e0, 1e1, 1e2, 1e3, 1e4]) @@ -280,6 +289,11 @@ def test_bar_log(self, axis, meth): ax = getattr(Series([200, 500]).plot, meth)(log=True, ax=ax) tm.assert_numpy_array_equal(getattr(ax, axis).get_ticklocs(), expected) + @pytest.mark.xfail( + np_version_gte1p24 and is_platform_linux(), + reason="Weird rounding problems", + strict=False, + ) @pytest.mark.parametrize( "axis, kind, res_meth", [["yaxis", "bar", "get_ylim"], ["xaxis", "barh", "get_xlim"]], From 761c6a75cc58243096bf1cc7e310effec7107c5c Mon Sep 17 00:00:00 2001 From: Richard Shadrach Date: Fri, 13 Oct 2023 16:53:40 -0400 Subject: [PATCH 3/5] debug --- pandas/tests/plotting/frame/test_frame.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 7be33126a57ed..0eaa0fe7b36f8 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -596,11 +596,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 From cea2ef42e62be90f922df1a338cdb745ab166fe7 Mon Sep 17 00:00:00 2001 From: richard Date: Fri, 13 Oct 2023 21:34:09 -0400 Subject: [PATCH 4/5] Debug --- pandas/tests/plotting/frame/test_frame.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 0eaa0fe7b36f8..75124c2895ea5 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -587,6 +587,7 @@ def test_area_lim(self, stacked): df = DataFrame( np.random.default_rng(2).random((6, 4)), columns=["x", "y", "z", "four"] ) + print(df.to_string()) neg_df = -df From e525fd127226247998f58919338ea5abd065ccb4 Mon Sep 17 00:00:00 2001 From: richard Date: Mon, 11 Dec 2023 22:39:03 -0500 Subject: [PATCH 5/5] Revert removing xfail; handle iterators in test --- pandas/tests/plotting/common.py | 4 +++- pandas/tests/plotting/frame/test_frame.py | 9 +++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pandas/tests/plotting/common.py b/pandas/tests/plotting/common.py index 69120160699c2..64e1bdadffc21 100644 --- a/pandas/tests/plotting/common.py +++ b/pandas/tests/plotting/common.py @@ -4,6 +4,7 @@ from __future__ import annotations +import copy from typing import TYPE_CHECKING import numpy as np @@ -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 diff --git a/pandas/tests/plotting/frame/test_frame.py b/pandas/tests/plotting/frame/test_frame.py index 84e0bf5990087..c8cb5435d09dc 100644 --- a/pandas/tests/plotting/frame/test_frame.py +++ b/pandas/tests/plotting/frame/test_frame.py @@ -4,6 +4,7 @@ datetime, ) import gc +import itertools import re import string import weakref @@ -638,12 +639,16 @@ def test_line_lim_subplots(self): assert xmin <= lines[0].get_data()[0][0] assert xmax >= lines[0].get_data()[0][-1] + @pytest.mark.xfail( + strict=False, + reason="2020-12-01 this has been failing periodically on the " + "ymin==0 assertion for a week or so.", + ) @pytest.mark.parametrize("stacked", [True, False]) def test_area_lim(self, stacked): df = DataFrame( np.random.default_rng(2).random((6, 4)), columns=["x", "y", "z", "four"] ) - print(df.to_string()) neg_df = -df @@ -1795,7 +1800,7 @@ def test_errorbar_plot_iterator(self): df = DataFrame(d) # yerr is iterator - ax = _check_plot_works(df.plot, yerr=np.full(len(df), 0.1)) + ax = _check_plot_works(df.plot, yerr=itertools.repeat(0.1, len(df))) _check_has_errorbars(ax, xerr=0, yerr=2) def test_errorbar_with_integer_column_names(self):