Skip to content

Closes #4946: register extension dtypes - #5095

Merged
ajpotts merged 4 commits into
Bears-R-Us:mainfrom
ajpotts:4946_register_extension_dtypes
Dec 9, 2025
Merged

ajpotts merged 4 commits into
Bears-R-Us:mainfrom
ajpotts:4946_register_extension_dtypes

Conversation

@ajpotts

@ajpotts ajpotts commented Dec 1, 2025 •

Copy link
Copy Markdown
Contributor

Improve dtype resolution & alias handling for Arkouda-backed pandas ExtensionArrays

This PR refines how Arkouda’s pandas integration handles dtype strings, expands alias support,
and strengthens correctness around when Arkouda arrays should (and should not) be constructed.
It also adds comprehensive test coverage across all Arkouda-supported dtypes.


🔧 Key Changes

1. Reworked _ArkoudaBaseDtype.construct_from_string

  • Added explicit Arkouda-prefixed dtype recognition, including:
    • ak.int64, ak_int64, akint64, arkouda.int64
    • (same structure for uint64, uint8, float64, bool, string, category, bigint)
  • Ensured plain pandas/NumPy dtype strings ("int64", "float64", "string", "category", etc.)
    fall through to pandas’ native dtype resolution.
  • Added special handling for "ak.string" and "ak.category" so they map correctly to Strings
    and Categorical.

This makes Arkouda’s dtype resolution opt-in, removes ambiguity with built-in dtypes, and
aligns with user expectations when mixing Arkouda and pure pandas workflows.


2. Comprehensive test suite for dtype parsing and integration

This PR includes full test coverage for all Arkouda dtypes and dtype aliases.

✔ Dtype string → ArkoudaDtype resolution

  • Validates all Arkouda-backed dtype classes.
  • Confirms every supported alias resolves correctly.
  • Ensures plain dtype names raise TypeError, preventing Arkouda from overriding pandas behavior.

✔ pd.array integration across all types

  • Numeric and bigint types produce an ArkoudaArray.
  • String types produce an ArkoudaStringArray.
  • Category types produce an ArkoudaCategoricalArray.
  • Ensures Arkouda-prefixed dtype names behave consistently across all aliases.
  • Ensures pandas native dtypes never create Arkouda arrays.

✔ Correct error behavior

  • dtype="bigint" remains unsupported by pandas and raises TypeError.
  • Arkouda does not intercept this, ensuring stable pandas semantics.

These tests provide end-to-end coverage for dtype resolution, array construction,
and pandas interop.


3. Clearer separation between Arkouda and native pandas behavior

This PR enforces:

  • Explicit opt-in to Arkouda using ak.* or arkouda.* prefixes
  • No interference with pandas’ own dtypes
  • Correct array classes for each Arkouda dtype
  • Consistent, predictable behavior across all dtypes
  • Improved safety through clearer error paths

Overall, this significantly improves both user ergonomics and the robustness of the pandas
interoperability layer.


🧪 Summary of user-visible behavior after this PR

dtype string Result
"int64" native pandas int64 array
"ak.int64" / "ak_int64" / … ArkoudaArray backed by int64
"bool" pandas boolean array
"ak.bool_" / "akbool" / … ArkoudaArray backed by Arkouda bool
"string" pandas string dtype
"ak.string" ArkoudaStringArray
"category" pandas Categorical
"ak.category" ArkoudaCategoricalArray
"bigint" TypeError (pandas behavior)
"ak.bigint" ArkoudaArray backed by BigInt

📈 Why this matters

  • Eliminates dtype ambiguity between Arkouda and pandas.
  • Ensures dtype parsing matches user intent.
  • Produces correct extension array types for every dtype.
  • Makes mixed pandas + Arkouda workflows predictable.
  • Provides a robust foundation for future Arkouda/pandas integrations,
    including server-side BigInt ops, richer string operations, and improved categorical behavior.

✔ Ready for Review

This PR includes:

  • Full implementation
  • Comprehensive test coverage
  • Updated behavior aligned with design principles
  • No breaking changes for existing Arkouda users

Please review and provide feedback!

Closes #4946: register extension dtypes

@ajpotts

ajpotts commented Dec 1, 2025

Copy link
Copy Markdown
Contributor Author

Demo: Arkouda dtype aliases vs plain pandas dtypes

You can run this in an IPython session or Jupyter notebook.

