Skip to content

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

Merged
ajpotts merged 2 commits into
Bears-R-Us:mainfrom
ajpotts:5353_Fix_Index.to_pandas_string/object_handling_to_use_pandas_str
Jan 28, 2026
Merged

ajpotts merged 2 commits into
Bears-R-Us:mainfrom
ajpotts:5353_Fix_Index.to_pandas_string/object_handling_to_use_pandas_str

Conversation

@ajpotts

@ajpotts ajpotts commented Jan 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR refactors Index.to_pandas() to better align Arkouda’s pandas interop with pandas’ own dtype semantics, while avoiding unintended dtype inference and unsupported server-side paths. It also modernizes and strengthens the associated unit tests.

Key Changes

Index.to_pandas() behavior

  • Explicit dtype preservation for stable dtypes
    Numeric, boolean, datetime, and timedelta data now round-trip to pandas with their original dtype explicitly preserved, avoiding pandas re-inference.

  • Improved string handling

    • Unicode string data is converted to pandas’ string dtype to match pandas NA semantics.
    • Arkouda Strings objects are materialized as pandas string dtype indexes.
    • No implicit decoding or coercion of bytes is attempted.
  • Categorical handling

    • Arkouda categoricals are converted to CategoricalIndex, preserving categories, codes, and name.
    • If Categorical.to_pandas() already returns an Index, it is reused directly.
  • Cleaner materialization path

    • Centralized logic for converting Arkouda-backed values into concrete NumPy arrays before pandas construction.

Tests

  • Replaced a monolithic test_to_pandas with smaller, focused tests:
    • Dtype preservation for int, float, and bool
    • String conversion for Python lists and Arkouda Strings
    • Rejection of mixed-type lists when allow_list=True
    • Empty index handling
    • Categorical round-trip correctness
    • MultiIndex correctness, including categorical levels and value round-trips
  • Tests now reflect supported Arkouda construction paths and avoid unreachable object/bytes cases.

Docs & cleanup

  • Expanded Index.to_pandas() docstring with clearer semantics and examples.
  • Fixed doctest import path for pandas index module.
  • Minor test cleanup (imports, readability).

Motivation

Previously, to_pandas() always passed dtype=val.dtype, which could:

  • Force inappropriate pandas dtypes
  • Mask pandas’ native string handling
  • Lead to brittle behavior across pandas versions

This refactor makes dtype behavior explicit where it matters, defers to pandas where appropriate, and ensures tests match real Arkouda usage.

Backward Compatibility

  • No change to public APIs.
  • Behavior changes are limited to pandas materialization and are covered by explicit tests.

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

@ajpotts
ajpotts force-pushed the 5353_Fix_Index.to_pandas_string/object_handling_to_use_pandas_str branch 6 times, most recently from 08bcaf4 to 150232b Compare January 27, 2026 20:50
@ajpotts
ajpotts marked this pull request as ready for review January 27, 2026 21:01
@codecov

codecov Bot commented Jan 27, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (main@0fc7e56). Learn more about missing BASE report.

Additional details and impacted files
@@           Coverage Diff            @@
##             main     #5354   +/-   ##
========================================
  Coverage        ?   100.00%           
========================================
  Files           ?         5           
  Lines           ?       115           
  Branches        ?         0           
========================================
  Hits            ?       115           
  Misses          ?         0           
  Partials        ?         0           
Flag Coverage Δ
python-coverage 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@ajpotts
ajpotts force-pushed the 5353_Fix_Index.to_pandas_string/object_handling_to_use_pandas_str branch from 150232b to 0af53cf Compare January 27, 2026 21:52
@ajpotts
ajpotts force-pushed the 5353_Fix_Index.to_pandas_string/object_handling_to_use_pandas_str branch from 0af53cf to 49c024b Compare January 28, 2026 16:07

@1RyanK 1RyanK left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@jaketrookman jaketrookman left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good

@ajpotts
ajpotts added this pull request to the merge queue Jan 28, 2026
Merged via the queue into Bears-R-Us:main with commit 58c09ad Jan 28, 2026
44 of 45 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

4 participants