Skip to content

Closes #5428: BUG: Pandas Series with dtype=ak Returns NumPy Index Values - #5435

Merged
ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5428_BUG_Pandas_Series_with_dtype=ak_Returns_NumPy_Index_Values
Feb 24, 2026
Merged

ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5428_BUG_Pandas_Series_with_dtype=ak_Returns_NumPy_Index_Values

Conversation

@ajpotts

@ajpotts ajpotts commented Feb 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR improves Arkouda’s pandas-extension interoperability in two areas:

  1. RangeIndex conversion is now server-side.
    _pandas_index_to_ak detects pandas.RangeIndex and constructs the corresponding index directly on the Arkouda server via ak_arange, avoiding client-side materialization for very large ranges.

  2. Series.ak.is_arkouda is now “fully Arkouda-backed”.
    The predicate now returns True only when both:

    • the Series values are stored in an ArkoudaExtensionArray, and
    • the Series index is Arkouda-backed (and for a MultiIndex, all levels are Arkouda-backed).

Motivation

  • Scalability / safety: RangeIndex is “virtual” (start/stop/step). Any conversion path that materializes its values on the client can blow up memory for huge ranges. Creating the range directly on the server avoids this footgun.
  • Correctness / clarity: Previously, Series.ak.is_arkouda could return misleading results by relying on .index.values, which is frequently a NumPy array even when the index is conceptually virtual or otherwise not truly Arkouda-backed. The updated logic checks idx.array (and MultiIndex levels) and better matches the meaning of “Arkouda-backed.”

User-visible behavior changes

_pandas_index_to_ak

  • pd.RangeIndex is converted via server-side ak_arange(...) and wrapped in ak.Index.
  • Defensive check: a RangeIndex with step == 0 raises ValueError.

Series.ak.is_arkouda

  • Now returns True only when both data and index are Arkouda-backed.
  • For pd.MultiIndex, requires each level to be Arkouda-backed.

Implementation notes

  • _pandas_index_to_ak:

    • handles pd.MultiIndex as before (delegates to ak.MultiIndex).
    • special-cases pd.RangeIndex to build values server-side using ak_arange(stop) for the common (start=0, step=1) case, otherwise ak_arange(start, stop, step).
  • Series.ak.is_arkouda:

    • early-exits False if the Series values are not an ArkoudaExtensionArray.
    • checks index backing via .array (and each MultiIndex level .array) using a defensive getattr(..., None).

Tests added

Index accessor tests (tests/pandas/extension/index_accessor.py)

  • test_pandas_index_to_ak_rangeindex_default_roundtrips
  • test_pandas_index_to_ak_rangeindex_nontrivial_roundtrips
  • test_pandas_index_to_ak_rangeindex_negative_step_roundtrips_or_errors

Series accessor tests (tests/pandas/extension/series_accessor.py)

  • test_is_arkouda_true_for_to_ak_series_with_default_rangeindex
  • test_is_arkouda_true_for_to_ak_series_with_nontrivial_index
  • test_is_arkouda_true_for_to_ak_series_with_multiindex

How to validate

  • Run the pandas-extension test suite (or at least the two modified test modules):
    • pytest -q tests/pandas/extension/index_accessor.py
    • pytest -q tests/pandas/extension/series_accessor.py

Notes / follow-ups

  • The negative-step RangeIndex test is intentionally permissive: if the backend does not support negative-step arange, the test accepts a clear exception. If negative steps should be supported, we can tighten the expectation to require round-tripping.

Closes #5428: BUG: Pandas Series with dtype=ak Returns NumPy Index Values

@ajpotts
ajpotts requested a review from jaketrookman February 24, 2026 19:08
@ajpotts
ajpotts marked this pull request as ready for review February 24, 2026 19:17
@ajpotts
ajpotts enabled auto-merge February 24, 2026 19:18

@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 Feb 24, 2026
Merged via the queue into Bears-R-Us:main with commit 0e9840f Feb 24, 2026
19 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.

BUG: Pandas Series with dtype="ak" Returns NumPy Index Values

2 participants