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

### Bug Fixes

- [](:class:`~plotnine.scale_size_datetime`) now honours its `range`
argument. Previously it was ignored and mapping data raised an error.

- [](:class:`~plotnine.scale_size_datetime`) now honours its `date_breaks`,
`date_labels` and `date_minor_breaks` arguments, which it previously
ignored.

- In a non-linear coordinate system (e.g. [](:class:`~plotnine.coord_trans`)),
the closing edge of a polygon is now curved along with the rest of its
boundary instead of being drawn as a straight chord.
Expand Down
6 changes: 5 additions & 1 deletion plotnine/scales/scale_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ class scale_size_datetime(scale_datetime):
guide: OptionalLegend = "legend"

def __post_init__(
self, range, date_breaks, date_labels, date_minor_breaks
self,
date_breaks: str | None,
date_labels: str | None,
date_minor_breaks: str | None,
range: tuple[float, float],
):
from mizani.palettes import area_pal

Expand Down
23 changes: 23 additions & 0 deletions tests/test_scale_internals.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from plotnine.scales.scale_size import (
scale_size_area,
scale_size_continuous,
scale_size_datetime,
scale_size_discrete,
scale_size_radius,
)
Expand Down Expand Up @@ -250,6 +251,28 @@ def test_size_palette():
s.palette(frac**2)


def test_size_datetime_arguments():
# Every initialisation-only argument is checked, not just `range`. They
# reach the scale by position, so one of them landing in the wrong
# parameter leaves the others correct and the mistake invisible.
s = scale_size_datetime(
date_breaks="1 year",
date_labels="%Y",
date_minor_breaks="1 month",
range=(2, 10),
)
npt.assert_allclose(s.palette([0.0, 1.0]), [2.0, 10.0])
assert callable(s.breaks)
assert callable(s.labels)
assert callable(s.minor_breaks)

s = scale_size_datetime()
npt.assert_allclose(s.palette([0.0, 1.0]), [1.0, 6.0])
assert s.breaks is True
assert s.labels is True
assert s.minor_breaks is True


def test_scale_identity():
def is_identity_scale(name):
return name.startswith("scale_") and name.endswith("_identity")
Expand Down