xarray-schema
Schema validation for Xarray
installation
Install xarray-schema from PyPI:
pip install xarray-schema
Conda:
conda install -c conda-forge xarray-schema
Or install it from source:
pip install git+https://github.com/carbonplan/xarray-schema
usage
Xarray-schema's API is modeled after Pandera. The DataArraySchema and DatasetSchema objects both have .validate() methods.
The basic usage is as follows:
import numpy as np
import xarray as xr
from xarray_schema import DataArraySchema, DatasetSchema, CoordsSchema
da = xr.DataArray(np.ones(4, dtype='i4'), dims=['x'], name='foo')
schema = DataArraySchema(dtype=np.integer, name='foo', shape=(4, ), dims=['x'])
schema.validate(da)
You can also use it to validate a Dataset like so:
schema_ds = DatasetSchema({'foo': schema})
schema_ds.validate(da.to_dataset())
Each component of the Xarray data model is implemented as a stand alone class:
from xarray_schema.components import (
DTypeSchema,
DimsSchema,
ShapeSchema,
NameSchema,
ChunksSchema,
ArrayTypeSchema,
AttrSchema,
AttrsSchema
)
# example constructions
dtype_schema = DTypeSchema('i4')
dims_schema = DimsSchema(('x', 'y', None)) # None is used as a wildcard
shape_schema = ShapeSchema((5, 10, None)) # None is used as a wildcard
name_schema = NameSchema('foo')
chunk_schema = ChunkSchema({'x': None, 'y': -1}) # None is used as a wildcard, -1 is used as
ArrayTypeSchema = ArrayTypeSchema(np.ndarray)
# Example usage
dtype_schama.validate(da.dtype)
# Each object schema can be exported to JSON format
dtype_json = dtype_schama.to_json()
roadmap
This is a very early prototype of a library. Some key things are missing:
- Validation of
coordsandattrs. These are not implemented yet. - Exceptions: Pandera accumulates schema exceptions and reports them all at once. Currently, we are a eagerly raising
SchemaErrorswhen the are found. - Roundtrip schemas to/from JSON and/or YAML format.
license
All the code in this repository is MIT licensed, but we request that you please provide attribution if reusing any of our digital content (graphics, logo, articles, etc.).
about us
CarbonPlan is a non-profit organization that uses data and science for climate action. We aim to improve the transparency and scientific integrity of climate solutions through open data and tools. Find out more at carbonplan.org or get in touch by opening an issue or sending us an email.
Metadata
Release files for xarray-schema 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| xarray-schema-0.0.3.tar.gz | 15.0 kB | Without provenance | Details for xarray-schema-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| xarray_schema-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for xarray_schema-0.0.3-py3-none-any.whl |
Total release size: 25.0 kB
Release files / xarray-schema-0.0.3.tar.gz
| Download URL | xarray-schema-0.0.3.tar.gz |
|---|---|
| Size | 15.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9c6c760489c0690a70394b2ad1368b32f8fa1333911c361b4adf249384212920
|
|
BLAKE2b-256 checksum How to use checksums |
643de0652fad05696e34897f085d4c3115dc4bedb1fb8c1827d6c79ce74095a6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Release files / xarray_schema-0.0.3-py3-none-any.whl
| Download URL | xarray_schema-0.0.3-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa6f856626b2e100213ba290407797464608b2555bb8e0b26093a97fe1ba38ce
|
|
BLAKE2b-256 checksum How to use checksums |
a96df585a27b380ee987619b5617c0ca672a71a4345b67cfedbb6299750ce845
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.0 CPython/3.9.12
|
Security for xarray-schema 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.