Skip to content

Fix Index.to_pandas string/object handling to use pandas "str" dtype when appropriate #5353

Closed

Description

@ajpotts

Description

This ticket tracks a change to Index.to_pandas that improves compatibility with pandas expectations for string-like indexes, particularly around missing values.

Previously, Index.to_pandas always constructed a pd.Index using the NumPy dtype inferred from the underlying array. For object, unicode, or bytes dtypes (dtype.kind in {"O", "U", "S"}), this could result in a pandas Index that does not match pandas’ "string" semantics, especially with respect to NA handling.

The new logic detects when the converted NumPy array:

  • Has an object / unicode / bytes dtype, and
  • Is empty or
  • Contains only str values or None

In those cases, Index.to_pandas now constructs the result via:

pd.Index(pd.array(val, dtype="str"), name=self.name)

Activity

  1. self-assigned this
    on Jan 27, 2026
  2. added 9 commits that reference this issue on Jan 27, 2026
    5951bbf
    2106e5b
    2524df9
    21f5325
    d88c61a
    08bcaf4
    150232b
    0af53cf
    49c024b
  3. added a commit that references this issue on Jan 28, 2026
    58c09ad
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions