From 778f511c8f91e28a76aa6683a52029479d767738 Mon Sep 17 00:00:00 2001 From: ajpotts Date: Fri, 13 Feb 2026 17:53:52 -0500 Subject: [PATCH] Closes #5413: bug in pd.array when dtype is ak.bigint --- arkouda/numpy/pdarraycreation.py | 2 +- arkouda/pandas/extension/_arkouda_array.py | 7 ++++++- tests/pandas/extension/arkouda_array_extension.py | 10 ++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/arkouda/numpy/pdarraycreation.py b/arkouda/numpy/pdarraycreation.py index 1948ddcc493..ba1d5adbf93 100644 --- a/arkouda/numpy/pdarraycreation.py +++ b/arkouda/numpy/pdarraycreation.py @@ -329,7 +329,7 @@ def array( # If a is not already a numpy.ndarray, convert it if not isinstance(a, np.ndarray): try: - if dtype is not None and dtype != bigint: + if dtype is not None and dtype not in (bigint, "bigint"): # if the user specified dtype, use that dtype a = np.array(a, dtype=dtype) elif ( diff --git a/arkouda/pandas/extension/_arkouda_array.py b/arkouda/pandas/extension/_arkouda_array.py index 1a4b81bcf3e..71c52dcb5b2 100644 --- a/arkouda/pandas/extension/_arkouda_array.py +++ b/arkouda/pandas/extension/_arkouda_array.py @@ -114,9 +114,14 @@ def __init__( def _from_sequence(cls, scalars, dtype=None, copy=False): from arkouda.numpy.pdarraycreation import array as ak_array + from ._dtypes import ArkoudaBigintDtype + # If pandas passes our own EA dtype, ignore it and infer from data if isinstance(dtype, _ArkoudaBaseDtype): - dtype = dtype.numpy_dtype + if isinstance(dtype, ArkoudaBigintDtype) or getattr(dtype, "name", None) == "bigint": + dtype = "bigint" + else: + dtype = dtype.numpy_dtype if dtype is not None and hasattr(dtype, "numpy_dtype"): dtype = dtype.numpy_dtype diff --git a/tests/pandas/extension/arkouda_array_extension.py b/tests/pandas/extension/arkouda_array_extension.py index a3f77422231..b1cc9c38b19 100644 --- a/tests/pandas/extension/arkouda_array_extension.py +++ b/tests/pandas/extension/arkouda_array_extension.py @@ -389,6 +389,16 @@ def test_copy_default_behaves_like_deep_true(self, ea): # Values preserved np.testing.assert_array_equal(default_copy.to_numpy(), ea.to_numpy()) + def test_pd_array_construct_from_ak_bigint_pdarray_explicit_dtype_does_not_cast_to_object(self): + # Regression: used to try cast and fail on server + a = ak.array(np.array([0, -1, 2]), dtype="bigint") + + b = pd.array(a, dtype="ak.bigint") + + # Should be Arkouda-backed and preserve values + assert str(b.dtype) in ("ak_bigint", "ak.bigint", "bigint") # tolerate aliasing + np.testing.assert_array_equal(np.asarray(b), np.array([0, -1, 2], dtype=object)) + class TestArkoudaArrayAsType: def test_arkouda_array_astype_object_returns_numpy_object_array(self):