-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Inconsistent treatment of pandas Index when dtype is object #4483
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
Comments
Definitely confusing. What's happening is that plotly.py is not providing a type for the x axis, so plotly.js tries to infer the axis type from the data provided, and these cases are kind of on the edge: in all cases two of the three values are consistent with numeric data (including numbers as strings), but either one (first case), two (second and third cases) or three (last case) are consistent with categories. So in the first three cases we infer a numeric axis and the non-numeric value I don't think we want to alter the behavior of plotly.js here - it's meant to automatically ignore things like |
This a very useful remark, which almost solves my problem! Unfortunately, plotly.js does not regard px.bar(pd.Series([11, 22, 33], [0, 1, 'A']), height=200).update_layout(xaxis_type="category") # 3 bars
px.bar(pd.Series([11, 22, 33], ['0', 1, 'A']), height=200).update_layout(xaxis_type="category") # 3 bars
px.bar(pd.Series([11, 22, 33], [0, '1', 'A']), height=200).update_layout(xaxis_type="category") # 3 bars
px.bar(pd.Series([11, 22, 33], ['0', '1', 'A']), height=200).update_layout(xaxis_type="category") # 3 bars
px.bar(pd.Series([11, 22, 33], ['0', '1', pd.NA]), height=200).update_layout(xaxis_type="category") # 2 bars and Why is this relevant? Incidentally, the original problem I was trying to solve is plotting a histogram with s = pd.Series([0, 0, 1, 1, 1, pd.NA])
vc = s.value_counts(dropna=False)
px.bar(vc) which did not work as I expected, and some digging led to this issue. As a workaround, I would have to add something like Thank you for clarification, @alexcjohnson, and feel free to close this issue if you don't think code or docs should be changed. |
Perhaps more importantly, if the axis is numeric there's nowhere we can put a Anyway I'm glad this helped. I'll close the issue but @LiamConnors if you think there's an obvious way to improve documentation about this please reopen. |
Each of the following lines is expected to produce a bar plot with three bars. However, in 3 out of 4 cases a two-bar plot is produced. Plotly seems to discard non-numeric objects when at least one numeric object is present.
I suppose this could be an issue in plotly.js instead of plotly.py, because the figures' jsons differ only in the presence or absence of quotation marks
"
around values. But because this unexpected behaviour can be fixed in plotly.py, I open the issue here.Suggested solutions:
The text was updated successfully, but these errors were encountered: