Skip to content
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
8 changes: 8 additions & 0 deletions doc/changelog.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ title: Changelog

- Fixed rendering of SVGs in jupyter notebooks.

## v0.15.3
(2025-01-28)

### Enhancements

- Removed warnings about copy-on-write for pandas >= 3.0.0


## v0.15.2
(2025-12-12)

Expand Down
20 changes: 12 additions & 8 deletions plotnine/_utils/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,16 @@
from typing import TYPE_CHECKING

import pandas as pd
from packaging.version import Version

if TYPE_CHECKING:
from typing_extensions import Self

from plotnine import ggplot
from plotnine.composition import Compose

PANDAS_LT_3 = Version(pd.__version__) < Version("3.0")


def reopen(fig):
"""
Expand Down Expand Up @@ -55,20 +58,20 @@ def __init__(self, plot: ggplot, show: bool = False):

# Contexts
self.rc_context = mpl.rc_context(plot.theme.rcParams)
# TODO: Remove this context when copy-on-write is permanent, i.e.
# pandas >= 3.0
self.pd_option_context = pd.option_context(
"mode.copy_on_write",
True,
)
if PANDAS_LT_3:
self.pd_option_context = pd.option_context(
"mode.copy_on_write",
True,
)

def __enter__(self) -> Self:
"""
Enclose in matplolib & pandas environments
"""

self.rc_context.__enter__()
self.pd_option_context.__enter__()
if PANDAS_LT_3:
self.pd_option_context.__enter__()

return self

Expand All @@ -89,7 +92,8 @@ def __exit__(self, exc_type, exc_value, exc_traceback):
plt.close(self.plot.figure)

self.rc_context.__exit__(exc_type, exc_value, exc_traceback)
self.pd_option_context.__exit__(exc_type, exc_value, exc_traceback)
if PANDAS_LT_3:
self.pd_option_context.__exit__(exc_type, exc_value, exc_traceback)


@dataclass
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ dependencies = [
"mizani~=0.14.0",
"numpy>=1.23.5",
"scipy>=1.8.0",
"statsmodels>=0.14.5",
"statsmodels>=0.14.6",
]
requires-python = ">=3.10"

Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 6 additions & 3 deletions tests/test_scale_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import numpy.testing as npt
import pandas as pd
import pytest
from packaging.version import Version

import plotnine as p9
from plotnine import (
Expand Down Expand Up @@ -57,6 +58,8 @@
)
from plotnine.scales.scales import make_scale

PANDAS_LT_3 = Version(pd.__version__) < Version("3.0")


# test palettes
def test_discrete_color_palettes():
Expand Down Expand Up @@ -630,15 +633,15 @@ def test_missing_data_discrete_scale():
assert p == "missing_data_discrete_scale"


@pytest.mark.skipif(PANDAS_LT_3, reason="Fails on pandas<3")
def test_missing_data_discrete_position_scale():
data = pd.DataFrame({"a": [1, 2, 3], "b": ["a", "b", None]})

# The missing data is not removed
p = ggplot(data, aes("a", "b")) + geom_point(
aes(fill="b"), stroke=0, size=10
)

with pytest.warns(PlotnineWarning):
assert p == "missing_data_discrete_position_scale"
assert p == "missing_data_discrete_position_scale"


data = pd.DataFrame(
Expand Down
Loading