-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
relplot gives a cryptic error message with col='size'
#2488
Comments
Thanks for reporting. Here's the full traceback that I see: ---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~/miniconda3/envs/py39/lib/python3.9/site-packages/seaborn/_core.py in categorical_order(vector, order)
1471 try:
-> 1472 order = vector.cat.categories
1473 except (TypeError, AttributeError):
~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/generic.py in __getattr__(self, name)
5461 return self[name]
-> 5462 return object.__getattribute__(self, name)
5463
AttributeError: 'DataFrame' object has no attribute 'cat'
During handling of the above exception, another exception occurred:
AttributeError Traceback (most recent call last)
~/miniconda3/envs/py39/lib/python3.9/site-packages/seaborn/_core.py in categorical_order(vector, order)
1475 try:
-> 1476 order = vector.unique()
1477 except AttributeError:
~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/generic.py in __getattr__(self, name)
5461 return self[name]
-> 5462 return object.__getattribute__(self, name)
5463
AttributeError: 'DataFrame' object has no attribute 'unique'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
<ipython-input-15-c57b6168b51b> in <module>
5
6 #Plotting our subplots dividing with smoker
----> 7 sns.relplot(x = "total_bill", y = "tip", hue = "smoker", col = "size", data = tips)
8
9 #Showing our plots in a proper format
~/miniconda3/envs/py39/lib/python3.9/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs)
44 )
45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46 return f(**kwargs)
47 return inner_f
48
~/miniconda3/envs/py39/lib/python3.9/site-packages/seaborn/relational.py in relplot(x, y, hue, size, style, data, row, col, col_wrap, row_order, col_order, palette, hue_order, hue_norm, sizes, size_order, size_norm, markers, dashes, style_order, legend, kind, height, aspect, facet_kws, units, **kwargs)
1013 facet_kws = {} if facet_kws is None else facet_kws.copy()
1014 facet_kws.update(grid_kws)
-> 1015 g = FacetGrid(
1016 data=full_data,
1017 col_wrap=col_wrap, row_order=row_order, col_order=col_order,
~/miniconda3/envs/py39/lib/python3.9/site-packages/seaborn/_decorators.py in inner_f(*args, **kwargs)
44 )
45 kwargs.update({k: arg for k, arg in zip(sig.parameters, args)})
---> 46 return f(**kwargs)
47 return inner_f
48
~/miniconda3/envs/py39/lib/python3.9/site-packages/seaborn/axisgrid.py in __init__(self, data, row, col, hue, col_wrap, sharex, sharey, height, aspect, palette, row_order, col_order, hue_order, hue_kws, dropna, legend_out, despine, margin_titles, xlim, ylim, subplot_kws, gridspec_kws, size)
334 col_names = []
335 else:
--> 336 col_names = categorical_order(data[col], col_order)
337
338 # Additional dict of kwarg -> list of values for mapping the hue var
~/miniconda3/envs/py39/lib/python3.9/site-packages/seaborn/_core.py in categorical_order(vector, order)
1476 order = vector.unique()
1477 except AttributeError:
-> 1478 order = pd.unique(vector)
1479
1480 if variable_type(vector) == "numeric":
~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/algorithms.py in unique(values)
395 array([('a', 'b'), ('b', 'a'), ('a', 'c')], dtype=object)
396 """
--> 397 values = _ensure_arraylike(values)
398
399 if is_extension_array_dtype(values):
~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/algorithms.py in _ensure_arraylike(values)
239 if isinstance(values, tuple):
240 values = list(values)
--> 241 values = construct_1d_object_array_from_listlike(values)
242 else:
243 values = np.asarray(values)
~/miniconda3/envs/py39/lib/python3.9/site-packages/pandas/core/dtypes/cast.py in construct_1d_object_array_from_listlike(values)
1636 # making a 1D array that contains list-likes is a bit tricky:
1637 result = np.empty(len(values), dtype="object")
-> 1638 result[:] = values
1639 return result
1640
ValueError: could not broadcast input array from shape (244,2) into shape (244) |
OK I think the answer is that it's a bug caused by the external column name colliding with one of the internal variable names (because you can do I would like to simplify that logic in general so I am hoping this bug will get fixed indirectly as part of that process. Current workaround is to rename the column something that doesn't collide with the seaborn variable names: sns.relplot(x="total_bill", y="tip", hue="smoker", col=tips["size"].rename(" size"), data=tips) |
* Avoid error from relplot faceting variable name collision Fixes #2488 * Make data attribute on output FacetGrid have original column names
In seaborn 0.11.1:
Generates "ValueError: could not broadcast input array from shape (244,2) into shape (244,)"
col='size'
doesn't seem to be interpreted as a column name.The text was updated successfully, but these errors were encountered: