plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

FutureWarning in _core.py

Open ramedina86 opened this issue 1 year ago • 1 comments

Using plotly==5.18.0 and pandas==2.2.0.

I get the following FutureWarning

.venv/lib/python3.12/site-packages/plotly/express/_core.py:2065: FutureWarning: When grouping with a length-1 list-like, you will need to pass a length-1 tuple to get_group in a future version of pandas. Pass `(name,)` instead of `name` to silence this warning.
  sf: grouped.get_group(s if len(s) > 1 else s[0])

I can suppress the warning by fixing a line in get_groups_and_orders()

sf: grouped.get_group(s if len(s) > 1 else s[0])

to

sf: grouped.get_group(s if len(s) > 1 else (s[0], ))

In my case, this only happens when I include color, which seems to trigger the grouping by tuple:

This doesn't work: fig = px.bar(main_df, x='role', y='count', color='role') This works: fig = px.bar(main_df, x='role', y='count')

ramedina86 avatar Feb 02 '24 22:02 ramedina86

Thanks for reporting, @ramedina86 . Adding a similar report: https://github.com/plotly/plotly.py/issues/4500

Coding-with-Adam avatar Feb 05 '24 21:02 Coding-with-Adam