From 7ec63088ad8795d987a7c87c66c0e8e3724c0669 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Thu, 6 Mar 2025 22:36:11 -0500 Subject: [PATCH 1/3] Gh1147 Drop version restriction on matplotlib and prevent test to write to root folder --- pyproject.toml | 4 ++-- tests/test_frame.py | 6 ++++-- tests/test_plotting.py | 27 +++++++++++++++++---------- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index c71bebaf6..5f0bb4ac5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ pyright = ">=1.1.396" poethepoet = ">=0.16.5" loguru = ">=0.6.0" typing-extensions = ">=4.4.0" -matplotlib = ">=3.5.1,<3.9.0" # TODO https://github.com/pandas-dev/pandas/issues/58851 +matplotlib = ">=3.5.10" # TODO https://github.com/pandas-dev/pandas/issues/58851 pre-commit = ">=2.19.0" black = ">=23.3.0" isort = ">=5.12.0" @@ -231,7 +231,7 @@ filterwarnings = [ # treat warnings as errors "error", # until there is a new dateutil release: github.com/dateutil/dateutil/pull/1285 - "ignore:datetime.datetime.utc:DeprecationWarning", + # "ignore:datetime.datetime.utc:DeprecationWarning", ] # Next line needed to avoid poetry complaint diff --git a/tests/test_frame.py b/tests/test_frame.py index e82351552..e947ceaa9 100644 --- a/tests/test_frame.py +++ b/tests/test_frame.py @@ -3996,8 +3996,10 @@ def test_hashable_args() -> None: df.columns = ["test"] # type: ignore[assignment] testDict = {"test": 1} - df.to_string("test", col_space=testDict) - df.to_string("test", col_space={"test": 1}) + + with ensure_clean() as path: + df.to_string(path, col_space=testDict) + df.to_string(path, col_space={"test": 1}) # GH 906 diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 1714bb71e..4a12b043b 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -575,7 +575,10 @@ def test_plot_keywords(close_figures): df = pd.DataFrame(np.random.rand(10, 5), columns=["A", "B", "C", "D", "E"]) check( - assert_type(df.plot(kind="box", vert=False, positions=[1, 4, 5, 6, 8]), Axes), + assert_type( + df.plot(kind="box", orientation="vertical", positions=[1, 4, 5, 6, 8]), + Axes, + ), Axes, ) @@ -603,15 +606,19 @@ def test_grouped_dataframe_boxplot(close_figures): check(assert_type(grouped.boxplot(subplots=True), Series), Series) # a single plot - check( - assert_type( - grouped.boxplot( - subplots=False, rot=45, fontsize=12, figsize=(8, 10), vert=False - ), - Axes, - ), - Axes, - ) + # check( + # assert_type( + # grouped.boxplot( + # subplots=False, + # rot=45, + # fontsize=12, + # figsize=(8, 10), + # orientation="horizontal", + # ), + # Axes, + # ), + # Axes, + # ) # not a literal bool check(assert_type(grouped.boxplot(subplots=bool(0.5)), Union[Axes, Series]), Series) From 849a69b4d73c1037a1944a4c2227b40b9cbb94d0 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Fri, 7 Mar 2025 19:39:45 -0500 Subject: [PATCH 2/3] Gh1147 Drop version restriction on matplotlib and prevent test to write to root folder --- pyproject.toml | 4 +--- tests/test_plotting.py | 34 +++++++++++++++++++++------------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 5f0bb4ac5..d4b955ce6 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -43,7 +43,7 @@ pyright = ">=1.1.396" poethepoet = ">=0.16.5" loguru = ">=0.6.0" typing-extensions = ">=4.4.0" -matplotlib = ">=3.5.10" # TODO https://github.com/pandas-dev/pandas/issues/58851 +matplotlib = ">=3.6.3" pre-commit = ">=2.19.0" black = ">=23.3.0" isort = ">=5.12.0" @@ -230,8 +230,6 @@ ignore-words-list = "indext, mose, sav, ser" filterwarnings = [ # treat warnings as errors "error", - # until there is a new dateutil release: github.com/dateutil/dateutil/pull/1285 - # "ignore:datetime.datetime.utc:DeprecationWarning", ] # Next line needed to avoid poetry complaint diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 4a12b043b..19a914efb 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -605,20 +605,28 @@ def test_grouped_dataframe_boxplot(close_figures): check(assert_type(grouped.boxplot(), Series), Series) check(assert_type(grouped.boxplot(subplots=True), Series), Series) + +def test_grouped_dataframe_boxplot_single(close_figures): + tuples = [t for t in itertools.product(range(10), range(2))] + index = pd.MultiIndex.from_tuples(tuples, names=["lvl0", "lvl1"]) + df = pd.DataFrame( + data=np.random.randn(len(index), 2), columns=["A", "B"], index=index + ) + grouped = df.groupby(level="lvl1") + # a single plot - # check( - # assert_type( - # grouped.boxplot( - # subplots=False, - # rot=45, - # fontsize=12, - # figsize=(8, 10), - # orientation="horizontal", - # ), - # Axes, - # ), - # Axes, - # ) + check( + assert_type( + grouped.boxplot( + subplots=False, + rot=45, + fontsize=12, + figsize=(8, 10), + ), + Axes, + ), + Axes, + ) # not a literal bool check(assert_type(grouped.boxplot(subplots=bool(0.5)), Union[Axes, Series]), Series) From 86dc4e662453c50ce9f7f26431166ad986be5a80 Mon Sep 17 00:00:00 2001 From: Loic Diridollou Date: Sun, 9 Mar 2025 20:32:34 -0400 Subject: [PATCH 3/3] GH1147 PR Feedback --- tests/test_plotting.py | 43 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 19a914efb..d89cab3c5 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -16,7 +16,10 @@ import pytest from typing_extensions import assert_type -from tests import check +from tests import ( + PD_LTE_22, + check, +) from pandas.plotting import ( deregister_matplotlib_converters, @@ -605,8 +608,31 @@ def test_grouped_dataframe_boxplot(close_figures): check(assert_type(grouped.boxplot(), Series), Series) check(assert_type(grouped.boxplot(subplots=True), Series), Series) + # a single plot + if not PD_LTE_22: + check( + assert_type( + grouped.boxplot( + subplots=False, + rot=45, + fontsize=12, + figsize=(8, 10), + orientation="horizontal", + ), + Axes, + ), + Axes, + ) + def test_grouped_dataframe_boxplot_single(close_figures): + """ + Test with pandas 2.2.3 separated to make it pass. + + With pandas 2.2.3 the passing of certain keywords is broken so this test + is put separately to make sure that we have no Axes already created. + It will fail with `orientation="horizontal"`. + """ tuples = [t for t in itertools.product(range(10), range(2))] index = pd.MultiIndex.from_tuples(tuples, names=["lvl0", "lvl1"]) df = pd.DataFrame( @@ -628,6 +654,21 @@ def test_grouped_dataframe_boxplot_single(close_figures): Axes, ) + if not PD_LTE_22: + check( + assert_type( + grouped.boxplot( + subplots=False, + rot=45, + fontsize=12, + figsize=(8, 10), + orientation="horizontal", + ), + Axes, + ), + Axes, + ) + # not a literal bool check(assert_type(grouped.boxplot(subplots=bool(0.5)), Union[Axes, Series]), Series)