Skip to content

Commit

Permalink
Avoid aggregating in lineplot when not necessary (#3081)
Browse files Browse the repository at this point in the history
* Avoid aggregating in lineplot when not necessary

* Update release notes
  • Loading branch information
mwaskom authored Oct 15, 2022
1 parent 876bedd commit 1d70f58
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions doc/whatsnew/v0.12.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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`).
8 changes: 7 additions & 1 deletion seaborn/relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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":
Expand Down
9 changes: 9 additions & 0 deletions tests/test_relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"})
Expand Down

0 comments on commit 1d70f58

Please sign in to comment.