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

Conversation

nokoshu
Copy link
Contributor

@nokoshu nokoshu commented Nov 22, 2023

Corresponds to the case where grouping_var has None object.

Related issue: #3511

Corresponds to the case where grouping_var has None object.
@mwaskom
Copy link
Owner

mwaskom commented Nov 22, 2023

Thanks for taking a crack at this. Can you please add a test case that would fail with the current behavior (and pass with your fix)? Thanks!

@nokoshu
Copy link
Contributor Author

nokoshu commented Nov 23, 2023

Thank you for your comment!
I'll add a test case.

Add a test case to test_relational.py and a fixture empty dataframe.
To avoid the error 'The truth value of an array with more than one element is ambiguous.', we don't use walrus operator.
Copy link

codecov bot commented Nov 25, 2023

Codecov Report

Merging #3569 (cc4430f) into master (d4b8de8) will increase coverage by 0.00%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3569   +/-   ##
=======================================
  Coverage   98.34%   98.34%           
=======================================
  Files          75       75           
  Lines       24626    24629    +3     
=======================================
+ Hits        24218    24222    +4     
+ Misses        408      407    -1     
Files Coverage Δ
seaborn/_base.py 97.51% <100.00%> (+0.13%) ⬆️
tests/test_relational.py 99.33% <100.00%> (+<0.01%) ⬆️

Copy link
Owner

@mwaskom mwaskom left a comment

Choose a reason for hiding this comment

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

Thanks, a couple nitpicks but looks like the right approach.

Comment on lines 169 to 171
@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).

seaborn/_base.py Outdated
Comment on lines 936 to 937
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)

- Remove unnecessary fixture.
- Refactoring.
@nokoshu nokoshu requested a review from mwaskom November 26, 2023 14:06
@nokoshu
Copy link
Contributor Author

nokoshu commented Nov 26, 2023

Thank you for your review!
I incorporated feedback.

@mwaskom
Copy link
Owner

mwaskom commented Nov 28, 2023

Thanks @Noko-Github

I think it's possible that this could also be fixed upstream by making the default levels value an empty list rather than None. I am not certain whether that would cause any other problems though and this is simple and seems to work so 👍

@mwaskom mwaskom merged commit 9a2196d into mwaskom:master Nov 28, 2023
11 checks passed
@mwaskom
Copy link
Owner

mwaskom commented Nov 28, 2023

Btw if you make the PR message say "Closes #issue" or "Fixes #issue" it will close the issue automatically when merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants