Repository: rayference/ussa1976 (language: python)

Issue:
Remove obsolete `units` module



Discussion / hints:

Fix patch:
diff --git a/poetry.lock b/poetry.lock
index 544f9f6..4164ef1 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -108,7 +108,7 @@ tests_no_zope = ["coverage[toml] (>=5.0.2)", "hypothesis", "pympler", "pytest (>
 
 [[package]]
 name = "babel"
-version = "2.10.1"
+version = "2.10.2"
 description = "Internationalization utilities"
 category = "dev"
 optional = false
@@ -1216,19 +1216,6 @@ python-versions = ">=3.7"
 docs = ["olefile", "sphinx (>=2.4)", "sphinx-copybutton", "sphinx-issues (>=3.0.1)", "sphinx-removed-in", "sphinx-rtd-theme (>=1.0)", "sphinxext-opengraph"]
 tests = ["check-manifest", "coverage", "defusedxml", "markdown2", "olefile", "packaging", "pyroma", "pytest", "pytest-cov", "pytest-timeout"]
 
-[[package]]
-name = "pint"
-version = "0.19.2"
-description = "Physical quantities module"
-category = "main"
-optional = false
-python-versions = ">=3.8"
-
-[package.extras]
-numpy = ["numpy (>=1.19.5)"]
-test = ["pytest", "pytest-mpl", "pytest-cov", "pytest-subtests"]
-uncertainties = ["uncertainties (>=3.1.6)"]
-
 [[package]]
 name = "platformdirs"
 version = "2.5.2"
@@ -2056,7 +2043,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest-
 [metadata]
 lock-version = "1.1"
 python-versions = ">=3.8,<3.10"
-content-hash = "e3948328570a489395e2373c790802df94b19efc346041ea85ee0e2fc4e2bcd1"
+content-hash = "aa3c356af01398940c9dde3c8ee574780f300cd654f2d8dfc2e380a03f44596e"
 
 [metadata.files]
 alabaster = [
@@ -2115,8 +2102,8 @@ attrs = [
     {file = "attrs-21.4.0.tar.gz", hash = "sha256:626ba8234211db98e869df76230a137c4c40a12d72445c45d5f5b716f076e2fd"},
 ]
 babel = [
-    {file = "Babel-2.10.1-py3-none-any.whl", hash = "sha256:3f349e85ad3154559ac4930c3918247d319f21910d5ce4b25d439ed8693b98d2"},
-    {file = "Babel-2.10.1.tar.gz", hash = "sha256:98aeaca086133efb3e1e2aad0396987490c8425929ddbcfe0550184fdc54cd13"},
+    {file = "Babel-2.10.2-py3-none-any.whl", hash = "sha256:81a3beca4d0cd40a9cfb9e2adb2cf39261c2f959b92e7a74750befe5d79afd7b"},
+    {file = "Babel-2.10.2.tar.gz", hash = "sha256:7aed055f0c04c9e7f51a2f75261e41e1c804efa724cb65b60a970dd4448d469d"},
 ]
 backcall = [
     {file = "backcall-0.2.0-py2.py3-none-any.whl", hash = "sha256:fbbce6a29f263178a1f7915c1940bde0ec2b2a967566fe1c65c1dfb7422bd255"},
@@ -2838,9 +2825,6 @@ pillow = [
     {file = "Pillow-9.1.1-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:baf3be0b9446a4083cc0c5bb9f9c964034be5374b5bc09757be89f5d2fa247b8"},
     {file = "Pillow-9.1.1.tar.gz", hash = "sha256:7502539939b53d7565f3d11d87c78e7ec900d3c72945d4ee0e2f250d598309a0"},
 ]
-pint = [
-    {file = "Pint-0.19.2.tar.gz", hash = "sha256:e1d4989ff510b378dad64f91711e7bdabe5ca78d75b06a18569ac454678c4baf"},
-]
 platformdirs = [
     {file = "platformdirs-2.5.2-py3-none-any.whl", hash = "sha256:027d8e83a2d7de06bbac4e5ef7e023c02b863d7ea5d079477e722bb41ab25788"},
     {file = "platformdirs-2.5.2.tar.gz", hash = "sha256:58c8abb07dcb441e6ee4b11d8df0ac856038f944ab98b7be6b27b2a3c7feef19"},
diff --git a/pyproject.toml b/pyproject.toml
index b069e87..2ca96b1 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -17,7 +17,6 @@ version = "0.2.0"
 Changelog = "https://github.com/nollety/ussa1976/releases"
 
 [tool.poetry.dependencies]
-Pint = ">=0.17"
 click = ">=7.0"
 netCDF4 = ">=1.5.7"
 numpy = ">=1.22"
diff --git a/src/ussa1976/units.py b/src/ussa1976/units.py
deleted file mode 100644
index 03acf5f..0000000
--- a/src/ussa1976/units.py
+++ /dev/null
@@ -1,37 +0,0 @@
-"""Units module."""
-import pint
-import xarray as xr
-
-ureg = pint.UnitRegistry()
-
-
-def to_quantity(da: xr.DataArray) -> pint.Quantity:  # type: ignore[type-arg]
-    """Convert a DataArray to a quantity.
-
-    The array's ``attrs`` metadata mapping must contain a ``units`` field.
-
-    Parameters
-    ----------
-    da : DataArray
-        :class:`~xarray.DataArray` instance which will be converted.
-
-    Returns
-    -------
-    quantity
-        The corresponding Pint quantity.
-
-    Raises
-    ------
-    ValueError
-        If the array's metadata do not contain a ``units`` field.
-
-    Notes
-    -----
-    This function can also be used on coordinate variables.
-    """
-    try:
-        units = da.attrs["units"]
-    except KeyError as e:
-        raise ValueError("this DataArray has no 'units' metadata field") from e
-    else:
-        return ureg.Quantity(da.values, units)


Test patch:
diff --git a/tests/test_units.py b/tests/test_units.py
deleted file mode 100644
index b0dacb6..0000000
--- a/tests/test_units.py
+++ /dev/null
@@ -1,31 +0,0 @@
-"""Test cases for the units module."""
-import numpy as np
-import pytest
-import xarray as xr
-
-from ussa1976.units import to_quantity
-from ussa1976.units import ureg
-
-
-@pytest.fixture
-def test_dataset() -> xr.Dataset:
-    """Test dataset fixture."""
-    return xr.Dataset(
-        data_vars={
-            "p": ("z", np.random.random(50), dict(units="Pa")),
-            "t": ("z", np.random.random(50)),
-        },
-        coords={"z": ("z", np.linspace(0, 100, 50), dict(units="m"))},
-    )
-
-
-def test_to_quantity(test_dataset: xr.Dataset) -> None:
-    """Returns a pint.Quantity object."""
-    p = to_quantity(test_dataset.p)
-    assert isinstance(p, ureg.Quantity)
-
-
-def test_to_quantity_no_units(test_dataset: xr.Dataset) -> None:
-    """Raises when data variable has no units."""
-    with pytest.raises(ValueError):
-        to_quantity(test_dataset.t)