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

[Fix issue][#3511]lineplot of empty dataframe with hue in seaborn 0.13.0 #3569

Merged
merged 5 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion seaborn/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,8 @@ def iter_data(

grouping_keys = []
for var in grouping_vars:
grouping_keys.append(levels.get(var, []))
key = levels.get(var) if levels.get(var) is not None else []
grouping_keys.append(key)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Total nitpick, but the duplicate call to levels.get above looks cumbersome, maybe move the ternary down here? e.g.

Suggested change
key = levels.get(var) if levels.get(var) is not None else []
grouping_keys.append(key)
key = levels.get(var)
grouping_keys.append([] if key is None else key)


iter_keys = itertools.product(*grouping_keys)
if reverse:
Expand Down
5 changes: 5 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ def null_df(rng, long_df):
return df


@pytest.fixture
def empty_df(long_df):
return long_df.drop(long_df.index)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need another fixture for this, you can just empty out long_df where you pass the data to lineplot in the relevant test (not that it matters too much, but long_df.iloc[:0] is probably more efficient than dropping every index value).



@pytest.fixture
def object_df(rng, long_df):

Expand Down
5 changes: 4 additions & 1 deletion tests/test_relational.py
Original file line number Diff line number Diff line change
Expand Up @@ -1219,7 +1219,7 @@ def test_lineplot_smoke(
wide_df, wide_array,
wide_list_of_series, wide_list_of_arrays, wide_list_of_lists,
flat_array, flat_series, flat_list,
long_df, null_df, object_df
long_df, null_df, object_df, empty_df
):

f, ax = plt.subplots()
Expand Down Expand Up @@ -1302,6 +1302,9 @@ def test_lineplot_smoke(
lineplot(x="x", y="y", hue="f", size="s", data=object_df)
ax.clear()

lineplot(x="x", y="y", hue="a", data=empty_df)
ax.clear()

def test_ci_deprecation(self, long_df):

axs = plt.figure().subplots(2)
Expand Down
Loading