diff --git a/doc/whatsnew/v0.12.1.rst b/doc/whatsnew/v0.12.1.rst index 76efa2b6fd..f655539268 100644 --- a/doc/whatsnew/v0.12.1.rst +++ b/doc/whatsnew/v0.12.1.rst @@ -24,4 +24,6 @@ v0.12.1 (Unreleased) - |Fix| Fixed a regression in :func:`kdeplot` where passing `cmap` for an unfilled bivariate plot would raise an exception (:pr:`3065`). +- |Fix| Addressed a performance regression in :func:`lineplot` with a large number of unique x values (:pr:`3081`). + - |Build| Seaborn no longer contains doctest-style examples, simplifying the testing infrastructure (:pr:`3034`). diff --git a/seaborn/relational.py b/seaborn/relational.py index fa8b3583b3..4fa854a630 100644 --- a/seaborn/relational.py +++ b/seaborn/relational.py @@ -427,7 +427,10 @@ def plot(self, ax, kws): sort_cols = [var for var in sort_vars if var in self.variables] sub_data = sub_data.sort_values(sort_cols) - if self.estimator is not None: + if ( + self.estimator is not None + and sub_data[orient].value_counts().max() > 1 + ): if "units" in self.variables: # TODO eventually relax this constraint err = "estimator must be None when specifying units" @@ -436,6 +439,9 @@ def plot(self, ax, kws): # Could pass as_index=False instead of reset_index, # but that fails on a corner case with older pandas. sub_data = grouped.apply(agg, other).reset_index() + else: + sub_data[f"{other}min"] = np.nan + sub_data[f"{other}max"] = np.nan # TODO this is pretty ad hoc ; see GH2409 for var in "xy": diff --git a/tests/test_relational.py b/tests/test_relational.py index ce4fbd4506..eee12e25b3 100644 --- a/tests/test_relational.py +++ b/tests/test_relational.py @@ -1070,6 +1070,15 @@ def test_plot(self, long_df, repeated_df): ax.clear() p.plot(ax, {}) + def test_non_aggregated_data(self): + + x = [1, 2, 3, 4] + y = [2, 4, 6, 8] + ax = lineplot(x=x, y=y) + line, = ax.lines + assert_array_equal(line.get_xdata(), x) + assert_array_equal(line.get_ydata(), y) + def test_orient(self, long_df): long_df = long_df.drop("x", axis=1).rename(columns={"s": "y", "y": "x"})