Skip to main content

pytest-regressions plugin for xarray

Project description

PyPI version Build status

A pytest-regressions plugin for identifying regressions in Xarray objects.

[!WARNING] xarray-regressions is in early development and might have breaking changes.

Install

pip install xarray-regressions

Usage

[!TIP] If you're unfamiliar with pytest-regressions, check out their documentation first.

Once installed, this package registers a test fixture xarray_regression for detecting regressions in the data or metadata of xr.DataArray and xr.Dataset objects.

Say you have a function make_dataarray that should always return the same output:

import xarray as xr

def make_dataarray(name: str) -> xr.DataArray:
    """A dummy method that needs to be tested."""
    return xr.DataArray(
        np.full((2, 4, 3), 1),
        dims=["variable", "y", "x"],
        coords={
            "variable": ["var1", "var2"],
            "y": [1, 2, 3, 4],
            "x": [1, 2, 3],
        },
        name=name,
        attrs={"foo": "bar"},
    )

Add the xarray_regression fixture to a new test and call the check method on the returned data array:

from xarray_regressions import XarrayRegressionFixture # Only used for type annotation

def test_make_dataarray(xarray_regression: XarrayRegressionFixture):
    """Test that the function always returns an identical xr.DataArray."""
    da = make_dataarray(name="test_array")
    xarray_regression.check(
        da,
        check_names=True,
        check_attrs=True,
    )

Running the test once will write da to a local NetCDF[^netcdf], and future test runs will compare da with the stored result. Values, dimensions, and coordinates are checked using xr.testing.assert_equal or xr.testing.assert_allclose (if atol or rtol are given). Names and attributes are checked seperately. Encodings are not currently checked.

If make_dataarray(name="test_array") returns a different result in the future, the test will fail:

AssertionError: DataArray names are different. L: foo, R: test_array

[^netcdf]: Because results are stored in NetCDF, all tested objects must be serializable.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xarray_regressions-0.0.2.tar.gz (44.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

xarray_regressions-0.0.2-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file xarray_regressions-0.0.2.tar.gz.

File metadata

  • Download URL: xarray_regressions-0.0.2.tar.gz
  • Upload date:
  • Size: 44.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for xarray_regressions-0.0.2.tar.gz
Algorithm Hash digest
SHA256 8c6d2c8c5f70d8115c2b612878e9f7c9b9318e8954a569fff372e2a833cca00c
MD5 c7341a39d56c6d69e8ef7fff8c4ed589
BLAKE2b-256 7cbfd9569f5ab45d02f750e262098dffc2e9ae8dd9ede8e14ace357c2dffad8a

See more details on using hashes here.

Provenance

The following attestation bundles were made for xarray_regressions-0.0.2.tar.gz:

Publisher: publish.yaml on aazuspan/xarray-regressions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file xarray_regressions-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for xarray_regressions-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 9b885499a48f0b2f4660f8c99bb20bf324e10a7549c8c07c8aa9dab018dae0a9
MD5 fb0876ece1fccf0a695369e8ca9c7e5d
BLAKE2b-256 6052fd09dda2118d4aa732b66722df39edb578046d10ef04f793864fb75d93ea

See more details on using hashes here.

Provenance

The following attestation bundles were made for xarray_regressions-0.0.2-py3-none-any.whl:

Publisher: publish.yaml on aazuspan/xarray-regressions

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page