Tracking
Describe the bug
On the PyArrow backend, building a Categorical column straight from Python values raises. The same calls work on pandas and Polars, and casting an existing PyArrow column to Categorical already works, so it looks like only the construct-from-Python-values path is affected.
Steps or code to reproduce the bug
import narwhals as nw
# ArrowTypeError: Array chunks must all be same type
nw.new_series("s", ["a", "b", "a"], dtype=nw.Categorical, backend="pyarrow")
# ArrowInvalid: Column data for field 0 with type dictionary<values=string, indices=int32> ...
nw.from_dicts([{"a": "x"}, {"a": "y"}], schema={"a": nw.Categorical()}, backend="pyarrow")
For contrast, these all work:
nw.new_series("s", ["a", "b"], dtype=nw.Categorical, backend="pandas") # ok
nw.new_series("s", ["a", "b"], dtype=nw.Categorical, backend="polars") # ok
nw.from_dict({"a": ["x", "y"]}, schema={"a": nw.Categorical()}, backend="pyarrow") # ok
nw.from_dict({"a": ["x", "y"]}, backend="pyarrow")["a"].cast(nw.Categorical) # ok
Expected results
The Categorical column is built on PyArrow too, the same as on pandas and Polars.
Actual results
new_series raises ArrowTypeError: Array chunks must all be same type, and from_dicts raises ArrowInvalid: Column data for field 0 with type dictionary<...>. Categorical maps to pa.dictionary(uint32, string) and isn't in UNSUPPORTED_DTYPES; the arrow construction path (pa.chunked_array / pa.Table.from_pylist) can't build a dictionary-typed array straight from Python values.
This came up in #3757.
narwhals.show_versions()
Python dependencies:
narwhals: 2.23.0
numpy: 2.2.6
pandas: 2.3.3
pyarrow: 23.0.1
polars: 1.42.1
dask: 2026.7.0
duckdb: 1.5.4
ibis: 12.0.0
sqlframe: 4.3.0
Tracking
Describe the bug
On the PyArrow backend, building a
Categoricalcolumn straight from Python values raises. The same calls work on pandas and Polars, and casting an existing PyArrow column toCategoricalalready works, so it looks like only the construct-from-Python-values path is affected.Steps or code to reproduce the bug
For contrast, these all work:
Expected results
The
Categoricalcolumn is built on PyArrow too, the same as on pandas and Polars.Actual results
new_seriesraisesArrowTypeError: Array chunks must all be same type, andfrom_dictsraisesArrowInvalid: Column data for field 0 with type dictionary<...>.Categoricalmaps topa.dictionary(uint32, string)and isn't inUNSUPPORTED_DTYPES; the arrow construction path (pa.chunked_array/pa.Table.from_pylist) can't build a dictionary-typed array straight from Python values.This came up in #3757.
narwhals.show_versions()