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

lineplot of empty dataframe with hue in seaborn 0.13.0 #3511

Closed
maximilianmordig opened this issue Oct 2, 2023 · 2 comments
Closed

lineplot of empty dataframe with hue in seaborn 0.13.0 #3511

maximilianmordig opened this issue Oct 2, 2023 · 2 comments

Comments

@maximilianmordig
Copy link

MWE

df1 = pd.DataFrame({}, columns=["aa", "bb", "cc"]) # empty dataframe
# df1 = pd.DataFrame([(1, 2, 3), (2, 1, 3)], columns=["aa", "bb", "cc"]) # with this, it works
sns.lineplot(df1, x="aa", y="bb") # works
sns.lineplot(df1, x="aa", y="bb", hue="cc") # does not work

Error happens with seaborn 0.13.0, but not with 0.12.2:

Error:

File .../python3.10/site-packages/seaborn/relational.py:507, in lineplot(data, x, y, hue, size, style, units, palette, hue_order, hue_norm, sizes, size_order, size_norm, dashes, markers, style_order, estimator, errorbar, n_boot, seed, orient, sort, err_style, err_kws, legend, ci, ax, **kwargs)
    504 color = kwargs.pop("color", kwargs.pop("c", None))
    505 kwargs["color"] = _default_color(ax.plot, hue, color, kwargs)
--> 507 p.plot(ax, kwargs)
    508 return ax

File .../python3.10/site-packages/seaborn/relational.py:274, in _LinePlotter.plot(self, ax, kws)
    266 # TODO How to handle NA? We don't want NA to propagate through to the
    267 # estimate/CI when some values are present, but we would also like
    268 # matplotlib to show "gaps" in the line when all values are missing.
   (...)
    271 
    272 # Loop over the semantic subsets and add to the plot
    273 grouping_vars = "hue", "size", "style"
--> 274 for sub_vars, sub_data in self.iter_data(grouping_vars, from_comp_data=True):
    276     if self.sort:
    277         sort_vars = ["units", orient, other]

File .../python3.10/site-packages/seaborn/_base.py:938, in VectorPlotter.iter_data(self, grouping_vars, reverse, from_comp_data, by_facet, allow_empty, dropna)
    935 for var in grouping_vars:
    936     grouping_keys.append(levels.get(var, []))
--> 938 iter_keys = itertools.product(*grouping_keys)
    939 if reverse:
    940     iter_keys = reversed(list(iter_keys))

TypeError: 'NoneType' object is not iterable
@mwaskom mwaskom added this to the v0.13.1 milestone Oct 7, 2023
nokoshu added a commit to nokoshu/seaborn that referenced this issue Nov 22, 2023
mwaskom pushed a commit that referenced this issue Nov 28, 2023
…3.0 (#3569)

* Update _base.py

Corresponds to the case where grouping_var has None object.

* Add a test case

Add a test case to test_relational.py and a fixture empty dataframe.

* Fix error

To avoid the error 'The truth value of an array with more than one element is ambiguous.', we don't use walrus operator.

* Incorporate feedbacks.

- Remove unnecessary fixture.
- Refactoring.
@mwaskom
Copy link
Owner

mwaskom commented Nov 28, 2023

Fixed by #3569

@mwaskom mwaskom closed this as completed Nov 28, 2023
@mwaskom
Copy link
Owner

mwaskom commented Nov 28, 2023

Thanks for reporting with a simple MWE btw!

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

No branches or pull requests

2 participants