Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: ensure that parameters are kept for NumpyArrays under ufunc operations #1712

Merged
merged 4 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 65 additions & 0 deletions tests/test_1707-broadcast-parameters-ufunc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

import pytest # noqa: F401

import awkward as ak # noqa: F401

numpy = ak.nplike.Numpy.instance()


def test_numpy_1d():
x = ak.Array(
ak.contents.NumpyArray(
numpy.array([1, 2, 3]),
parameters={"attrs": {"not": "hashable"}, "name": "x"},
)
)
y = ak.Array(
ak.contents.NumpyArray(
numpy.array([1, 2, 3]),
parameters={"attrs": {"not": "hashable"}, "name": "y"},
)
)
result = x + y
assert ak.parameters(result) == {"attrs": {"not": "hashable"}}


def test_numpy_2d():
x = ak.Array(
ak.contents.NumpyArray(
numpy.array([[1, 2, 3]]),
parameters={"attrs": {"not": "hashable"}, "name": "x"},
)
)
y = ak.Array(
ak.contents.NumpyArray(
numpy.array([[1, 2, 3]]),
parameters={"attrs": {"not": "hashable"}, "name": "y"},
)
)
result = x + y
assert ak.parameters(result) == {"attrs": {"not": "hashable"}}


def test_regular_array_numpy_1d():
x = ak.Array(
ak.contents.RegularArray(
ak.contents.NumpyArray(
numpy.array([1, 2, 3, 4, 5, 6]),
parameters={"attrs": {"not": "hashable"}, "name": "x"},
),
3,
)
)
y = ak.Array(
ak.contents.RegularArray(
ak.contents.NumpyArray(
numpy.array([7, 8, 9, 10, 11, 12]),
parameters={"attrs": {"not": "hashable"}, "name": "y"},
),
3,
)
)
result = x + y
assert result.layout.parameters == {}
assert result.layout.content.parameters == {"attrs": {"not": "hashable"}}
2 changes: 1 addition & 1 deletion tests/test_1709-ak-array-constructor-behavior.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

import pytest # noqa: F401
import awkward as ak # noqa: F401

import awkward as ak # noqa: F401

numpy = ak.nplike.Numpy.instance()

Expand Down