stinodego opened a new issue, #40128: URL: https://github.com/apache/arrow/issues/40128
### Describe the bug, including details regarding any error messages, version, and platform. Casting a DictionaryArray to another dictionary type will preserve the original dictionary, unless the array is empty. ### Minimal example ```python import pyarrow as pa arr = pa.array(["foo", "bar"], pa.dictionary(pa.int32(), pa.string())) arr_empty = arr[:0] arr_empty_cast = arr_empty.cast(pa.dictionary(pa.int64(), pa.string())) print(arr_empty_cast.dictionary) # [] ``` ### Additional examples ```python import pyarrow as pa arr = pa.array(["foo", "bar"], pa.dictionary(pa.int32(), pa.string())) print(arr.dictionary) # ["foo", "bar"] arr_short_cast = arr[:1].cast(pa.dictionary(pa.int64(), pa.string())) print(arr_short_cast.dictionary) # ["foo", "bar"] arr_empty = arr[:0] print(arr_empty.dictionary) # ["foo", "bar"] arr_empty_cast = arr_empty.cast(pa.dictionary(pa.int64(), pa.string())) print(arr_empty_cast.dictionary) # [] ``` ### Expected output The original categories should be preserved when changing the index type, even if the array is empty. ### Component(s) Python -- 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]
