diff --git a/doc/changelog.qmd b/doc/changelog.qmd index 0afaea656..cc75c84f2 100644 --- a/doc/changelog.qmd +++ b/doc/changelog.qmd @@ -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. diff --git a/plotnine/scales/scale_size.py b/plotnine/scales/scale_size.py index 0ecfcc3da..cab969bbe 100644 --- a/plotnine/scales/scale_size.py +++ b/plotnine/scales/scale_size.py @@ -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 diff --git a/tests/test_scale_internals.py b/tests/test_scale_internals.py index aff976fcd..b9c4d7c77 100644 --- a/tests/test_scale_internals.py +++ b/tests/test_scale_internals.py @@ -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, ) @@ -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")