Skip to content

Builtins

Strategies for built-in Python objects in the context of Awkward Array.

These strategies are related to the section of Awkward Array User Guide "How to convert to/from Python objects".

Functions:

Name Description
builtin_safe_dtypes

Strategy for NumPy dtypes with corresponding Python built-in types.

items_from_dtype

Strategy for Python built-in type values for a given NumPy dtype.

lists

Strategy for nested Python lists for which Awkward Arrays can be created.

from_list

Strategy for Awkward Arrays created from Python lists.

builtin_safe_dtypes

builtin_safe_dtypes() -> st.SearchStrategy[np.dtype]

Strategy for NumPy dtypes with corresponding Python built-in types.

Examples:

>>> builtin_safe_dtypes().example()
dtype(...)

items_from_dtype

items_from_dtype(
    dtype: dtype, *, allow_nan: bool = True
) -> st.SearchStrategy[Any]

Strategy for Python built-in type values for a given NumPy dtype.

Parameters:

Name Type Description Default
dtype dtype

The NumPy dtype to generate items for.

required
allow_nan bool

Generate potentially NaN for relevant dtypes if True.

True

Examples:

>>> i = items_from_dtype(np.dtype('int64')).example()
>>> isinstance(i, int)
True

lists

lists(
    draw: DrawFn,
    *,
    dtype: dtype | SearchStrategy[dtype] | None = None,
    allow_nan: bool = True,
    max_size: int = 10,
) -> NestedList

Strategy for nested Python lists for which Awkward Arrays can be created.

Parameters:

Name Type Description Default
dtype dtype | SearchStrategy[dtype] | None

The dtype of the list items or a strategy to generate it. If None, a dtype is drawn from builtin_safe_dtypes().

None
allow_nan bool

Generate potentially NaN for relevant dtypes if True.

True
max_size int

Maximum total number of items (non-lists) in the entire nested list.

10

Examples:

>>> l = lists().example()
>>> ak.Array(l)
<Array ... type='...'>

from_list

from_list(
    *,
    dtype: dtype | SearchStrategy[dtype] | None = None,
    allow_nan: bool = True,
    max_size: int = 10,
) -> st.SearchStrategy[ak.Array]

Strategy for Awkward Arrays created from Python lists.

Parameters:

Name Type Description Default
dtype dtype | SearchStrategy[dtype] | None

The dtype of the list items or a strategy to generate it. If None, a dtype is drawn from builtin_safe_dtypes().

None
allow_nan bool

Generate potentially NaN for relevant dtypes if True.

True
max_size int

Maximum total number of items (non-lists) in the entire nested list.

10

Examples:

>>> from_list().example()
<Array ... type='...'>