File: test_3347_weakref_mask_highlevel_array.py

package info (click to toggle)
python-awkward 2.8.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,140 kB
  • sloc: python: 182,845; cpp: 33,828; sh: 432; makefile: 21; javascript: 8
file content (25 lines) | stat: -rw-r--r-- 776 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
from __future__ import annotations

import platform

import pytest

import awkward as ak


@pytest.mark.skipif(
    platform.python_implementation() == "PyPy",
    reason="PyPy has a different GC strategy than CPython and thus weakrefs may stay alive a little bit longer than expected, see: https://doc.pypy.org/en/latest/cpython_differences.html#differences-related-to-garbage-collection-strategies",
)
def test_Array_mask_weakref():
    arr = ak.Array([1])
    m = arr.mask

    assert ak.all(m[[True]] == arr)

    del arr
    with pytest.raises(
        ValueError,
        match=r"The array to mask was deleted before it could be masked. If you want to construct this mask, you must either keep the array alive or use 'ak.mask' explicitly.",
    ):
        _ = m[[True]]