def fixed_coords_datasets()

in hypothesis_gufunc/extra/xr.py [0:0]


def fixed_coords_datasets(vars_to_dims, coords, dtype=None, elements=None):
    """Generate a :class:`xarray:xarray.Dataset` where the variables, dimensions, and coordinates are specified a-priori.

    Parameters
    ----------
    vars_to_dims : dict(typing.Hashable, list(str))
        Mapping of variable names to list of dimensions, which can be fed to constructor for a
        :class:`xarray:xarray.Dataset`.
    coords : dict(str, list)
        Dictionary mapping dimension name to its coordinate values.
    dtype : dict(typing.Hashable, type) or None
        Dictionary mapping variables names to the data type for that variable's elements.
    elements : SearchStrategy or None
        Strategy to fill the elements of the :class:`xarray:xarray.Dataset`. If `None`, a default is selected based on
        `dtype`.

    Returns
    -------
    ds : :class:`xarray:xarray.Dataset`
        :class:`xarray:xarray.Dataset` with the specified variables, dimensions, and coordinates.
    """
    if dtype is None:
        dtype = defaultdict(lambda: DEFAULT_DTYPE)

    C = OrderedDict([(vv, fixed_coords_dataarrays(dd, coords, dtype[vv], elements)) for vv, dd in vars_to_dims.items()])
    data_st = fixed_dictionaries(C)
    S = data_st.map(lambda data: xr.Dataset(data, coords=coords))
    return S