Skip to content

Part 2 of #5074: create arkouda accessor for pandas Index - #5110

Merged
ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5074_create_arkouda_accessor_for_pandas_Index_pt2
Dec 8, 2025
Merged

ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5074_create_arkouda_accessor_for_pandas_Index_pt2

Conversation

@ajpotts

@ajpotts ajpotts commented Dec 4, 2025 •

Copy link
Copy Markdown
Contributor

PR Description

Fix MultiIndex name handling, modernize examples, and correct EA detection logic

Summary

This PR makes three small but correctness-critical improvements to the pandas Index/MultiIndex Arkouda accessor:

  1. Fix MultiIndex name mapping when a level name is None
    Previously, None names were coerced to the string "None", which created incorrect round-trip behavior between pandas and Arkouda.
    We now preserve None by emitting None instead of "None".

  2. Update documentation examples to use pd_idx.array
    Pandas no longer exposes _data on Index objects. Updating the docstring reflects the correct modern API.

  3. Fix Arkouda-backed MultiIndex detection logic
    The check previously inspected level._data, which does not exist on newer pandas versions.
    We now correctly inspect level.array and verify that it is an ArkoudaExtensionArray.

These changes improve round-trip compatibility, correctness, and pandas-2.x alignment.

Why this matters

  • Correctness: Ensures None level names survive round-trips through Arkouda without corruption.
  • Interoperability: Keeps the accessor stable across pandas releases by avoiding deprecated private attributes.
  • Robustness: MultiIndex EA detection now works reliably instead of silently returning false.

Detailed Changes

1. Preserve None names in MultiIndex

- return ak_MultiIndex(index, names=[str(n) for n in index.names])
+ return ak_MultiIndex(index, names=index.names)

2. Update example to reflect pandas' public API

- >>> type(pd_idx._data)
+ >>> type(pd_idx.array)

3. Correct MultiIndex EA detection

- values = level._data if hasattr(level, "_data") else None
+ values = level.array if hasattr(level, "_data") else None

Mini Example for Reviewers

import pandas as pd
import arkouda as ak

ak.connect()

# MultiIndex with a None name
idx = pd.MultiIndex.from_product(
    [["A", "B"], [1, 2]],
    names=[None, "second"]
)

# Convert to Arkouda-backed Index
ak_idx = idx.ak.to_ak()

print(ak_idx.names)  
# Before this PR: ['None', 'second']   (incorrect)
# After this PR:  [None, 'second']      (correct)

# Round-trip back to pandas
idx2 = ak_idx.ak.collect()
assert idx2.names == idx.names

Part 2 of #5074: create arkouda accessor for pandas Index

@ajpotts
ajpotts force-pushed the 5074_create_arkouda_accessor_for_pandas_Index_pt2 branch from e080189 to 0929da1 Compare December 4, 2025 22:21
@ajpotts
ajpotts force-pushed the 5074_create_arkouda_accessor_for_pandas_Index_pt2 branch from 0929da1 to 1ff1e1c Compare December 4, 2025 22:23
@ajpotts
ajpotts marked this pull request as ready for review December 5, 2025 16:20

@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 Dec 8, 2025
Merged via the queue into Bears-R-Us:main with commit 636e353 Dec 8, 2025
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.

3 participants