skillfed

pint-xarray

Physical units interface to xarray using Pint

pint-xarray v0.6.1 113.3K downloads/30d#12,347 on PyPI119
Permissive license Apache-2.0 Active released

What it is and what it does

pint-xarray bridges Pint's physical units library with xarray's labeled multidimensional arrays, letting you attach and track units on dataset variables and perform unit-aware arithmetic and conversions. It works by registering accessor methods on xarray objects, so you call `.pint.quantify()` to add units, `.pint.to()` to convert between units, and `.pint.dequantify()` to strip units back off.

The package is designed for scientific and engineering workflows where dimensional consistency matters—tracking whether a measurement is in meters or kilometers, seconds or milliseconds—and catching unit mismatches before they propagate through calculations. It integrates directly with xarray's data model, so units stay attached to variables as you slice, combine, or transform datasets.

Use it for:

  • Attach units to climate or weather model output and convert between unit systems for analysis.
  • Track physical dimensions through geophysical data processing pipelines to catch unit errors early.
  • Perform dimensional analysis on scientific datasets to ensure unit consistency across operations.
  • Convert measurement data from one unit system to another while preserving xarray's labeled structure.
  • Build unit-aware data pipelines for physics or engineering simulations using xarray as the data container.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Adds physical units support to xarray datasets and data variables using Pint, enabling unit-aware arithmetic and conversions on multidimensional labeled arrays.

Yes. The package is actively maintained, has no known vulnerabilities, installs with low friction, and fills a genuine gap for scientists and engineers working with xarray who need physical units. The Apache-2.0 license is permissive. Start with it if you're already using xarray and need dimensional tracking; the API is straightforward and the dependency footprint is small.

Install

pint-xarray on PyPI

pip

pip install pint-xarray

uv

uv add pint-xarray

poetry

poetry add pint-xarray

Installing pint-xarray

Before you install

Low friction installation with a pure-Python wheel. Actively maintained as of 2026-08-14 with recent releases; depends on three well-established packages (xarray, numpy, pint) that are standard in scientific Python.

License in practice

Apache-2.0 permissive license allows commercial and private use with minimal restrictions, making it safe for most projects.

Quickstart

pip install pint-xarray

import pint_xarray
import xarray as xr

ds = xr.Dataset({"a": ("x", [0, 1, 2]), "b": ("y", [-3, 5, 1], {"units": "m"})})
q = ds.pint.quantify(a="s")
c = q.pint.to({"a": "ms", "b": "km"})

Requires Python 3.11 or later.

Verify before relying

  • Whether unit-aware operations preserve xarray's lazy evaluation and chunking (Dask integration).
  • Performance impact of unit tracking on large multidimensional arrays.
  • Compatibility with xarray's groupby, resample, and other high-level operations when units are attached.

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (>=3.11)
Install friction low — pure-Python wheel
Runtime dependencies 3 — xarray, numpy, pint
Maintenance actively maintained — 144 days since the last release
Last repo commit
First released
Downloads 113,278/month — #12,347 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: pint_xarray-0.6.1-py3-none-any.whl

Development Status :: 3 - AlphaEnvironment :: ConsoleIntended Audience :: Science/ResearchOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Scientific/Engineering

Tags

xarray unitspint xarray integrationphysical units for arraysunit conversion xarraydimensional analysis xarrayquantity arraysscientific data units
units-and-quantitiesscientific-computingdata-validation

More Scientific/Engineering packages