Kayvan-Zahiri opened a new pull request, #51045: URL: https://github.com/apache/arrow/pull/51045
### Rationale for this change `from_dataframe` builds the dictionary array without the `is_ordered` flag the producer reports, so an ordered categorical column comes back unordered. A pyarrow table with `dictionary(int32, string, ordered=True)` does not survive its own round trip, and an ordered pandas `Categorical` loses its ordering on the way in. The pandas consumer passes the flag through (`pd.Categorical(values, categories=categories, ordered=categorical["is_ordered"])`), and our own producer reports it, so pyarrow is the only side dropping it. ### What changes are included in this PR? `categorical_column_to_dictionary` passes `ordered=categorical["is_ordered"]` to `DictionaryArray.from_arrays`. Indices, dictionary and null handling are untouched. ### Are these changes tested? Yes. `test_pyarrow_roundtrip_categorical` is now parametrized over ordered True and False, and the ordered cases fail without the change: `assert table.equals(result)` sees `ordered=1` going in and `ordered=0` coming out. I also fixed a copy-paste in `test_pandas_roundtrip_categorical`, which read `describe_categorical` from the result column twice, so its `is_ordered` assertion compared the result with itself and could never fail. ### Are there any user-facing changes? An ordered dictionary column stays ordered through `from_dataframe`. No API change. I used an AI assistant while finding and writing this. I checked the behavior and the tests myself before opening the PR. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
