Skip to content

[C++] Cast dictionary of extension type to extension type #31015

Description

@asfimport

We support casting a DictionaryArray to its dictionary values' type. For example:

>>> arr = pa.array([1, 2, 1]).dictionary_encode()
>>> arr
<pyarrow.lib.DictionaryArrayobjectat0x7f0c1aca46d0>
-- dictionary:
[
1,
2
]
-- indices:
[
0,
1,
0
]
>>> arr.typeDictionaryType(dictionary<values=int64, indices=int32, ordered=0>)
>>> arr.cast(arr.type.value_type)
<pyarrow.lib.Int64Arrayobjectat0x7f0c19891dc0>
[
1,
2,
1
]

However, if the type of the dictionary values is an ExtensionType, this cast is not supported:

>>> frompyarrow.tests.test_extension_typeimportUuidType
>>> storage = pa.array([b"0123456789abcdef"], type=pa.binary(16))
>>> arr = pa.ExtensionArray.from_storage(UuidType(), storage)
>>> arr
<pyarrow.lib.ExtensionArrayobjectat0x7f0c1875bc40>
[
30313233343536373839616263646566
]
>>> dict_arr = pa.DictionaryArray.from_arrays(pa.array([0, 0], pa.int32()), arr)
>>> dict_arr.typeDictionaryType(dictionary<values=extension<arrow.py_extension_type<UuidType>>, indices=int32, ordered=0>)
>>> dict_arr.cast(UuidType())
...
ArrowNotImplementedError: Unsupportedcastfromdictionary<values=extension<arrow.py_extension_type<UuidType>>, indices=int32, ordered=0> toextension<arrow.py_extension_type<UuidType>> (noavailablecastfunctionfortargettype)
../src/arrow/compute/cast.cc:119GetCastFunctionInternal(cast_options->to_type, args[0].type().get())

Reporter: Joris Van den Bossche / @jorisvandenbossche
Assignee: Miles Granger / @milesgranger
Watchers: Rok Mihevc / @rok

Related issues:

PRs and other links:

Note: This issue was originally created as ARROW-15545. Please see the migration documentation for further details.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions