Skip to content

Closes #4597: implement pandas ExtensionArray for arkouda - #4598

Merged
ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:extension_array
Aug 21, 2025
Merged

ajpotts merged 1 commit into
Bears-R-Us:mainfrom
ajpotts:extension_array

Conversation

@ajpotts

@ajpotts ajpotts commented Jun 12, 2025 •

Copy link
Copy Markdown
Contributor

Summary
This PR introduces experimental support for using Arkouda arrays as pandas ExtensionArrays, enabling seamless integration with pandas Series, DataFrame, and Index operations.

Key Features
✅ ArkoudaArray, ArkoudaStringArray, and ArkoudaCategoricalArray now implement the ExtensionArray interface.

✅ Corresponding ArkoudaDtype, ArkoudaStringDtype, and ArkoudaCategoricalDtype classes added and registered.

✅ Basic support for:

Element-wise operations and reductions

Slicing, indexing, and take

Series and DataFrame construction

Joins and merges via _concat_same_type

Index and MultiIndex compatibility (partial)

✅ Unit tests for Series behavior and join operations

⚠️ String and categorical fill behavior is still evolving and may require explicit fill_value for correctness.

Implementation Notes
_concat_same_type is attached to each Arkouda-backed array class to support join operations.

A shared BaseArkoudaArray class factors out common logic for take, slicing, and equality.

Some limitations and fallbacks are documented where full pandas interoperability isn't yet available.

This work brings Arkouda one step closer to being a drop-in backend for pandas workflows at scale. It allows developers to write familiar pandas code while executing at scale on distributed memory systems.

Closes #4597: implement pandas ExtensionArray for arkouda

@ajpotts

ajpotts commented Jun 16, 2025

Copy link
Copy Markdown
Contributor Author

Examples showing it working:

In [2]: data = ArkoudaArray(ak.array([1,2,3]))
   ...: s = pd.Series(data)
   ...: s
Out[2]: 
0    1
1    2
2    3
dtype: arkouda

In [3]: 
   ...: type(s)
   ...: 
Out[3]: pandas.core.series.Series

In [4]: df = pd.DataFrame({"col1": ArkoudaArray(ak.arange(5)), "col2": ArkoudaArray(ak.arange(5)*2)})
   ...: df
Out[4]: 
  col1 col2
0    0    0
1    1    2
2    2    4
3    3    6
4    4    8

In [5]: type(df)
Out[5]: pandas.core.frame.DataFrame

In [6]: #   Indexing
   ...: s[:2]
Out[6]: 
0    1
1    2
dtype: arkouda

In [7]: #   Joins
   ...: df2 = pd.DataFrame({"col1": ArkoudaArray(ak.arange(5)*3), "col3": ArkoudaArray(ak.arange(5)*2)})
   ...: df.merge(df2, on="col1", how="inner")
Out[7]: 
  col1 col2 col3
0    0    0    0
1    3    6    2

In [8]: df.iloc[1:3]
Out[8]: 
  col1 col2
1    1    2
2    2    4

@ajpotts
ajpotts force-pushed the extension_array branch 2 times, most recently from afb39bc to 7315ba4 Compare June 16, 2025 19:30
@ajpotts
ajpotts force-pushed the extension_array branch from 7315ba4 to 0a97c4e Compare July 1, 2025 15:43
@ajpotts
ajpotts changed the base branch from master to main July 25, 2025 14:10
@ajpotts
ajpotts force-pushed the extension_array branch 5 times, most recently from d6d2928 to 056feba Compare August 11, 2025 21:05
@ajpotts
ajpotts marked this pull request as ready for review August 11, 2025 21:05

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

@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

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

Okay, in some degree of detail, here we go:

You've added four classes. ArkoudaBaseArray inherits from the pandas ExtensionArray. ArkoudaArray, ArkoudaCategoricalArray and ArkoudaStringArray all inherit from both ArkoudaBaseArray and ExtensionArray. In each case, some methods have been redefined.

So far, only ArkoudaArray has more than docstring tests in the test file.

The _arkouda_array.py test file appears to cover all of the redefined methods. I have a few observations:

  • I'd rather the nbytes test checked against a value, rather than just >0
  • Somewhat similar comment about the reduce test. It seems to only be checking that the reduction operations happened, not what the results were.
  • In test_factorize, checking against the set of codes loses some information. Imo, it would be better to check that codes = [0,1,0,2], rather than set(code) = {0,1,2}.
  • It doesn't seem to me that _from_factorized is actually given factorized input. By that, I mean it's given the unique values, but nothing corresponding to codes. Now if that was the intent (i.e., "from_factorized" means "no repeated values") then never mind.

Since you've described this as a work in progress, and since all the tests in tests/pandas/extension/arkouda_array.py pass, I'm inclined to approve it as is.

@ajpotts
ajpotts requested a review from drculhane August 20, 2025 19:04

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

Approved.

@ajpotts
ajpotts added this pull request to the merge queue Aug 21, 2025
Merged via the queue into Bears-R-Us:main with commit 3c8b272 Aug 21, 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.

implement pandas ExtensionArray for arkouda

4 participants