You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I believe I have found an error in plotly when I attempted to use plotly express to build a scatter or line plot using a dataframe with a categorical column that has been filtered to a subset of values. I am using plotly version 5.13.0.
Minimal code with some comments to produce the issue in a jupyter notebook environment:
import plotly.express as px
import pandas as pd
# Make a dataframe
df = {
'foo':[1,2,3,4,5],
'bar':[12,5,17,8,9],
'baz':[3.0,3.0,4.0,4.0,5.0]
}
df = pd.DataFrame(df)
# Make one of the columns a category type
df['baz'] = df['baz'].astype('category')
# Filter to some specific category values
qdf = df[
df['baz'].isin((3.0,4.0))
]
# Make and show a figure
fig = px.scatter(
qdf,
x = 'foo',
y = "bar",
color = "baz"
)
fig.show()
Expected output is a figure with points colored based on the categorical variable.
Actual output is: KeyError: 5.0 I'm including the traceback below. What I think is happening is that plotly is asking the dataframe what values are in the column via some process that returns all the values that COULD be in the column. Which results in a key error when those values are sent to the "get_group" function of the grouper.
~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.10/lib/python3.10/site-packages/plotly/express/_core.py in make_figure(args, constructor, trace_patch, layout_patch)
2002 )
2003 grouper = [x.grouper or one_group for x in grouped_mappings] or [one_group]
-> 2004 groups, orders = get_groups_and_orders(args, grouper)
2005
2006 col_labels = []
~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.10/lib/python3.10/site-packages/plotly/express/_core.py in get_groups_and_orders(args, grouper)
1977 full_sorted_group_names = [tuple(g) for g in full_sorted_group_names]
1978
-> 1979 groups = {
1980 sf: grouped.get_group(s if len(s) > 1 else s[0])
1981 for sf, s in zip(full_sorted_group_names, sorted_group_names)
~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.10/lib/python3.10/site-packages/plotly/express/_core.py in (.0)
1978
1979 groups = {
-> 1980 sf: grouped.get_group(s if len(s) > 1 else s[0])
1981 for sf, s in zip(full_sorted_group_names, sorted_group_names)
1982 }
~/.cache/pypoetry/virtualenvs/python-kernel-OtKFaj5M-py3.10/lib/python3.10/site-packages/pandas/core/groupby/groupby.py in get_group(self, name, obj)
815 inds = self._get_index(name)
816 if not len(inds):
--> 817 raise KeyError(name)
818
819 return obj._take_with_is_copy(inds, axis=self.axis)
KeyError: 5.0
The text was updated successfully, but these errors were encountered:
I believe I have found an error in plotly when I attempted to use plotly express to build a scatter or line plot using a dataframe with a categorical column that has been filtered to a subset of values. I am using plotly version 5.13.0.
Minimal code with some comments to produce the issue in a jupyter notebook environment:
Expected output is a figure with points colored based on the categorical variable.
Actual output is:
KeyError: 5.0
I'm including the traceback below. What I think is happening is that plotly is asking the dataframe what values are in the column via some process that returns all the values that COULD be in the column. Which results in a key error when those values are sent to the "get_group" function of the grouper.The text was updated successfully, but these errors were encountered: