Skip to main content

Hypothesis-awkward

Hypothesis strategies for Awkward Array.

pypi-python-badge pypi-badge conda-forge-badge

test-badge codecov-badge

Awkward Array represents deeply nested, variable-length, and mixed-type data — the kind of irregular structure common in scientific datasets. Its valid arrays therefore span a vast combinatorial space, and test data written by hand covers only a small corner of it. The edge cases that break code tend to hide in the parts no one thought to write down.

Property-based testing addresses this. Instead of asserting specific outputs for hand-picked inputs, you assert properties that should hold for any valid input and let the framework generate the inputs. Hypothesis is a property-based testing library for Python: its strategies are composable objects that describe how to build test data, and when a test fails Hypothesis shrinks it, searching for a minimal sample that still triggers the failure.

This package, hypothesis-awkward, brings property-based testing to Awkward Array with a collection of strategies for generating Awkward Arrays. Its main strategy, arrays(), generates nearly fully general Awkward Arrays: called with no arguments, it produces nested, variable-length, record, and union layouts; leaf values of any NumPy dtype Awkward Array supports, as well as strings and bytestrings; optional, masked, and missing values; and virtual arrays — with options to constrain any of these. The goal is full generality, so these strategies can surface edge cases in tools that use Awkward Array, and in Awkward Array itself.

Installation

You can install the package from PyPI using pip:

pip install hypothesis-awkward

This also installs Hypothesis and Awkward Array as dependencies unless they are already installed.

The strategy arrays()

The function arrays() is the main strategy. It generates Awkward Arrays with many options to control the output arrays.

Sample outputs of arrays()

You can see sample outputs of the current version of arrays() in the test case:

from hypothesis import given

import awkward as ak
import hypothesis_awkward.strategies as st_ak


@given(array=st_ak.constructors.arrays())
def test_array(array: ak.Array) -> None:
    print(f'{array=!r}')

For example, this might print:

array=<Array ['', '\U000c2f9f', ..., '@ú\x94j\U000c4364e'] type='4 * string'>
array=<Array [[], [], None, [], ..., [], [], None] type='42 * option[var * ?bytes]'>
array=<Array [??, ??, ??, ??, ??, ??] type='6 * var * unknown'>
array=<Array [[], [], [], [], [], [], [], []] type='8 * var * string'>
array=<Array [??, ??, ??, ??, ??, ??, ??, ??] type='8 * var * string'>
array=<Array [b'O\x01\x14\xecE\xdb_'] type='1 * bytes'>
array=<Array [??, ??] type='2 * var * bytes'>
array=<Array [None] type='1 * ?bytes'>
array=<Array [??, ??, ??, ??] type='4 * string'>
array=<Array [NaT, NaT, ..., -9223372036854773681] type='26 * datetime64[Y]'>
array=<Array [[??, ??], [??, ??], ..., [??, ??]] type='8 * 2 * var * timedelta64[fs]'>
array=<Array [[[[], [], [], [], []]]] type='1 * 1 * var * var * timedelta64[fs]'>
array=<Array [[[[[], [], [], [], []]]]] type='1 * 1 * 1 * var * var * var * bool'>
array=<Array [[16996], [10841], ..., [10841], None] type='7 * option[1 * uint16]'>
array=<Array [[0]] type='1 * option[1 * uint16]'>
array=<Array [??] type='1 * option[1 * uint16]'>
array=<Array [[None]] type='1 * 1 * option[1 * option[var * int16]]'>
array=<Array [[]] type='1 * option[var * 0 * union[timedelta64[D], 0 * unknown]]'>
array=<Array [??, ??] type='2 * datetime64[D]'>
array=<Array [??, ??, ??, ??] type='4 * ?timedelta64[us]'>
array=<Array [??, ??, ??, ??, ??, ??, ..., ??, ??, ??, ??, ??, ??] type='14 * bytes'>
array=<Array [[], [], [], [], ..., [], [], [], []] type='55 * option[var * var * ...'>
array=<Array [0.0, inf, 0.0, nan, 0.0] type='5 * float16'>
array=<Array [None, -768614336404561008-11, ..., None] type='6 * ?datetime64[M]'>
array=<Array [??, ??] type='2 * option[var * 1 * string]'>

In the type strings above, a ? marks an option type (e.g., ?int64), whose missing values print as None. Virtual arrays print as ??.

The options of arrays()

The strategy arrays() has many options to control the output arrays. You can find all options in the API reference:

Other strategies

In addition to arrays(), this package includes other strategies that generate Awkward Arrays and related data types, which can be found in the API reference:

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hypothesis_awkward-0.20.0.tar.gz (230.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hypothesis_awkward-0.20.0-py3-none-any.whl (64.5 kB view details)

Uploaded Python 3

File details

Details for the file hypothesis_awkward-0.20.0.tar.gz.

File metadata

  • Download URL: hypothesis_awkward-0.20.0.tar.gz
  • Upload date:
  • Size: 230.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for hypothesis_awkward-0.20.0.tar.gz
Algorithm Hash digest
SHA256 a5a6ff5e48cc3fd76634b831ce992286ec93b8e45d3da63b73b1c5324e8ca085
MD5 fac04058b23286f562d55c261e00f182
BLAKE2b-256 fb122c130880d537738216610ae12dc6e6141e3b6dbcdf1250a149867fb9c109

See more details on using hashes here.

Provenance

The following attestation bundles were made for hypothesis_awkward-0.20.0.tar.gz:

Publisher: pypi.yml on scikit-hep/hypothesis-awkward

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file hypothesis_awkward-0.20.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hypothesis_awkward-0.20.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28405cd80a08b2491003336537c164cb04645ed81da338803cf7bfb8e97c72eb
MD5 5182f1886648f68202b3c685a4f7dfc7
BLAKE2b-256 f48d70bbfe465d7e40e89a8ec8ff887d80127d9554ed527f364912854e689df2

See more details on using hashes here.

Provenance

The following attestation bundles were made for hypothesis_awkward-0.20.0-py3-none-any.whl:

Publisher: pypi.yml on scikit-hep/hypothesis-awkward

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.20.0 This release

2 files

0.19.1

2 files

0.19.0

2 files

0.18.1

2 files

0.18.0

2 files

0.17.0

2 files

0.16.1

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.0

2 files

0.10.0

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

0.0.5

2 files

0.0.4

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page