Skip to content

Commit

Permalink
Fixed geom_dotplot & geom_sina when index 0 is missing
Browse files Browse the repository at this point in the history
fixes #888
  • Loading branch information
has2k1 committed Nov 12, 2024
1 parent 8a3eb88 commit 6cb4c1d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 3 deletions.
9 changes: 9 additions & 0 deletions doc/changelog.qmd
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
2 changes: 1 addition & 1 deletion plotnine/geoms/geom_dotplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
2 changes: 1 addition & 1 deletion plotnine/mapping/aes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion plotnine/stats/stat_sina.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=...)?"
Expand Down

0 comments on commit 6cb4c1d

Please sign in to comment.