Skip to content

Closes #5087 pandas series accessor for arkouda - #5099

Merged
ajpotts merged 6 commits into
Bears-R-Us:mainfrom
ajpotts:5087_pandas_series_accessor_for_arkouda_v2
Dec 17, 2025
Merged

ajpotts merged 6 commits into
Bears-R-Us:mainfrom
ajpotts:5087_pandas_series_accessor_for_arkouda_v2

Conversation

@ajpotts

@ajpotts ajpotts commented Dec 2, 2025 •

Copy link
Copy Markdown
Contributor

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:

>>> 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

@ajpotts
ajpotts force-pushed the 5087_pandas_series_accessor_for_arkouda_v2 branch from 55ea6f2 to c37e870 Compare December 2, 2025 16:59
@ajpotts ajpotts changed the title Closes #5087 pandas series accessor for arkouda v2 Closes #5087 pandas series accessor for arkouda Dec 2, 2025
@ajpotts
ajpotts force-pushed the 5087_pandas_series_accessor_for_arkouda_v2 branch from c37e870 to 9851e1e Compare December 2, 2025 17:48
@ajpotts
ajpotts marked this pull request as ready for review December 2, 2025 17:58

@drculhane drculhane 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.

Also looks solid.

@ajpotts
ajpotts force-pushed the 5087_pandas_series_accessor_for_arkouda_v2 branch 3 times, most recently from 11d969d to 1cc36dd Compare December 8, 2025 23:12

@drculhane drculhane 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 straightforward.

@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 I think!

@ajpotts
ajpotts force-pushed the 5087_pandas_series_accessor_for_arkouda_v2 branch from 9462b9b to 0abf852 Compare December 16, 2025 21:46
@ajpotts
ajpotts added this pull request to the merge queue Dec 17, 2025
Merged via the queue into Bears-R-Us:main with commit cc6bb8b Dec 17, 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.

pandas series accessor for arkouda

3 participants