Fix px treating unsigned integer columns as categorical - #5726
Open
Belagum wants to merge 1 commit into
Open
Conversation
The pandas fastpath in _is_continuous only checked dtype.kind against "ifc", so uint8/16/32/64 columns were treated as discrete. For px.bar this flipped the orientation heuristic and produced empty-looking plots. Add "u" to the accepted kinds, matching the narwhals path which already treats unsigned ints as numeric. Closes plotly#4291 Closes plotly#4344
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link to issue
Closes #4291
Closes #4344
Description of change
_is_continuous()has a pandas fastpath that checksdtype.kind in "ifc", so unsigned integer columns (kind == "u") were treated as categorical. Inpx.barthat flips the auto-orientation heuristic, so auint32ycolumn ends up drawn as thin horizontal bars and the plot looks empty. This adds"u"to the accepted kinds, as suggested in #4291 (comment) (the narwhals path already usesdtype.is_numeric(), which includes unsigned ints, so polars/pyarrow inputs were unaffected).Demo
Running the example from #4291 with
Rain_countcast to different dtypes, before and after:_is_continuous/ orientationuint32False/hTrue/vUInt32(nullable)False/hTrue/vuint32[pyarrow]False/hTrue/vint32True/vTrue/vUInt32True/vTrue/vuint32True/vTrue/vTesting strategy
Added
test_auto_orient_unsigned_intintest_px_input.py, parametrized over the existingconstructorfixture (pandas, pandas nullable, pandas pyarrow-backed, polars, pyarrow) andUInt8/UInt16/UInt32/UInt64. It checks_is_continuousand the resultingpx.barorientation in both directions. Without the fix the 12 pandas cases fail, the polars/pyarrow ones pass.tests/test_optional/test_pxpasses locally (excepttest_render_mode, which needs statsmodels that I don't have installed).Guidelines