Skip to content

Fix px treating unsigned integer columns as categorical - #5726

Open
Belagum wants to merge 1 commit into
plotly:mainfrom
Belagum:px-unsigned-int-continuous
Open

Fix px treating unsigned integer columns as categorical#5726
Belagum wants to merge 1 commit into
plotly:mainfrom
Belagum:px-unsigned-int-continuous

Conversation

@Belagum

@Belagum Belagum commented Sep 13, 2026

Copy link
Copy Markdown

Link to issue

Closes #4291
Closes #4344

Description of change

_is_continuous() has a pandas fastpath that checks dtype.kind in "ifc", so unsigned integer columns (kind == "u") were treated as categorical. In px.bar that flips the auto-orientation heuristic, so a uint32 y column 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 uses dtype.is_numeric(), which includes unsigned ints, so polars/pyarrow inputs were unaffected).

Demo

Running the example from #4291 with Rain_count cast to different dtypes, before and after:

input before: _is_continuous / orientation after
pandas uint32 False / h True / v
pandas UInt32 (nullable) False / h True / v
pandas uint32[pyarrow] False / h True / v
pandas int32 True / v True / v
polars UInt32 True / v True / v
pyarrow uint32 True / v True / v

Testing strategy

Added test_auto_orient_unsigned_int in test_px_input.py, parametrized over the existing constructor fixture (pandas, pandas nullable, pandas pyarrow-backed, polars, pyarrow) and UInt8/UInt16/UInt32/UInt64. It checks _is_continuous and the resulting px.bar orientation in both directions. Without the fix the 12 pandas cases fail, the polars/pyarrow ones pass. tests/test_optional/test_px passes locally (except test_render_mode, which needs statsmodels that I don't have installed).

Guidelines

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plotly.express.bar does not work with pandas uint32 dtype when passing in a list of values for y uint32 dataframe don't display in px.bar

1 participant