From 6cb4c1d46633d93baf4a977bad5e97592e6ad02c Mon Sep 17 00:00:00 2001 From: Hassan Kibirige Date: Tue, 12 Nov 2024 14:51:14 +0300 Subject: [PATCH] Fixed geom_dotplot & geom_sina when index 0 is missing fixes #888 --- doc/changelog.qmd | 9 +++++++++ plotnine/geoms/geom_dotplot.py | 2 +- plotnine/mapping/aes.py | 2 +- plotnine/stats/stat_sina.py | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/changelog.qmd b/doc/changelog.qmd index fbaac6afe..572544a4a 100644 --- a/doc/changelog.qmd +++ b/doc/changelog.qmd @@ -1,6 +1,15 @@ --- title: Changelog --- +## v0.14.2 +(not-yet-released) + +### Bug Fixes + +- Fixed bugs that affected [](:class:`~plotnine.geom_dotplot`) and + [](:class:`~plotnine.geom_sina`) where data with an index that + did not include 0 led to a crash. ({{< issue 888 >}}) + ## v0.14.1 (2024-11-05) diff --git a/plotnine/geoms/geom_dotplot.py b/plotnine/geoms/geom_dotplot.py index 423111c6b..70fb1f172 100644 --- a/plotnine/geoms/geom_dotplot.py +++ b/plotnine/geoms/geom_dotplot.py @@ -204,7 +204,7 @@ def draw_group( ax_width, ax_height = bbox.width, bbox.height factor = (ax_width / ax_height) * np.ptp(ranges.y) / np.ptp(ranges.x) - size = data.loc[0, "binwidth"] * params["dotsize"] + size = data["binwidth"].iloc[0] * params["dotsize"] offsets = data["stackpos"] * params["stackratio"] if params["binaxis"] == "x": diff --git a/plotnine/mapping/aes.py b/plotnine/mapping/aes.py index 8d451402a..6db8b742e 100644 --- a/plotnine/mapping/aes.py +++ b/plotnine/mapping/aes.py @@ -644,4 +644,4 @@ def has_groups(data: pd.DataFrame) -> bool: """ # If any row in the group column is equal to NO_GROUP, then # the data all of them are and the data has no groups - return data.loc[0, "group"] != NO_GROUP + return data["group"].iloc[0] != NO_GROUP diff --git a/plotnine/stats/stat_sina.py b/plotnine/stats/stat_sina.py index 99612f8c2..c6a795d84 100644 --- a/plotnine/stats/stat_sina.py +++ b/plotnine/stats/stat_sina.py @@ -98,7 +98,7 @@ def setup_data(self, data): if ( array_kind.continuous(data["x"]) and not has_groups(data) - and (data["x"] != data.loc["x", 0]).any() + and (data["x"] != data["x"].iloc[0]).any() ): raise TypeError( "Continuous x aesthetic -- did you forget " "aes(group=...)?"