Skip to content

Commit 3c1392f

Browse files
authored
clean up the documentation (#177)
* update the docstring of `DataArray.pint.quantify` * same for `Dataset.pint.quantify` * link to the proper section on pint's string formatting * add markers to the link texts of the extlinks * fix some links * remove the explicit mention of ipython_genutils * unpin sphinx
1 parent 7c93089 commit 3c1392f

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

docs/conf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@
7575

7676
# extlinks
7777
extlinks = {
78-
"issue": (f"{github_url}/issues/%s", "GH"),
79-
"pull": (f"{github_url}/pull/%s", "PR"),
78+
"issue": (f"{github_url}/issues/%s", "GH%s"),
79+
"pull": (f"{github_url}/pull/%s", "PR%s"),
8080
}
8181

8282
# autosummary

docs/contributing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@ In order to keep code consistent, we use
1414

1515
- `Black <https://black.readthedocs.io/en/stable/>`_ for standardized code formatting
1616
- `blackdoc <https://blackdoc.readthedocs.io/en/stable/>`_ for standardized code formatting in documentation
17-
- `Flake8 <http://flake8.pycqa.org/en/latest/>`_ for general code quality
18-
- `isort <https://github.com/timothycrosley/isort>`_ for standardized order in imports. See also `flake8-isort <https://github.com/gforcada/flake8-isort>`_.
17+
- `Flake8 <https://flake8.pycqa.org/en/latest/>`_ for general code quality
18+
- `isort <https://github.com/PyCQA/isort>`_ for standardized order in imports. See also `flake8-isort <https://github.com/gforcada/flake8-isort>`_.

docs/creation.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,6 @@ This will get the string representation of a :py:class:`pint.Unit` instance and
130130
attach it as a ``units`` attribute. The data of the variable will now be
131131
whatever `pint`_ wrapped.
132132

133-
.. _pint: https://pint.readthedocs.org/en/stable
134-
.. _xarray: https://xarray.pydata.org/en/stable
133+
.. _pint: https://pint.readthedocs.io/en/stable/
134+
.. _xarray: https://docs.xarray.dev/en/stable/
135135
.. _units in indexes: https://github.com/pydata/xarray/issues/1603

docs/requirements.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ xarray>=0.16.0
33
pooch
44
netCDF4
55
cf-xarray>=0.6
6-
sphinx<4
7-
ipython_genutils # remove once there's a new `nbconvert` release
6+
sphinx
87
sphinx_rtd_theme
98
ipython
109
ipykernel

docs/whats-new.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ What's new
3535
-----------------
3636
- rewrite :py:meth:`Dataset.pint.quantify` and :py:meth:`DataArray.pint.quantify`, to
3737
use pint's ``UnitRegistry.parse_units`` instead of ``UnitRegistry.parse_expression``
38-
(:pull:`40`)
38+
(:issue:`40`)
3939
By `Tom Nicholas <https://github.com/TomNicholas>`_.
4040
- ensure the variables which causes the error is explicit if an error occurs in
41-
:py:meth:`Dataset.pint.quantify` and other methods (:pull:`43`, :pull:`91`)
41+
:py:meth:`Dataset.pint.quantify` and other methods (:pull:`43`, :issue:`91`)
4242
By `Tom Nicholas <https://github.com/TomNicholas>`_ and `Justus Magin <https://github.com/keewis>`_.
4343
- refactor the internal conversion functions (:pull:`56`)
4444
By `Justus Magin <https://github.com/keewis>`_.

pint_xarray/accessors.py

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def quantify(self, units=_default, unit_registry=None, **unit_kwargs):
245245
parsed by the given unit registry. If no units are specified then the
246246
units will be parsed from the `'units'` entry of the DataArray's
247247
`.attrs`. Will raise a ValueError if the DataArray already contains a
248-
unit-aware array.
248+
unit-aware array with a different unit.
249249
250250
.. note::
251251
Be aware that unless you're using ``dask`` this will load
@@ -310,6 +310,18 @@ def quantify(self, units=_default, unit_registry=None, **unit_kwargs):
310310
<xarray.DataArray (wavelength: 2)>
311311
array([0.4, 0.9])
312312
Dimensions without coordinates: wavelength
313+
314+
Quantify with the same unit:
315+
316+
>>> q = da.pint.quantify()
317+
>>> q
318+
<xarray.DataArray (wavelength: 2)>
319+
<Quantity([0.4 0.9], 'hertz')>
320+
Dimensions without coordinates: wavelength
321+
>>> q.pint.quantify("Hz")
322+
<xarray.DataArray (wavelength: 2)>
323+
<Quantity([0.4 0.9], 'hertz')>
324+
Dimensions without coordinates: wavelength
313325
"""
314326
if units is None or isinstance(units, (str, pint.Unit)):
315327
if self.da.name in unit_kwargs:
@@ -397,7 +409,8 @@ def dequantify(self, format=None):
397409
398410
See Also
399411
--------
400-
https://pint.readthedocs.io/en/stable/tutorial.html#string-formatting
412+
:doc:`pint:formatting`
413+
pint's string formatting guide
401414
402415
Examples
403416
--------
@@ -958,7 +971,7 @@ def quantify(self, units=_default, unit_registry=None, **unit_kwargs):
958971
units are specified then the units will be parsed from the
959972
``"units"`` entry of the Dataset variable's ``.attrs``. Will
960973
raise a ValueError if any of the variables already contain a
961-
unit-aware array.
974+
unit-aware array with a different unit.
962975
963976
.. note::
964977
Be aware that unless you're using ``dask`` this will load
@@ -1035,6 +1048,28 @@ def quantify(self, units=_default, unit_registry=None, **unit_kwargs):
10351048
Data variables:
10361049
a (x) int64 0 3 2
10371050
b (x) int64 5 -2 1
1051+
1052+
Quantify with the same unit:
1053+
1054+
>>> q = ds.pint.quantify()
1055+
>>> q
1056+
<xarray.Dataset>
1057+
Dimensions: (x: 3)
1058+
Coordinates:
1059+
* x (x) int64 0 1 2
1060+
u (x) int64 [s] -1 0 1
1061+
Data variables:
1062+
a (x) int64 [m] 0 3 2
1063+
b (x) int64 5 -2 1
1064+
>>> q.pint.quantify({"a": "m"})
1065+
<xarray.Dataset>
1066+
Dimensions: (x: 3)
1067+
Coordinates:
1068+
* x (x) int64 0 1 2
1069+
u (x) int64 [s] -1 0 1
1070+
Data variables:
1071+
a (x) int64 [m] 0 3 2
1072+
b (x) int64 5 -2 1
10381073
"""
10391074
units = either_dict_or_kwargs(units, unit_kwargs, "quantify")
10401075
registry = get_registry(unit_registry, units, conversion.extract_units(self.ds))
@@ -1100,8 +1135,8 @@ def dequantify(self, format=None):
11001135
Parameters
11011136
----------
11021137
format : str, default: None
1103-
The format specification (as accepted by pint) used for the string
1104-
representations. If ``None``, the registry's default
1138+
The format specification (as accepted by pint's unit formatter) used for the
1139+
string representations. If ``None``, the registry's default
11051140
(:py:attr:`pint.UnitRegistry.default_format`) is used instead.
11061141
11071142
Returns
@@ -1112,7 +1147,8 @@ def dequantify(self, format=None):
11121147
11131148
See Also
11141149
--------
1115-
https://pint.readthedocs.io/en/stable/tutorial.html#string-formatting
1150+
:doc:`pint:formatting`
1151+
pint's string formatting guide
11161152
11171153
Examples
11181154
--------

0 commit comments

Comments
 (0)