Summary
Calling pd.array on an Arkouda-backed Categorical fails with a NotImplementedError when a target dtype is explicitly provided. The failure occurs because pd.array ultimately attempts to iterate over the Categorical, but Arkouda's Categorical.__iter__ intentionally disallows iteration to prevent implicit data transfer from the server.
This prevents a valid and expected conversion path for Arkouda-backed categoricals.
Reproduction
import arkouda as ak
import pandas as pd
from arkouda.pandas import Categorical
pd.array(
Categorical(ak.array(["a", "a", "b"])),
dtype="ak_int64"
)
Observed Behavior
The call fails with:
NotImplementedError: Categorical does not support iteration.
To force data transfer from server, use to_ndarray
Relevant stack trace excerpt:
File .../pandas/core/construction.py:321, in array
return cls._from_sequence(data, dtype=dtype, copy=copy)
File .../_arkouda_array.py:122, in _from_sequence
return cls(ak_array(scalars, dtype=dtype, copy=copy))
File .../pdarraycreation.py:250, in array
a = list(a)
File .../categorical.py:629, in __iter__
raise NotImplementedError(...)
Expected Behavior
pd.array(Categorical(...), dtype=...) should either:
- Use a non-iterative conversion path for Arkouda-backed
Categorical, or
- Explicitly and safely materialize data via a supported method (e.g.,
to_ndarray()), or
- Fail earlier with a clearer error indicating that this conversion is unsupported with guidance on alternatives.
In particular, Pandas-style construction should not implicitly rely on Python iteration for Arkouda extension types.
Summary
Calling
pd.arrayon an Arkouda-backedCategoricalfails with aNotImplementedErrorwhen a target dtype is explicitly provided. The failure occurs becausepd.arrayultimately attempts to iterate over theCategorical, but Arkouda'sCategorical.__iter__intentionally disallows iteration to prevent implicit data transfer from the server.This prevents a valid and expected conversion path for Arkouda-backed categoricals.
Reproduction
Observed Behavior
The call fails with:
Relevant stack trace excerpt:
Expected Behavior
pd.array(Categorical(...), dtype=...)should either:Categorical, orto_ndarray()), orIn particular, Pandas-style construction should not implicitly rely on Python iteration for Arkouda extension types.