Skip to content

Preserve selected child dtype when formatting union scalars #8840

Description

@connortsui20

Summary

UnionScalar formatting should format the selected child through its typed Scalar view instead of formatting the raw ScalarValue stored inside UnionValue.

This was identified while reviewing #8838 and depends on the UnionScalar support introduced there.

Current behavior

The formatter reaches directly into UnionValue::value(). That loses the selected variant's dtype when the child is dtype-aware or nested:

  • struct children display as their tuple storage and omit field names;
  • extension children display their storage representation;
  • nested union children display as union@<type-id>(...) instead of using the selected variant name.

Expected behavior

Formatting a union should preserve the normal display semantics of the selected child scalar, for example:

record({foo: 42i32})

rather than:

record([42i32])

Proposed fix

Use UnionScalar::value() to reconstruct the selected child Scalar with its dtype, then format that scalar. Add a regression test with a struct-valued child (and optionally a nested union child).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions