diff --git a/packages/python/plotly/plotly/express/_core.py b/packages/python/plotly/plotly/express/_core.py index 6f3d55dc5c9..36c57055331 100644 --- a/packages/python/plotly/plotly/express/_core.py +++ b/packages/python/plotly/plotly/express/_core.py @@ -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 @@ -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