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

Pass tuple to get_group to fix warning #4519

Merged
merged 2 commits into from
Feb 15, 2024
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
15 changes: 11 additions & 4 deletions packages/python/plotly/plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
_subplot_type_for_trace_type,
)

pandas_2_2_0 = version.parse(pd.__version__) >= version.parse("2.2.0")

NO_COLOR = "px_no_color_constant"
trendline_functions = dict(
lowess=lowess, rolling=rolling, ewm=ewm, expanding=expanding, ols=ols
Expand Down Expand Up @@ -2068,10 +2070,15 @@ def get_groups_and_orders(args, grouper):
g.insert(i, "")
full_sorted_group_names = [tuple(g) for g in full_sorted_group_names]

groups = {
sf: grouped.get_group(s if len(s) > 1 else s[0])
for sf, s in zip(full_sorted_group_names, sorted_group_names)
}
groups = {}
for sf, s in zip(full_sorted_group_names, sorted_group_names):
if len(s) > 1:
groups[sf] = grouped.get_group(s)
else:
if pandas_2_2_0:
groups[sf] = grouped.get_group((s[0],))
else:
groups[sf] = grouped.get_group(s[0])
return groups, orders


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from plotly.express._core import build_dataframe
from pandas.testing import assert_frame_equal
import sys
import warnings


# Fixtures
Expand Down Expand Up @@ -667,3 +668,16 @@ def test_x_or_y(fn):
assert list(fig.data[0].x) == constant
assert list(fig.data[0].y) == categorical
assert fig.data[0].orientation == "h"


def test_no_futurewarning():
with warnings.catch_warnings(record=True) as warn_list:
_ = px.scatter(
x=[15, 20, 29],
y=[10, 20, 30],
color=["Category 1", "Category 2", "Category 1"],
)
future_warnings = [
warn for warn in warn_list if issubclass(warn.category, FutureWarning)
]
assert len(future_warnings) == 0, "FutureWarning(s) raised!"
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
requests==2.25.1
tenacity==6.2.0
pandas==2.0.2
numpy==1.21.6
pandas==2.2.0
numpy==1.22.4
xarray==0.17.0
statsmodels
Pillow==8.2.0
Expand Down