Skip to content

Commit

Permalink
test: add @ioana's tests of to_arraylib. (#1908)
Browse files Browse the repository at this point in the history
* test: add @ioana's tests of to_arraylib.

* Fix the formatting (black).
  • Loading branch information
jpivarski authored Nov 22, 2022
1 parent 0f8ae2a commit 3894053
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/test_1765-add-ioanas-test-of-to_arraylib.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# BSD 3-Clause License; see https://github.com/scikit-hep/awkward-1.0/blob/main/LICENSE

import numpy as np # noqa: F401
import pytest # noqa: F401

import awkward as ak # noqa: F401


def test():
aa = ak.contents.NumpyArray(
np.frombuffer(b"hellothere", "u1"), parameters={"__array__": "bytestring"}
)
b = ak._util.to_arraylib(np, aa, False)
assert b.tolist() == [104, 101, 108, 108, 111, 116, 104, 101, 114, 101]
assert b.dtype == np.dtype(np.uint8)

c = ak.contents.NumpyArray(np.array([0, 1577836800], dtype="datetime64[s]"))
assert [d.isoformat() for d in ak._util.to_arraylib(np, c, False).tolist()] == [
"1970-01-01T00:00:00",
"2020-01-01T00:00:00",
]

recordarray = ak.contents.RecordArray(
[ak.contents.NumpyArray(np.array([1, 2, 3, 4, 5], dtype=np.int64))],
fields=["one"],
)
assert ak._util.to_arraylib(np, recordarray, False).tolist() == [
(1,),
(2,),
(3,),
(4,),
(5,),
]

0 comments on commit 3894053

Please sign in to comment.