File: test_1688_pack_categorical.py

package info (click to toggle)
python-awkward 2.8.9-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 24,932 kB
  • sloc: python: 178,875; cpp: 33,828; sh: 432; makefile: 21; javascript: 8
file content (29 lines) | stat: -rw-r--r-- 994 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
26
27
28
29
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward/blob/main/LICENSE

from __future__ import annotations

import pytest

import awkward as ak
from awkward._nplikes.numpy import Numpy

numpy = Numpy.instance()


def test():
    pytest.importorskip("pyarrow")

    this = ak.str.to_categorical(["one", "two", "one", "three", "one", "four"])
    assert ak.is_categorical(this)
    # Ensure packing by itself doesn't change the type
    this_packed = ak.to_packed(this)
    assert this_packed.type == this.type
    # Ensure the categories match between the two
    assert ak.all(ak.categories(this_packed) == ak.categories(this))

    # Ensure the inner types match (ignoring the length change)
    this_subset_packed = ak.to_packed(this[:-1])
    assert ak.is_categorical(this_subset_packed)
    assert this_subset_packed.type.content == this.type.content
    # Ensure the categories match between the two
    assert ak.all(ak.categories(this_subset_packed) == ak.categories(this))