Skip to content

Closes #5426: apply to Series accessor - #5427

Merged
ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5426_apply_to_Series_accessor
Feb 24, 2026
Merged

ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:5426_apply_to_Series_accessor

Conversation

@ajpotts

@ajpotts ajpotts commented Feb 20, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This PR introduces a new apply method on the Arkouda pandas Series
accessor (Series.ak.apply).
It enables element-wise application of Python callables or supported
lambda strings directly on Arkouda-backed numeric pdarray data without
materializing to NumPy.

This integrates Arkouda's distributed apply functionality into the
pandas ExtensionArray API surface while preserving metadata (index and
name) and maintaining strict type discipline.


Key Changes

1. Series.ak.apply Implementation

Added:

Series.ak.apply(func, result_dtype=None)

Behavior:

  • Delegates execution to arkouda.apply.apply
  • Executes fully on the Arkouda server
  • Preserves:
    • Series name
    • Index values
    • Index name
  • Returns a new Arkouda-backed pandas Series

2. Strict Type Enforcement

The method explicitly requires:

  • The Series must be Arkouda-backed
  • The underlying data must be a numeric pdarray

Rejected cases:

  • NumPy-backed pandas Series
  • Strings-backed Series
  • Categorical-backed Series

This avoids silent materialization and ensures correctness while apply
only supports numeric pdarray.


3. Dtype Handling

  • result_dtype is required when the callable changes dtype
  • For string lambda expressions, Arkouda enforces that result_dtype
    must match the input dtype (validated via existing apply.py rules)

4. Metadata Preservation

All tests confirm:

  • Index equality
  • Index name preservation
  • Series name preservation
  • Distributed (Arkouda-backed) result remains intact

5. Testing

Added comprehensive tests covering:

  • Non-Arkouda-backed rejection
  • Callable-based apply
  • String lambda apply
  • Dtype change handling
  • Rejection of Strings-backed Series
  • Rejection of Categorical-backed Series
  • Metadata preservation guarantees

Tests are gated behind the ApplyMsg Chapel module and skip cleanly
when unsupported.


6. Test Stability Improvement

Clears cached attributes in ak.apply during connection setup to
prevent stale state between tests.


Design Rationale

This implementation:

  • Aligns Arkouda with pandas' ExtensionArray API expectations
  • Avoids implicit NumPy conversion
  • Maintains distributed semantics
  • Keeps feature surface disciplined while apply support is limited
    to numeric pdarray

Future extensions may expand support to:

  • Strings
  • Categorical
  • Other Arkouda-backed types

This PR establishes the correct API contract and safety boundaries
first.


Example Usage

>>> import arkouda as ak
>>> import pandas as pd

>>> ak.connect()  # doctest: +SKIP
>>> s = pd.Series([1, 2, 3]).ak.to_ak()
>>> s.ak.apply(lambda x: x + 1)

Impact

  • No breaking changes
  • Adds new ExtensionArray accessor capability
  • Strengthens API consistency
  • Improves distributed pandas parity

Related Work

Part of ongoing effort to:

  • Complete pandas ExtensionArray API coverage
  • Provide distributed equivalents of common pandas operations
  • Tighten dtype and metadata guarantees

Closes #5426: apply to Series accessor

@ajpotts
ajpotts force-pushed the 5426_apply_to_Series_accessor branch from 350884c to 58f4f7e Compare February 20, 2026 23:48
@ajpotts
ajpotts requested a review from jaketrookman February 23, 2026 14:49
@ajpotts
ajpotts force-pushed the 5426_apply_to_Series_accessor branch 2 times, most recently from 5287c23 to e89c17e Compare February 24, 2026 15:55
@ajpotts
ajpotts force-pushed the 5426_apply_to_Series_accessor branch from e89c17e to 286e1eb Compare February 24, 2026 16:17
@ajpotts
ajpotts marked this pull request as ready for review February 24, 2026 17:00

@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 800aef6 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.

apply to Series accessor

2 participants