Schema validation for Xarray objects
Project description
About the project
Xarrera is an open source project that provides an API for performing data-format validation on Xarray objects.
Getting Started
Prerequisites
- Python >= 3.9
Installation
Install Xarrera from PyPI:
pip install xarrera
Conda:
conda install -c conda-forge xarrera
Or install it from source:
pip install git+https://github.com/javgat/xarrera
Another option is cloning the repository and installing the python package and its dependencies by using:
git clone https://github.com/javgat/xarrera.git
cd xarrera
pip install -e .
Usage
Xarrera'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 xarrera 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 xarrera.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 = ChunksSchema({'x': None, 'y': -1}) # None is used as a wildcard, -1 is used as
ArrayTypeSchema = ArrayTypeSchema(np.ndarray)
# Example usage
dtype_schema.validate(da.dtype)
# Each object schema can be exported to JSON format
dtype_json = dtype_schema.to_json()
Roadmap
This is a very early prototype of a library, based on a library with multiple forks with small additions. The following key things to do are:
- Include features implemented on existing
xarray-schemaforks. - Include changes proposed in
xarray-schemaissues board. - Include features proposed in
xarray-schemaissues board into the Roadmap. - Contact former
xarray-schemadevelopers, forkers, and issue writers aboutxarrera. - ...
- Accumulate schema exceptions and report them all at once.
Currently, we are a eagerly raising
SchemaErrorswhen the are found.
Versioning
Version changes and descriptions are stored in the CHANGELOG. This file is updated each time a new version is released.
Contributing
Development Guide
-
Install npm (required for pre-commit hooks)
Some pre-commit hooks (e.g., for formatting or linting) depend on Node.js and npm. You can install them via your system package manager, or download from nodejs.org (npm is included).
For example, on Debian/Ubuntu:
sudo apt update sudo apt install nodejs npm
If you use conda, you can also install it with:
conda install -c conda-forge nodejs
-
Install Pre-commit Hooks
Install the
pre-commithooks to automatically check code styling:pre-commit install -
Install Python Dependencies
Install the python package dependencies listed in the
requirements.txtfile, preferably in a python virtual enironment:pip install -r requirements.txt # or pip install -e .
Testing
-
Install test dependencies
Install de development dependencies with:
pip install -r dev-requirements.txt # or pip install -e ".[dev]"
-
Run the style check
Run the
mypystyle check with:mypy xarrera tests
-
Run the tests
Run the tests with:
pytest
Generate the coverage with
pytest --cov=./ --cov-report=xml --verbose
License
All the code in this repository is MIT licensed.
History
This project was originally developed at CarbonPlan. It was transferred to the xarray-contrib organization in August 2022.
Due to the inactivity in xarray-contrib, it was forked to Xarrera in March 2026.
Authors
- Javier Gatón Herguedas - Maintainer - gaton@goa.uva.es
- Joe Hamman - Initial Work - joe@carbonplan.org - CarbonPlan
- Anderson Banihirwe - Initial Work - anderson@carbonplan.org - CarbonPlan
- Oriana Chegwidden - Initial Work - CarbonPlan
- Peter A. I. Forsyth - Initial Work
- Raphael Hagen - Initial Work - raphael@carbonplan.org - CarbonPlan
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file xarrera-0.0.4.tar.gz.
File metadata
- Download URL: xarrera-0.0.4.tar.gz
- Upload date:
- Size: 25.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a9f164ad2feb64d2fb321fa058de2a0f0b8d836c3066e206a96e225be205ba6d
|
|
| MD5 |
6feff3575f675a0521aa11c36fcd4bd9
|
|
| BLAKE2b-256 |
b4f3908dfb1da2ea4dd2eb512062cbe46362725c8088b7094338585f4daf947b
|
File details
Details for the file xarrera-0.0.4-py3-none-any.whl.
File metadata
- Download URL: xarrera-0.0.4-py3-none-any.whl
- Upload date:
- Size: 13.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42e29239f16224c8d19c5374e7d50c5adb146046f54bca099431cb6bc3b933b7
|
|
| MD5 |
b2144df43a9930af3e9bdc8ea869339f
|
|
| BLAKE2b-256 |
c472ff88e1e8d6bad1a951f550d16f81a690e30d3869b2ad9a5b75285cfe731a
|