Skip to main content

xarray extension for data comparison

Project description

xarray-compare

PyPI Python Test License DOI

xarray extension for data comparison

TL;DR

xarray-compare is a third-party Python package which provides extra data-comparison features. After importing the package, several DataArray methods (dataarray.is*()) will be available.

Requirements

  • Python: 3.6, 3.7, or 3.8 (tested by the author)
  • Dependencies: See pyproject.toml

Installation

$ pip install xarray-compare

List of available methods

  • .isbetween(lower, upper): Test whether each value in a DataArray falls within an interval
  • .ismatch(pattern): Test whether each string in a DataArray matches a regex pattern

Methods of "not-in" version are also provided for readability.

  • .isnotin(values): Equivalent to ~dataarray.isin(values) (.isin() is an xarray's builtin)
  • .isnotbetween(lower, upper): Equivalent to ~dataarray.isbetween(lower, upper)
  • .isnotmatch(pattern): Equivalent to ~dataarray.ismatch(pattern)

Examples

xarray-compare is a just-import package. After importing it, methods become available from normal DataArray instances.

import xarray as xr
import xarray_compare

A method returns a boolean DataArray each value of which is True where that of the input DataArray fulfills the condition and False otherwise. This is why it works well with the dataarray.where() method.

da = xr.DataArray([0, 1, 1, 2, 3, 5, 8, 13])
da.where(da.isbetween(1, 4), drop=True)

# <xarray.DataArray (dim_0: 4)>
# array([1., 1., 2., 3.])
# Dimensions without coordinates: dim_0
da = xr.DataArray(['a', 'aa', 'ab', 'bc'])
da.where(da.ismatch("^a+$"), drop=True)

# <xarray.DataArray (dim_0: 2)>
# array(['a', 'aa'], dtype=object)
# Dimensions without coordinates: dim_0

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-compare-0.2.0.tar.gz (4.8 kB view hashes)

Uploaded Source

Built Distribution

xarray_compare-0.2.0-py3-none-any.whl (5.2 kB view hashes)

Uploaded Python 3

Supported by

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