Skip to content

core

ensure_member_name #

ensure_member_name(data)

If the input is a string, then ensure that it is a valid name for a subnode in a zarr group

Source code in src/pydantic_zarr/core.py
def ensure_member_name(data: Any) -> str:
    """
    If the input is a string, then ensure that it is a valid
    name for a subnode in a zarr group
    """
    if isinstance(data, str):
        if "/" in data:
            raise ValueError(
                f'Strings containing "/" are invalid. Got {data}, which violates this rule.'
            )
        if data in ("", ".", ".."):
            raise ValueError(f"The string {data} is not a valid member name.")
        return data
    raise TypeError(f"Exected a str, got {type(data)}.")

model_like #

model_like(a, b, exclude=None, include=None)

A similarity check for a pair pydantic.BaseModel, parametrized over included or excluded fields.

Source code in src/pydantic_zarr/core.py
def model_like(
    a: BaseModel, b: BaseModel, exclude: IncEx = None, include: IncEx = None
) -> bool:
    """
    A similarity check for a pair pydantic.BaseModel, parametrized over included or excluded fields.


    """

    a_dict = a.model_dump(exclude=exclude, include=include)
    b_dict = b.model_dump(exclude=exclude, include=include)

    return a_dict == b_dict