Skip to content

GH1147 Drop version restriction on matplotlib and prevent test to write to root folder #1148

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
Mar 10, 2025
Merged
Show file tree
Hide file tree
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
4 changes: 1 addition & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.6.3"
pre-commit = ">=2.19.0"
black = ">=23.3.0"
isort = ">=5.12.0"
Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/test_frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
62 changes: 59 additions & 3 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -575,7 +578,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,
)

Expand All @@ -602,17 +608,67 @@ 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(
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), vert=False
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switching this to orientation='horizontal' creates an error, needs to dig into it.

Copy link
Collaborator

Choose a reason for hiding this comment

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

error in pytest or in typing? If pytest, then if you can reproduce by just using pandas, then report a pandas issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a runtime error, if you try and run the code it will throw an error.
Right now with vert=False then it runs fine but changing to orientation=‘horizontal’ then it will throw an error. I need to step into the code to understand why the conversion they are recommending is actually broken in this particular case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This seems a pandas bug, I am going to do a little bit of investigation, it happens because the orientation parameter is not passed properly.
For now if you run the plot and there are no other Axes available this will work so I will split the test and ship it as is not to block this PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I dug into it and I was not able to reproduce it on the main branch of pandas.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So you could keep the test in there and surround it with if not PD_LTE_22, and just have the test as you modified it here, and add the new test with the if statement that would then be executed in the nightly tests (which we have to separately fix)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually that would not work since the issue was how pandas passed the information to matplotlib (and we upgraded matplotlib version) and we don't have a test of the matplotlib version if I am correct.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The test was originally failing because of the matplotlib version that was upgraded and then it was how pandas supplied the kwargs to matplotlib.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes, so in the current form, with the upgraded matplotlib, the test using orientation='horizontal', the test fails with pandas 2.2.3, but works with the version in main (larger than 2.2.x).

So you could surround your desired test that includes orientation='horizontal' with a if not PD_LTE_22 code, and leave in the test as you wrote it in this PR without the if not PD_LTE_22, with a comment to remove that test once pandas releases a version beyond 2.2.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sorry I completely missed your point. This is addressed. I kept the split test and added for both a check on PD_LTE_22 with the new orientation="horizontal", I tested with poetry run poe pytest --nightly and it passed for the test_plotting.py tests (we have other tests failing but this is addressed in another PR #1152).

subplots=False,
rot=45,
fontsize=12,
figsize=(8, 10),
),
Axes,
),
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)

Expand Down