Repository navigation
Conversation
ajpotts
force-pushed
the
5074_create_arkouda_accessor_for_pandas_Index
branch
from
November 19, 2025 21:15
f4789d3 to
7198dcc
Compare
ajpotts
force-pushed
the
5074_create_arkouda_accessor_for_pandas_Index
branch
from
December 2, 2025 14:34
7198dcc to
c6f8bca
Compare
ajpotts
force-pushed
the
5074_create_arkouda_accessor_for_pandas_Index
branch
from
December 2, 2025 14:35
c6f8bca to
7c728ed
Compare
ajpotts
marked this pull request as ready for review
December 2, 2025 14:37
drculhane
approved these changes
Dec 3, 2025
drculhane
left a comment
Contributor
There was a problem hiding this comment.
Again, looks comprehensive. Nicely done.
1RyanK
approved these changes
Dec 4, 2025
1RyanK
left a comment
Contributor
There was a problem hiding this comment.
Looks good, I think a few minor things though
| pandas index. | ||
|
|
||
| This is the opposite of :meth:`to_ak`. If the index is already | ||
| NumPy-backed, this is effectively a shallow copy. |
Contributor
There was a problem hiding this comment.
I think it's not quite a shallow copy?
import pandas as pd
# This is a plain, normal pandas MultiIndex
arrays = [[1, 1, 2], ["red", "blue", "red"]]
midx = pd.MultiIndex.from_arrays(arrays, names=["num", "color"])
print("Original MultiIndex:")
print(midx)
print("Original length:", len(midx))
# This uses your ArkoudaIndexAccessor.collect() implementation
midx2 = midx.ak.collect()
print("\nAfter midx.ak.collect():")
print(midx2)
print("Collected length:", len(midx2))
print("Equals original?", midx2.equals(midx))Output is
Original MultiIndex:
MultiIndex([(1, 'red'),
(1, 'blue'),
(2, 'red')],
names=['num', 'color'])
Original length: 3
After midx.ak.collect():
MultiIndex([(1, 'blue'),
(2, 'red')],
names=['num', 'color'])
Collected length: 2
Equals original? False
| """ | ||
| if hasattr(self._obj, "levels"): | ||
| for level in self._obj.levels: | ||
| values = level._data if hasattr(level, "_data") else None |
Contributor
There was a problem hiding this comment.
Would it be better to use .array instead of ._data?
| # pandas.MultiIndex in its constructor. | ||
| if isinstance(index, pd.MultiIndex): | ||
| # Preserve names when constructing the ak.MultiIndex | ||
| return ak_MultiIndex(index, names=[str(n) for n in index.names]) |
Contributor
There was a problem hiding this comment.
I think this does not quite match pandas behavior:
import pandas as pd
import arkouda as ak
from arkouda.pandas.extension._index_accessor import _pandas_index_to_ak
arrays = [[1, 1], [2, 3]]
# Note: first name is None, second is a string
midx = pd.MultiIndex.from_arrays(arrays, names=[None, "b"])
print("Original pandas MultiIndex names:", list(midx.names))
ak_midx = _pandas_index_to_ak(midx)
print("Arkouda MultiIndex names:", list(ak_midx.names))
print("Raw names repr:", repr(list(ak_midx.names)))Output is
Original pandas MultiIndex names: [None, 'b']
Arkouda MultiIndex names: ['None', 'b']
Raw names repr: ['None', 'b']
Note that in pandas, it is literally None and you have turned it into a string
|
|
||
| The resulting index stores its values on the Arkouda server: | ||
|
|
||
| >>> type(pd_idx._data) |
Contributor
There was a problem hiding this comment.
I think .array also works well here and avoids private variables
github-merge-queue Bot
pushed a commit
that referenced
this pull request
Dec 17, 2025
# Add `.ak` Series Accessor & Improve EA Construction This PR introduces a new `.ak` accessor for `pandas.Series`, completing the pandas-side API for Arkouda-backed objects and bringing Series to parity with the existing Index/MultiIndex and DataFrame accessors. ## Summary of Changes ### 1. Add `ArkoudaSeriesAccessor` (`pd.Series.ak`) New module: `arkouda/pandas/extension/_series_accessor.py` This accessor enables seamless, zero-copy transitions between: - **NumPy-backed pandas Series** - **pandas Series backed by ArkoudaExtensionArray** (distributed / server-side) - **legacy Arkouda arrays** (`pdarray`, `Strings`, `Categorical`) Supported API: - `s.ak.to_ak()` – Convert a Series to an Arkouda-backed Series while preserving index and name - `s.ak.collect()` – Materialize an Arkouda-backed Series back to NumPy - `s.ak.to_ak_legacy()` – Produce the actual Arkouda array object - `pd.Series.ak.from_ak_legacy()` – Wrap a legacy Arkouda array in a Series without materializing - `s.ak.is_arkouda` – Introspection flag The implementation follows the same design, style, and semantics as the existing Index and DataFrame accessors. --- ### 2. Register accessor and expose it `ArkoudaSeriesAccessor` is now imported and exported from `arkouda.pandas.extension.__init__`, making it part of the public API. --- ### 3. Improve `ArkoudaExtensionArray._from_sequence` This new implementation adds a dtype-dispatching factory that: - Detects Arkouda server-side arrays (`pdarray`, `Strings`, `Categorical`) - Returns the correct EA subclass (`ArkoudaArray`, `ArkoudaStringArray`, `ArkoudaCategoricalArray`) - Falls back to converting Python/NumPy sequences into Arkouda `pdarray` (via `ak_array`) - Eliminates several circular import hazards with scoped local imports - Aligns behavior with pandas’ EA construction guidelines This method is required for correct Series construction and zero-copy wrapping in the accessor. --- ### 4. Add comprehensive unit tests New file: `tests/pandas/extension/series_accessor.py` Tests cover: - Doctest validation of the accessor module - Numeric and string roundtrip conversions - Preservation of index values and **index names** - `_pandas_series_to_ak_legacy` and `_ak_legacy_to_pandas_series` - Idempotency of `to_ak()` - Proper type dispatch (`Strings` vs `pdarray`) - Correct usage of ArkoudaExtensionArray These tests mirror the Index accessor test style to maintain consistency. --- ## Motivation Arkouda’s pandas integration already supports (PRs pending #5075 and #5071): - DataFrame `.ak` accessor - Index / MultiIndex `.ak` accessor - ExtensionArray subclasses Series was the missing piece. This PR completes the pandas API surface and unlocks: - Zero-copy Series-level conversions - Smooth DataFrame ↔ Series workflows - Easier construction of Arkouda-backed Series for testing and prototyping --- ## User-Facing Impact Users can now write: ```python >>> s = pd.Series([1, 2, 3]) >>> s_ak = s.ak.to_ak() >>> s_ak.ak.is_arkouda True ``` Closes #5087: pandas series accessor for arkouda --------- Co-authored-by: ajpotts <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
New module:
arkouda/pandas/extension/_index_accessor.py
This module defines:
Provides the following methods:
.to_ak()
Convert a pandas Index/MultiIndex to an Arkouda-backed pandas object
using ArkoudaExtensionArray. Zero NumPy materialization.
.collect()
Materialize Arkouda-backed index data into NumPy-backed pandas objects.
Opposite of .to_ak().
Produce true legacy Arkouda ak.Index / ak.MultiIndex objects.
Wrap legacy Arkouda index objects back into Arkouda-backed pandas objects.
Boolean property indicating whether the index is backed by Arkouda.
_pandas_index_to_ak
_ak_index_to_pandas_no_copy
These implement the zero-copy transformation between pandas EAs and Arkouda objects.
Closes #5074: create arkouda accessor for pandas Index