>>> import arkouda as ak
>>> ak.connect()

>>> import pandas as pd
>>> from arkouda.pandas.extension import (
...     ArkoudaArray,
...     ArkoudaStringArray,
...     ArkoudaCategoricalArray,
... )
>>> from arkouda.pandas.extension._dtypes import (
...     _ArkoudaBaseDtype,
...     ArkoudaInt64Dtype,
...     ArkoudaStringDtype,
...     ArkoudaCategoricalDtype,
... )

# ---------------------------------------------------------------------
# 1. Plain pandas dtypes stay pure pandas (NO Arkouda involvement)
# ---------------------------------------------------------------------

>>> a_int = pd.array([1, 3, 4], dtype="int64")
>>> type(a_int)
pandas.core.arrays.numpy_.NumpyExtensionArray

>>> a_str = pd.array(["a", "b", "c"], dtype="string")
>>> type(a_str)
pandas.core.arrays.string_.StringArray

# Confirm they are not Arkouda-backed
>>> isinstance(a_int, ArkoudaArray), isinstance(a_str, ArkoudaArray)
(False, False)

# ---------------------------------------------------------------------
# 2. Arkouda-prefixed dtypes opt into Arkouda-backed arrays
# ---------------------------------------------------------------------

# Numeric example: ak.int64
>>> a_ak_int = pd.array([1, 3, 4], dtype="ak.int64")
>>> type(a_ak_int)
<class 'arkouda.pandas.extension._arkouda_array.ArkoudaArray'>

>>> a_ak_int.dtype
ArkoudaInt64Dtype('int64')

>>> isinstance(a_ak_int, ArkoudaArray)
True

# Demonstrate aliases
>>> _ArkoudaBaseDtype.construct_from_string("ak_int64")
ArkoudaInt64Dtype('int64')

>>> _ArkoudaBaseDtype.construct_from_string("akint64")
ArkoudaInt64Dtype('int64')

>>> _ArkoudaBaseDtype.construct_from_string("arkouda.int64")
ArkoudaInt64Dtype('int64')

# ---------------------------------------------------------------------
# 3. String and category use their specialized Arkouda EAs
# ---------------------------------------------------------------------

# String example
>>> a_ak_str = pd.array(["a", "b", "c"], dtype="ak.string")
>>> type(a_ak_str)
<class 'arkouda.pandas.extension._arkouda_string_array.ArkoudaStringArray'>

>>> a_ak_str.dtype
ArkoudaStringDtype('string')

>>> isinstance(a_ak_str, ArkoudaStringArray)
True

# Category example
>>> a_ak_cat = pd.array(["red", "blue", "red"], dtype="ak.category")
>>> type(a_ak_cat)
<class 'arkouda.pandas.extension._arkouda_categorical_array.ArkoudaCategoricalArray'>

>>> a_ak_cat.dtype
ArkoudaCategoricalDtype('category')

>>> isinstance(a_ak_cat, ArkoudaCategoricalArray)
True

# ---------------------------------------------------------------------
# 4. Plain "bigint" is not supported by pandas; Arkouda does not override
# ---------------------------------------------------------------------

>>> from pandas.errors import DataError
>>> import pytest

>>> try:
...     pd.array([1, 3, 4], dtype="bigint")
... except TypeError as e:
...     print("TypeError from pandas as expected:", e)
TypeError from pandas as expected: data type 'bigint' not understood

# But Arkouda-prefixed bigint works:
>>> a_ak_big = pd.array([1, 3, 4], dtype="ak.bigint")
>>> type(a_ak_big)
<class 'arkouda.pandas.extension._arkouda_array.ArkoudaArray'>

>>> a_ak_big.dtype
ArkoudaBigintDtype('bigint')

@ajpotts
ajpotts marked this pull request as ready for review December 1, 2025 21:44

@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 complete to me.

@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! Definitely do not have to address all of these.

Comment thread arkouda/pandas/extension/_dtypes.py Resolved
Comment thread arkouda/pandas/extension/_dtypes.py Resolved
Comment thread arkouda/pandas/extension/_dtypes.py Resolved
@ajpotts
ajpotts force-pushed the 4946_register_extension_dtypes branch from 028116f to d9a73f4 Compare December 8, 2025 15:22

@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 merged commit 05c663c into Bears-R-Us:main Dec 9, 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.

register extension dtypes

4 participants