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
5 changes: 5 additions & 0 deletions doc/whatsnew/v0.12.1.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

v0.12.1 (Unreleased)
--------------------

- |Fix| Make :class:`objects.PolyFit` robust to missing data (:pr:`3010`).
5 changes: 4 additions & 1 deletion seaborn/_stats/regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ def _fit_predict(self, data):

def __call__(self, data, groupby, orient, scales):

return groupby.apply(data, self._fit_predict)
return (
groupby
.apply(data.dropna(subset=["x", "y"]), self._fit_predict)
)


@dataclass
Expand Down
9 changes: 9 additions & 0 deletions tests/_stats/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import pytest
from numpy.testing import assert_array_equal, assert_array_almost_equal
from pandas.testing import assert_frame_equal

from seaborn._core.groupby import GroupBy
from seaborn._stats.regression import PolyFit
Expand Down Expand Up @@ -50,3 +51,11 @@ def test_one_grouper(self, df):
grid = np.linspace(part["x"].min(), part["x"].max(), gridsize)
assert_array_equal(part["x"], grid)
assert part["y"].diff().diff().dropna().abs().gt(0).all()

def test_missing_data(self, df):

groupby = GroupBy(["group"])
df.iloc[5:10] = np.nan
res1 = PolyFit()(df[["x", "y"]], groupby, "x", {})
res2 = PolyFit()(df[["x", "y"]].dropna(), groupby, "x", {})
assert_frame_equal(res1, res2)