Skip to content

Closes #5419: Bug: DataFrame.ak.to_ak() Does Not Convert Index to Arkouda-Backed Index - #5420

Merged
ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5419_Bug_DataFrame.ak.to_ak_Does_Not_Convert_Index_to_Arkouda-Backed_Index
Feb 19, 2026
Merged

ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5419_Bug_DataFrame.ak.to_ak_Does_Not_Convert_Index_to_Arkouda-Backed_Index

Conversation

@ajpotts

@ajpotts ajpotts commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR fixes an architectural inconsistency in DataFrame.ak.to_ak()
where:

  • Columns were correctly converted to Arkouda-backed ExtensionArrays
  • The index remained a pandas RangeIndex

This broke Arkouda's zero-copy invariants and resulted in mixed backend
state (Arkouda-backed columns with NumPy-backed index).

This PR ensures the index is converted to an Arkouda-backed pandas
Index using ArkoudaIndexAccessor.


Problem

Before this change:

df = pd.DataFrame({"a": np.arange(5)})
ak_df = df.ak.to_ak()

ak_df["a"].array      # ArkoudaExtensionArray ✅
ak_df.index           # RangeIndex ❌

The index was silently replaced with a default RangeIndex because
to_ak() rebuilt the DataFrame without passing an index:

return pd_DataFrame(cols)

This caused: - Mixed backend state - Violation of Arkouda zero-copy
guarantees - Potential downstream inconsistencies in index-aware
operations


Changes

1. Convert Index via ArkoudaIndexAccessor

from arkouda.pandas.extension import ArkoudaIndexAccessor

idx = ArkoudaIndexAccessor(self._obj.index).to_ak()
return pd_DataFrame(cols, index=idx)

This reuses the existing index conversion infrastructure and keeps
behavior consistent with:

  • _index_accessor.py
  • Series.ak.to_ak()

2. Avoid Re-materializing Already Arkouda-Backed Columns

If a column is already Arkouda-backed, reuse it instead of calling
ak.array() again:

if isinstance(col.array, ArkoudaExtensionArray):
    cols[name] = col.array
else:
    cols[name] = ArkoudaExtensionArray._from_sequence(ak_array(col.values))

This preserves zero-copy behavior and improves performance.


New Test

Added regression test:

def test_dataframe_to_ak_converts_index_to_arkouda_backed():

Verifies:

  • Columns are Arkouda-backed
  • Index is Arkouda-backed
  • Values are preserved
  • No NumPy fallback occurs

Architectural Impact

This change restores the invariant:

An Arkouda-backed pandas DataFrame must have both: - Arkouda-backed
columns - Arkouda-backed index

No behavior changes for users except increased correctness and
consistency.


Performance Impact

  • Avoids unnecessary re-materialization for already Arkouda-backed
    columns
  • No additional server transfers introduced

Backwards Compatibility

Fully backwards compatible.
Only fixes inconsistent backend state.

Closes #5419: Bug: DataFrame.ak.to_ak() Does Not Convert Index to Arkouda-Backed Index

@ajpotts
ajpotts force-pushed the 5419_Bug_DataFrame.ak.to_ak_Does_Not_Convert_Index_to_Arkouda-Backed_Index branch from bfb670a to 4a56aee Compare February 19, 2026 11:37
@ajpotts
ajpotts marked this pull request as ready for review February 19, 2026 13:09

@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 merged commit b1bb503 into Bears-R-Us:main Feb 19, 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: DataFrame.ak.to_ak() Does Not Convert Index to Arkouda-Backed Index

2 participants