|
| 1 | +import pytest |
| 2 | + |
| 3 | +import xarray as xr |
| 4 | +from xarray.testing import assert_equal |
| 5 | + |
| 6 | +import numpy as np |
| 7 | +from numpy.testing import assert_array_equal |
| 8 | + |
| 9 | +from pint import UnitRegistry |
| 10 | +from pint.unit import Unit |
| 11 | +from pint.errors import DimensionalityError |
| 12 | + |
| 13 | +from pintxarray.accessors import PintDataArrayAccessor, PintDatasetAccessor |
| 14 | +from .utils import extract_units |
| 15 | + |
| 16 | + |
| 17 | +# make sure scalars are converted to 0d arrays so quantities can |
| 18 | +# always be treated like ndarrays |
| 19 | +unit_registry = UnitRegistry(force_ndarray=True) |
| 20 | +Quantity = unit_registry.Quantity |
| 21 | + |
| 22 | + |
| 23 | +@pytest.fixture() |
| 24 | +def example_unitless_da(): |
| 25 | + array = np.linspace(0, 10, 20) |
| 26 | + x = np.arange(20) |
| 27 | + da = xr.DataArray(data=array, dims="x", coords={"x": x}) |
| 28 | + da.attrs['units'] = 'm' |
| 29 | + da.coords['x'].attrs['units'] = 's' |
| 30 | + return da |
| 31 | + |
| 32 | +@pytest.fixture() |
| 33 | +def example_quantity_da(): |
| 34 | + array = np.linspace(0, 10, 20) * unit_registry.m |
| 35 | + x = np.arange(20) * unit_registry.s |
| 36 | + return xr.DataArray(data=array, dims="x", coords={"x": x}) |
| 37 | + |
| 38 | + |
| 39 | +class TestQuantifyDataArray: |
| 40 | + @pytest.mark.skip(reason="Not yet implemented") |
| 41 | + def test_attach_units_given_registry(self): |
| 42 | + ... |
| 43 | + |
| 44 | + def test_attach_units(self, example_unitless_da): |
| 45 | + orig = example_unitless_da |
| 46 | + result = orig.pint.quantify('m') |
| 47 | + assert_array_equal(result.data.magnitude, orig.data) |
| 48 | + assert str(result.data.units) == 'meter' |
| 49 | + |
| 50 | + def test_attach_units_from_attrs(self): |
| 51 | + ... |
| 52 | + |
| 53 | + def test_attach_unit_class(self): |
| 54 | + ... |
| 55 | + |
| 56 | + def test_error_when_already_units(self, example_quantity_da): |
| 57 | + da = example_quantity_da |
| 58 | + with pytest.raises(ValueError): |
| 59 | + da.pint.quantify() |
| 60 | + |
| 61 | + def test_error_on_nonsense_units(self): |
| 62 | + ... |
| 63 | + |
| 64 | + def test_registry_kwargs(self): |
| 65 | + ... |
| 66 | + |
| 67 | + |
| 68 | +@pytest.mark.skip(reason="Not yet implemented") |
| 69 | +class TestDequantifyDataArray: |
| 70 | + def test_strip_units(self): |
| 71 | + ... |
| 72 | + |
| 73 | + def test_error_if_no_units(self): |
| 74 | + ... |
| 75 | + |
| 76 | + def test_roundtrip_attrs(self): |
| 77 | + ... |
| 78 | + |
| 79 | + |
| 80 | +@pytest.mark.skip(reason="Not yet implemented") |
| 81 | +class TestPropertiesDataArray: |
| 82 | + def test_units(self): |
| 83 | + ... |
| 84 | + |
| 85 | + |
| 86 | +@pytest.mark.skip(reason="Not yet implemented") |
| 87 | +class TestConversionDataArray: |
| 88 | + def test_units(self): |
| 89 | + ... |
| 90 | + |
| 91 | + |
| 92 | +@pytest.mark.skip(reason="Not yet implemented") |
| 93 | +class TestUncertainties: |
| 94 | + def test_units(self): |
| 95 | + ... |
| 96 | + |
| 97 | + |
| 98 | +@pytest.mark.skip(reason="Not yet implemented") |
| 99 | +class TestQuantifyDataSet: |
| 100 | + def test_attach_units(self): |
| 101 | + ... |
| 102 | + |
| 103 | + def test_attach_str_units(self): |
| 104 | + ... |
| 105 | + |
| 106 | + def test_attach_units_from_registry(self): |
| 107 | + ... |
| 108 | + |
| 109 | + |
| 110 | +@pytest.mark.skip(reason="Not yet implemented") |
| 111 | +class TestIndexing: |
| 112 | + ... |
0 commit comments