Skip to main content

Hypothesis strategies for Awkward Array

Project description

hypothesis-awkward

Hypothesis strategies for Awkward Arrays.

pypi-badge pypi-python-badge

test-badge codecov-badge

Hypothesis is a property-based testing library. Its strategies are Python functions that strategically generate test data that can fail test cases in pytest and other testing frameworks. Once a test fails, Hypothesis searches for the simplest sample that causes the same error. Hypothesis automatically explores edge cases; developers do not need to craft test data manually.

Property-based testing is useful for finding edge cases in array libraries and in code that uses them. In fact, Hypothesis strategies for NumPy and pandas data types are included in Hypothesis itself. Xarray provides strategies for its data structure. The Apache Arrow codebase has strategies for PyArrow, which are not officially documented in its API reference.

This package, hypothesis-awkward, is a collection of Hypothesis strategies for Awkward Array, which can represent a wide variety of layouts of nested, variable-length, and mixed-type data. The current version of this package includes strategies that generate samples with certain types of layouts. The goal is to develop strategies that can generate fully general Awkward Arrays with multiple options to control the layout, data types, missing values, masks, and other array attributes. These strategies can help close in on edge cases in tools that use Awkward Array, and Awkward Array itself.

[!NOTE]

This package is early work in progress and still experimental. The APIs may change over time.

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 is currently experimental and developed in strategies/constructors/. The plan is to have arrays() generate fully general 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 [] type='0 * bool'>
array=<Array [0] type='1 * int16'>
array=<Array [1.72e-11, -3.4e+38, -3.4e+38, -4.05e+15] type='4 * float32'>
array=<Array [[], [], [], []] type='4 * var * 2 * timedelta64[W]'>
array=<Array ['', "e\U00034a9e'"] type='2 * string'>
array=<Array [[], ['char']] type='2 * var * string'>
array=<Array [[b'\xd7']] type='1 * var * bytes'>
array=<Array [[[], []], [[]], [], []] type='5 * var * var * 4 * unknown'>
array=<Array [] type='0 * unknown'>
array=<Array [{Rd: []}] type='1 * {Rd: var * datetime64[s]}'>
array=<Array [(''), (..., ...), ..., (..., ...), ('\U0005f041')] type='6 * (string)'>
array=<Array [False] type='1 * union[bytes, bool]'>
array=<Array [36, [b'\x92\xa7\x0b']] type='2 * union[int8, 1 * bytes, unknown]'>
array=<Array [b'5f\x18\xbc', ..., b'5f\x18\xbc'] type='3 * union[string, bytes]'>
array=<Array [0, 0, -5.53e+16] type='3 * union[float32, unknown]'>
array=<Array [??, ??, ??] type='3 * uint32'>
array=<Array [(??, ??)] type='1 * (bytes, union[timedelta64[M], bytes])'>
array=<Array [??, ??, ??, ??, ??] type='5 * var * var * (uint64, bytes)'>

The current version generates arrays with NumpyArray, EmptyArray, string, and bytestring as leaf contents that can be nested multiple levels deep in RegularArray, ListOffsetArray, ListArray, RecordArray, and UnionArray. Arrays might be virtual, shown as ?? in the output.

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:

Project details


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.8.0.tar.gz (128.9 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.8.0-py3-none-any.whl (39.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hypothesis_awkward-0.8.0.tar.gz
  • Upload date:
  • Size: 128.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for hypothesis_awkward-0.8.0.tar.gz
Algorithm Hash digest
SHA256 3b3108a4a8754be44c7c6be4d62f08fcc516525bb210b987e761c1e9c0d795d8
MD5 91f556c7ce369b864651ddf83d08103e
BLAKE2b-256 59903bb812fa50463d3cdc02ed3ae57c4cf9b1908d71b31c4498ea84625cb2a8

See more details on using hashes here.

Provenance

The following attestation bundles were made for hypothesis_awkward-0.8.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.8.0-py3-none-any.whl.

File metadata

File hashes

Hashes for hypothesis_awkward-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0fa68fce673e851bbaf0ee6597df457341e2b32626b568d7658eecc8b5a5c7f
MD5 60a2f10b26d135ca9165129bdfca883b
BLAKE2b-256 ce9058a375c64a598b01f08c8c456b1ef80886775f7a075a0eba4cf6ae8df8ec

See more details on using hashes here.

Provenance

The following attestation bundles were made for hypothesis_awkward-0.8.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.

Supported by

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