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 fail in pytest or other testing frameworks. Once a test fails, Hypothesis searches for the simplest sample that causes the same error. Hypothesis automatically explores edge cases; you do not need to come up with test data manually.
Hypothesis itself includes strategies for NumPy and pandas data types. Xarray provides strategies for its data structure. The Apache Arrow codebase has strategies for PyArrow, which are not officially documented in its API reference.
I am putting together Hypothesis strategies that I developed for Awkward Array in this package. This is very 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.
A simple example
The strategy from_numpy generates Awkward Arrays that are converted from NumPy
arrays. (Internally, it first generates NumPy arrays that can be converted to
Awkward Arrays, then converts them with ak.from_numpy.)
The test below converts the generated Awkward Array back to a NumPy array with
to_numpy and asserts that the list representations of both arrays are equal.
from hypothesis import given
import awkward as ak
import hypothesis_awkward.strategies as st_ak
@given(ak_array=st_ak.from_numpy(allow_structured=False))
def test_array(ak_array: ak.Array) -> None:
np_array = ak_array.to_numpy()
assert ak_array.to_list() == np_array.tolist()
Strategies
So far, I have written strategies based on the first two sections of the Awkward Array User Guide: "How to convert to/from NumPy" and "How to convert to/from Python objects".
NumPy
These strategies are related to the section "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 Arrays |
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 "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 |
Perspective
The strategies that I developed so far only generate samples with certain types of layouts. It is probably possible to build strategies that generate fully general Awkward Arrays with the array builder and direct constructions, which would be useful for closing all edge cases in developing tools that use Awkward Array and even Awkward Array itself.
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.0.5.tar.gz.
File metadata
- Download URL: hypothesis_awkward-0.0.5.tar.gz
- Upload date:
- Size: 18.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8765c94577b3c8384a4fa566e7dc42c144da0f97e4cd6b4decad5bd20d8a32d5
|
|
| MD5 |
7103edf89a4e99c3123ededcf813678a
|
|
| BLAKE2b-256 |
9841b378afd41633ad85ec942495d1814a1f64d9a85f0dc97fedd5457d5cb37f
|
Provenance
The following attestation bundles were made for hypothesis_awkward-0.0.5.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.0.5.tar.gz -
Subject digest:
8765c94577b3c8384a4fa566e7dc42c144da0f97e4cd6b4decad5bd20d8a32d5 - Sigstore transparency entry: 741941974
- Sigstore integration time:
-
Permalink:
TaiSakuma/hypothesis-awkward@17b8a9db4fa574e180b14830abdd706af162697e -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/TaiSakuma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@17b8a9db4fa574e180b14830abdd706af162697e -
Trigger Event:
push
-
Statement type:
File details
Details for the file hypothesis_awkward-0.0.5-py3-none-any.whl.
File metadata
- Download URL: hypothesis_awkward-0.0.5-py3-none-any.whl
- Upload date:
- Size: 16.4 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 |
68b4f94842645e6e73c04e170aa785737c883c9a4b9364ef194dab1f92aa3f84
|
|
| MD5 |
bf80cbf6ae2af13d2d24d6e2892fa479
|
|
| BLAKE2b-256 |
afc8f183381a3a648a844a0c78cc3f89084cbbc3f596c34b94b03cd3868c2e65
|
Provenance
The following attestation bundles were made for hypothesis_awkward-0.0.5-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.0.5-py3-none-any.whl -
Subject digest:
68b4f94842645e6e73c04e170aa785737c883c9a4b9364ef194dab1f92aa3f84 - Sigstore transparency entry: 741941984
- Sigstore integration time:
-
Permalink:
TaiSakuma/hypothesis-awkward@17b8a9db4fa574e180b14830abdd706af162697e -
Branch / Tag:
refs/tags/v0.0.5 - Owner: https://github.com/TaiSakuma
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi.yml@17b8a9db4fa574e180b14830abdd706af162697e -
Trigger Event:
push
-
Statement type: