Skip to content

Create hypothesis.extra.xarray #3948

@raybellwaves

Description

@raybellwaves

I use hypothesis.extra.pandas for creation of pandas.DataFrame. e.g. https://hypothesis.readthedocs.io/en/latest/numpy.html#hypothesis.extra.pandas.data_frames

from hypothesis.extra.pandas import column, data_frames
df = data_frames([column("A", dtype=int), column("B", dtype=float)]).example()

I would be great to have something similar for xarray. I'm not sure what the API would look like but here is a mock up

from hypothesis.extra.xarray import data_array, data_set
ds = data_set(
    [
        data_array("A", shape=(2, 2), dtype=int),
        data_array("B", shape=(2, 2), dtype=float),
    ]
).example()

which could wrap the numpy functions

import xarray as xr
from hypothesis.extra.numpy import arrays
xr.Dataset(
    {
        "A": xr.DataArray(arrays(dtype=int, shape=(2, 2)).example()),
        "B": xr.DataArray(arrays(dtype=float, shape=(2, 2)).example()),
    }
)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions