Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid aggregating in lineplot when not necessary #3081

Merged
merged 2 commits into from
Oct 15, 2022
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
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