xarray-contrib/xarray-schema

Forbid internally inconsistent schemas

paiforsyth opened this issue · 0 comments

A key feature of xarray.Dataset is that all dimensions of the same name must have the same sizes across DataArrays. For this reason, a Dataset schema that requires different sizes for dimensions of the same name will never match any Datasets. I suggest that it should be an an error to construct such a schema. This would allow early detection of such erroneous schemas.

So with this feature, the following test would pass:

def test_forbid_internally_inconsistent_schema():
    with pytest.raises(Exception):
        schema =DatasetSchema(
            data_vars={
                "v1":DataArraySchema(shape=ShapeSchema((2,)), dims=("dim_1",)),
                "v2": DataArraySchema(shape=ShapeSchema((3,)), dims=("dim_1",)),
            }