Skip to content

IndexedOptionArray.to_IndexedOptionArray64 fails when index dtype is int32 #3726

@T90REAL

Description

@T90REAL

Version of Awkward Array

2.8.10

Description and code to reproduce

Calling IndexedOptionArray.to_IndexedOptionArray64() on an array backed by an Index32 raises AttributeError. The implementation passes the Index wrapper directly to the backend astype, but only the underlying NumPy array supports that method. Index.to64() already performs the correct conversion and can be used internally to fix this.

import numpy as np
import awkward as ak
from awkward.index import Index

index32 = Index(np.array([0, 1, -1], dtype=np.int32))
content = ak.contents.NumpyArray(np.array([10, 20, 30]))

arr = ak.contents.IndexedOptionArray(index32, content)

arr.to_IndexedOptionArray64()
Traceback (most recent call last):
  File "/data/src/test.py", line 10, in <module>
    arr.to_IndexedOptionArray64()
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/contents/indexedoptionarray.py", line 272, in to_IndexedOptionArray64
    self._backend.nplike.astype(self._index, dtype=np.int64),
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/hdd/miniconda3/envs/py312/lib/python3.12/site-packages/awkward/_nplikes/array_module.py", line 751, in astype
    return x.astype(dtype, copy=copy)  # type: ignore[attr-defined]
           ^^^^^^^^
AttributeError: 'Index32' object has no attribute 'astype'. Did you mean: 'dtype'?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug (unverified)The problem described would be a bug, but needs to be triaged

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions