Skip to content

Compute method if_else seems to create an invalid Dictionary Array #47886

Closed

Description

@qsourav

Describe the bug, including details regarding any error messages, version, and platform.

When if_else() is performed on two ChunkedArrays of ordered dictionary type, the resultant ChunkedArray is somewhat strange:

import pyarrow as pa
import pyarrow.compute as pc
dictionary = ["a", "b", "c"]

c1 = pa.DictionaryArray.from_arrays(pa.array([0,1,0], type=pa.int32()), dictionary, ordered=True)
c2 = pa.DictionaryArray.from_arrays(pa.array([2,1,0], type=pa.int32()), dictionary, ordered=True)
c3 = pa.DictionaryArray.from_arrays(pa.array([1,1,0], type=pa.int32()), dictionary, ordered=True)
left = pa.chunked_array([c1, c2, c3])
print(left.type) # ordered=True


c1 = pa.DictionaryArray.from_arrays(pa.array([0,1,0], type=pa.int32()), dictionary, ordered=True)
c2 = pa.DictionaryArray.from_arrays(pa.array([2,None,0], type=pa.int32()), dictionary, ordered=True)
c3 = pa.DictionaryArray.from_arrays(pa.array([None,1,0], type=pa.int32()), dictionary, ordered=True)
right = pa.chunked_array([c1, c2, c3])
print(right.type) # ordered=True


mask = pc.is_null(right)
res = pc.if_else(mask, left, right)
print(res.type) # ordered=True
print(res.chunk(0).type) # ordered=False
print(res.chunk(1).type) # ordered=False
print(res.chunk(2).type) # ordered=False

res.type shows ordered=True, while the internal chunks are unordered.
If internal chunks are unordered, should not the ChunkedArray (res) be marked as unordered as well?

It causes some internal issues in my application (I am using C++ interface: arrow::compute::CallFunction) aborting my program with: Array chunks must all be same type.

PS. I checked with nightly package and it seems to be there as well:
pip install -i https://pypi.anaconda.org/scientific-python-nightly-wheels/simple pyarrow

Looking forward to your input/suggestion on this.

Thanks and Regards,
Sourav Saha

Component(s)

C++, Python

Activity

  1. goldigd05 commented on Jan 4, 2026

    @goldigd05

    Hi, I would like to report a bug in if_else when used on ordered dictionary ChunkedArrays.

    Currently, the resulting ChunkedArray reports ordered=True at the top level,
    but its internal chunks are ordered=False. This can cause C++ errors like
    "Array chunks must all be same type" when using arrow::compute::CallFunction.

    I suggest that if_else should either:

    1. Preserve the ordered property for each internal chunk, or
    2. If chunks cannot remain ordered, mark the top-level ChunkedArray as unordered.

    I can help reproduce this in a minimal test and propose a fix.

  2. thisisnic commented on Oct 20, 2026

    @thisisnic
    Member

    This was fixed in #49937

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions