Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
- Add support for custom tick values in `mpl_to_plotly` when the matplotlib tick positions don't follow an arithmetic progression, including custom tick labels and tick values on date axes [[#5262](https://github.com/plotly/plotly.py/pull/5262)], with thanks to @robertoffmoura for the contribution!

### Fixed
- Fix Plotly Express treating unsigned integer columns (`uint8`, `uint16`, `uint32`, `uint64`) in pandas DataFrames as categorical, which caused `px.bar` and other functions to pick the wrong orientation and render empty plots [[#4291](https://github.com/plotly/plotly.py/issues/4291), [#4344](https://github.com/plotly/plotly.py/issues/4344)]
- Fix `mpl_to_plotly` not setting `paper_bgcolor` and `plot_bgcolor` from the matplotlib figure and axes backgrounds, so converted figures match the source figure's background colors [[#5285](https://github.com/plotly/plotly.py/pull/5285)], with thanks to @robertoffmoura for the contribution!
- Fix rendering issue causing a too-large div when calling `Figure.show()` in Google Colab [[#5718](https://github.com/plotly/plotly.py/pull/5718)]

Expand Down
2 changes: 1 addition & 1 deletion plotly/express/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def _is_continuous(df: nw.DataFrame, col_name: str) -> bool:
# fastpath for pandas: Narwhals' Series.dtype has a bit of overhead, as it
# tries to distinguish between true "object" columns, and "string" columns
# disguised as "object". But here, we deal with neither.
return df_native[col_name].dtype.kind in "ifc"
return df_native[col_name].dtype.kind in "iufc"
return df.get_column(col_name).dtype.is_numeric()


Expand Down
15 changes: 14 additions & 1 deletion tests/test_optional/test_px/test_px_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import pytest
from packaging import version
import unittest.mock as mock
from plotly.express._core import build_dataframe
from plotly.express._core import build_dataframe, _is_continuous
from plotly import optional_imports
from pandas.testing import assert_frame_equal
import sys
Expand Down Expand Up @@ -624,6 +624,19 @@ def test_auto_orient_x_and_y(fn, x, y, result):
assert fn(x=series[x], y=series[y]).data[0].orientation == result


@pytest.mark.parametrize("dtype", [nw.UInt8, nw.UInt16, nw.UInt32, nw.UInt64])
def test_auto_orient_unsigned_int(constructor, dtype):
df = nw.from_native(constructor(dict(category=["a", "b", "c"], value=[1, 2, 3])))
df = df.with_columns(nw.col("value").cast(dtype)).to_native()

assert _is_continuous(nw.from_native(df, eager_only=True), "value")
fig = px.bar(df, x="category", y="value")
assert fig.data[0].orientation == "v"
assert list(fig.data[0].y) == [1, 2, 3]
fig = px.bar(df, x="value", y="category")
assert fig.data[0].orientation == "h"


def test_histogram_auto_orient():
numerical = [1, 2, 3, 4]
assert px.histogram(x=numerical, nbins=5).data[0].nbinsx == 5
Expand Down
Loading