Skip to content

ak.almost_equal raises IndexError for UnionArray with unused contents #3772

@ikrommyd

Description

@ikrommyd

Version of Awkward Array

HEAD

Description and code to reproduce

To reproduce

import awkward as ak
import numpy as np

form = ak.forms.UnionForm(
    "i8",
    "i64",
    [
        ak.forms.NumpyForm("int64", form_key="numpy1"),
        ak.forms.NumpyForm("int64", form_key="numpy2"),
    ],
    form_key="union",
)
buffers = {
    "union-tags": np.array([1, 1], dtype=np.int8),
    "union-index": np.array([0, 1]),
    "numpy1-data": np.array([1, 2]),
    "numpy2-data": np.array([3, 4]),
}

array = ak.from_buffers(form, 2, buffers)
print(ak.almost_equal(array, array))

gives

File ~/Dropbox/work/pyhep_dev/awkward/src/awkward/operations/ak_almost_equal.py:249, in _impl.<locals>.visitor(left, right)
    245 # Create map from left tags to right tags
    246 left_tag_to_right_tag = backend.nplike.empty(
    247     left_tag_order.size, dtype=np.int64
    248 )
--> 249 left_tag_to_right_tag[left_tag_order] = right_tag_order
    251 # Map left tags onto right, such that the result should equal right.tags
    252 # if the two tag arrays are equivalent
    253 new_left_tag = left_tag_to_right_tag[left.tags.data]

IndexError: index 1 is out of bounds for axis 0 with size 1

This error occurred while calling

    ak.almost_equal(
        <Array [3, 4] type='2 * union[int64, int64]'>
        <Array [3, 4] type='2 * union[int64, int64]'>
    )

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

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions