Skip to content

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

Closed

Description

@ajpotts

Summary

When converting a pandas DataFrame to an Arkouda-backed DataFrame using:

>>> import arkouda as ak
>>> ak_df = df.ak.to_ak()

The resulting DataFrame columns are correctly Arkouda-backed
ExtensionArrays, but the index remains a pandas RangeIndex instead
of being converted to an Arkouda-backed index.

This breaks zero-copy semantics and violates the design invariant that
Arkouda-backed DataFrames should have Arkouda-backed indices.


Reproduction

>>> import pandas as pd
>>> import numpy as np
>>> import arkouda as ak

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

>>> ak_df["a"].values
ArkoudaArray([0 1 2 3 4])

>>> ak_df["a"].index
RangeIndex(start=0, stop=5, step=1)

Expected behavior:

type(ak_df.index.array)
# arkouda.pandas.extension._arkouda_array.ArkoudaArray

Root Cause

In _dataframe_accessor.py, the to_ak() method rebuilds the DataFrame
without converting or preserving the index:

return pd_DataFrame(cols)

This causes pandas to attach a default RangeIndex.


Proposed Fix

Modify to_ak() to convert the index using 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 maintains
architectural consistency.


Additional Improvement (Optional)

Avoid re-materializing already Arkouda-backed columns:

for name, col in self._obj.items():
    if isinstance(col.array, ArkoudaExtensionArray):
        cols[name] = col.array
    else:
        cols[name] = ArkoudaExtensionArray._from_sequence(ak_array(col.values))

Impact

  • Breaks distributed/zero-copy guarantees
  • Causes inconsistent DataFrame state
  • May introduce subtle bugs in downstream index-aware operations

Acceptance Criteria

  • df.ak.to_ak() produces a DataFrame whose index is Arkouda-backed
  • No NumPy materialization occurs during conversion
  • Existing behavior for columns is preserved
  • Add regression test verifying index backend type

Priority

Medium --- correctness and architectural consistency issue

Activity

  1. added
    bug
    on Feb 19, 2026
  2. self-assigned this
    on Feb 19, 2026
  3. added 3 commits that reference this issue on Feb 19, 2026
    bfb670a
    4a56aee
    b1bb503
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions