tinezivic opened a new pull request, #49797:
URL: https://github.com/apache/arrow/pull/49797

   ### Rationale for this change
   
   `DictionaryBuilderBase::type()` does not pass the `ordered` parameter to 
`::arrow::dictionary()`, causing it to always default to `false`. This means 
that any `DictionaryArray` built through `MakeBuilder()` or 
`MakeDictionaryBuilder()` with an ordered `DictionaryType` will produce an 
array where `type().ordered() == false`.
   
   This affects PyArrow users: `pa.array(data, type=pa.dictionary(pa.int8(), 
pa.string(), ordered=True))` returns an array with `ordered=False`.
   
   Reported in: https://github.com/apache/arrow/issues/41017
   Also caused: https://github.com/pandas-dev/pandas/issues/58152
   
   ### What changes are included in this PR?
   
   - Add `bool ordered_ = false` member and `set_ordered()` method to 
`DictionaryBuilderBase` (both the primary template and the `NullType` 
specialization)
   - Pass `ordered_` to `::arrow::dictionary()` in `type()` and 
`FinishInternal()`
   - Add `bool ordered` field to `DictionaryBuilderCase` in `builder.cc`
   - Propagate `dict_type.ordered()` through `MakeBuilderImpl::Visit()` and 
`MakeDictionaryBuilder()`
   
   ### Are these changes tested?
   
   Yes. Added 3 C++ tests in `array_dict_test.cc`:
   - `MakeBuilderPreservesOrdered` — verifies `MakeBuilder` with ordered dict 
type produces ordered array
   - `MakeBuilderUnorderedByDefault` — verifies unordered stays unordered
   - `MakeDictionaryBuilderPreservesOrdered` — verifies `MakeDictionaryBuilder` 
preserves ordered
   
   ### Are there any user-facing changes?
   
   No API changes. `DictionaryBuilder` now correctly preserves the `ordered` 
flag from the input `DictionaryType`, fixing the silent data loss.


-- 
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]

Reply via email to