Hypothesis strategies for Awkward Array
Project description
hypothesis-awkward
Hypothesis strategies for Awkward Arrays.
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 [-9223372036854724544 milliseconds] type='1 * timedelta64[ms]'>
array=<Array [[9.01e+15+infj], [-6.1e-05+1.23e+176j]] type='2 * 1 * complex128'>
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='3 * uint32'>
array=<Array [[[b'6'], [b'\xe6sW\xbf'], []]] type='1 * 3 * var * bytes'>
array=<Array [[[], []], [[]], [], []] type='5 * var * var * 4 * unknown'>
array=<Array [] type='0 * unknown'>
array=<Array [[??], []] type='2 * var * var * bytes'>
array=<Array [[], [], [], [], []] type='5 * var * unknown'>
array=<Array [[[]], [[]], [[]]] type='3 * 1 * 0 * unknown'>
array=<Array [[[], []]] type='1 * var * var * var * timedelta64[ms]'>
array=<Array [[[[[[]]]]], [[[[[]]]]]] type='2 * 1 * 1 * 1 * 1 * var * unknown'>
The current version generates arrays with NumpyArray, EmptyArray, string,
and bytestring as leaf contents that can be nested multiple levels deep in
RegularArray, ListOffsetArray, and ListArray lists. Arrays might be
virtual, shown as ?? in the output.
The API of arrays()
def arrays(
*,
dtypes: st.SearchStrategy[np.dtype] | None = None,
max_size: int = 10,
allow_nan: bool = False,
allow_numpy: bool = True,
allow_empty: bool = True,
allow_string: bool = True,
allow_bytestring: bool = True,
allow_regular: bool = True,
allow_list_offset: bool = True,
allow_list: bool = True,
max_depth: int = 5,
allow_virtual: bool = True,
):
| Parameter | Description |
|---|---|
dtypes |
A strategy for NumPy scalar dtypes used in NumpyArray. If None, the default strategy that generates any scalar dtype supported by Awkward Array is used. Does not affect string or bytestring content. |
max_size |
Maximum total number of elements in the generated array. Each numerical value counts as one. Each string and bytestring (not character or byte) counts as one. |
allow_nan |
No NaN/NaT values are generated if False. |
allow_numpy |
No NumpyArray is generated if False. |
allow_empty |
No EmptyArray is generated if False. |
allow_string |
No string content is generated if False. Each string (not character) counts toward max_size. String layers do not count toward max_depth. Unaffected by dtypes and allow_nan. |
allow_bytestring |
No bytestring content is generated if False. Each bytestring (not byte) counts toward max_size. Bytestring layers do not count toward max_depth. Unaffected by dtypes and allow_nan. |
allow_regular |
No RegularArray is generated if False. |
allow_list_offset |
No ListOffsetArray is generated if False. |
allow_list |
No ListArray is generated if False. |
max_depth |
Maximum nesting depth. Each RegularArray, ListOffsetArray, and ListArray layer adds one level, excluding those that form string or bytestring content. |
allow_virtual |
No virtual arrays are generated if False. |
Other strategies
In addition to arrays() mentioned above, this package includes other
strategies that generate Awkward Arrays and related data types.
NumPy
These strategies are related to the section of Awkward Array User Guide "How to convert to/from NumPy".
| Strategy | Data type |
|---|---|
from_numpy |
Awkward Arrays created from NumPy arrays |
numpy_arrays |
NumPy arrays that can be converted to Awkward Array |
numpy_dtypes |
NumPy dtypes (simple or array) supported by Awkward Array |
supported_dtypes |
NumPy dtypes (simple only) supported by Awkward Array |
supported_dtype_names |
Names of NumPy dtypes (simple only) supported by Awkward Array |
Python lists
These strategies are related to the section of Awkward Array User Guide "How to convert to/from Python objects".
| Strategy | Data type |
|---|---|
from_list |
Awkward Arrays created from Python lists |
lists |
Nested Python lists for which Awkward Arrays can be created |
items_from_dtype |
Python built-in type values for a given NumPy dtype |
builtin_safe_dtypes |
NumPy dtypes with corresponding Python built-in types |
builtin_safe_dtype_names |
Names of NumPy dtypes with corresponding Python built-in types |
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file hypothesis_awkward-0.4.0.tar.gz.
File metadata
- Download URL: hypothesis_awkward-0.4.0.tar.gz
- Upload date:
- Size: 91.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b64931c7e8be8601056aee7b9d5f747eb624cf7f7733f8dddfab8ba02f94281c
|
|
| MD5 |
e92b4ad697f3ff1fcbaf20200400e936
|
|
| BLAKE2b-256 |
d011e402e98c9130ba3a8c2bc3d4ff356abf0daa6df6eef8e1b30f0e4ad5fcd9
|
Provenance
The following attestation bundles were made for hypothesis_awkward-0.4.0.tar.gz:
Publisher:
pypi.yml on TaiSakuma/hypothesis-awkward
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hypothesis_awkward-0.4.0.tar.gz -
Subject digest:
b64931c7e8be8601056aee7b9d5f747eb624cf7f7733f8dddfab8ba02f94281c - Sigstore transparency entry: 956658531
- Sigstore integration time:
-
Permalink:
TaiSakuma/hypothesis-awkward@63131385a0e5e84d5da54ec3b5b68bd86d520fea -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/TaiSakuma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@63131385a0e5e84d5da54ec3b5b68bd86d520fea -
Trigger Event:
push
-
Statement type:
File details
Details for the file hypothesis_awkward-0.4.0-py3-none-any.whl.
File metadata
- Download URL: hypothesis_awkward-0.4.0-py3-none-any.whl
- Upload date:
- Size: 33.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b0b8c829c57966ef7d127a53f86a947b5527a49ebb2a914125112e7b7d7a4135
|
|
| MD5 |
79a17f2c5789540813b64ec60d0f2da7
|
|
| BLAKE2b-256 |
b07d6866bb10fe445440d66a87dd28545197d62eaabb948b773bbb73b379af12
|
Provenance
The following attestation bundles were made for hypothesis_awkward-0.4.0-py3-none-any.whl:
Publisher:
pypi.yml on TaiSakuma/hypothesis-awkward
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
hypothesis_awkward-0.4.0-py3-none-any.whl -
Subject digest:
b0b8c829c57966ef7d127a53f86a947b5527a49ebb2a914125112e7b7d7a4135 - Sigstore transparency entry: 956658617
- Sigstore integration time:
-
Permalink:
TaiSakuma/hypothesis-awkward@63131385a0e5e84d5da54ec3b5b68bd86d520fea -
Branch / Tag:
refs/tags/v0.4.0 - Owner: https://github.com/TaiSakuma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@63131385a0e5e84d5da54ec3b5b68bd86d520fea -
Trigger Event:
push
-
Statement type: