Skip to content

Commit

Permalink
Clean up docstrings; update docs; skip visualize tests with no graphviz
Browse files Browse the repository at this point in the history
  • Loading branch information
rpmanser committed Jul 8, 2020
1 parent 75e1c03 commit e529f34
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 19 deletions.
9 changes: 7 additions & 2 deletions docs/numpy.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,12 @@
"\n",
"print(repr(q))\n",
"print()\n",
"print(repr(d * ureg.kelvin))"
"\n",
"# DO NOT create using multiplication on the right until\n",
"# https://github.com/dask/dask/issues/4583 is resolved, as\n",
"# unexpected behavior may result\n",
"print(repr(d * ureg.kelvin))\n",
"print(repr(ureg.kelvin * d))"
]
},
{
Expand Down Expand Up @@ -490,7 +495,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.3"
"version": "3.8.2"
}
},
"nbformat": 4,
Expand Down
5 changes: 3 additions & 2 deletions pint/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class BehaviorChangeWarning(UserWarning):

try:
import numpy as np
from numpy import ndarray, datetime64 as np_datetime64
from numpy import datetime64 as np_datetime64
from numpy import ndarray

HAS_NUMPY = True
NUMPY_VER = np.__version__
Expand Down Expand Up @@ -158,8 +159,8 @@ def _to_magnitude(value, force_ndarray=False, force_ndarray_like=False):
pass

try:
from dask import array as dask_array
from dask.base import compute, persist, visualize
import dask.array as dask_array

except ImportError:
compute, persist, visualize = None, None, None
Expand Down
1 change: 1 addition & 0 deletions pint/pint-convert
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ ureg.default_system = args.system

if args.unc:
import uncertainties

# Measured constans subject to correlation
# R_i: Rydberg constant
# g_e: Electron g factor
Expand Down
22 changes: 8 additions & 14 deletions pint/quantity.py
Original file line number Diff line number Diff line change
Expand Up @@ -1951,49 +1951,43 @@ def _dask_finalize(results, func, args, units):

@check_dask_array
def compute(self, **kwargs):
"""Compute a dask collection wrapped by pint.Quantity.
"""Compute the Dask array wrapped by pint.Quantity.
Parameters
----------
**kwargs : dict
Any keyword arguments to pass to the ``dask.base.compute`` function.
Any keyword arguments to pass to ``dask.compute``.
Returns
-------
pint.Quantity
Returns either the result of calling ``dask.base.compute``, in the case
that dask is enabled, or the object on which the ``compute`` method was
called without any modifications.
A pint.Quantity wrapped numpy array.
"""
(result,) = compute(self, **kwargs)
return result

@check_dask_array
def persist(self, **kwargs):
"""Compute a dask collection, and keep as a dask collection, wrapped by
pint.Quantity.
"""Persist the Dask Array wrapped by pint.Quantity.
Parameters
----------
**kwargs : dict
Any keyword arguments to pass to the ``dask.base.persist`` function.
Any keyword arguments to pass to ``dask.persist``.
Returns
-------
pint.Quantity
Returns either the result of calling ``dask.base.persist``, in the case
that dask is enabled, or the object on which the ``persist`` method was
called without any modifications.
A pint.Quantity wrapped Dask array.
"""
(result,) = persist(self, **kwargs)
return result

@check_dask_array
def visualize(self, **kwargs):
"""Produce a visual representation of the graph contained in the wrapped
Dask collection.
"""Produce a visual representation of the Dask graph.
The graphviz and python-graphviz libraries are required.
The graphviz library is required.
Parameters
----------
Expand Down
6 changes: 5 additions & 1 deletion pint/testsuite/test_dask.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import importlib
import os

import pytest
Expand Down Expand Up @@ -91,6 +92,9 @@ def test_persist(dask_array, numpy_array):
assert q.magnitude is dask_array


@pytest.mark.skipif(
importlib.util.find_spec("graphviz") is None, reason="GraphViz is not available"
)
def test_visualize(dask_array):
"""Test the visualize() method on a pint.Quantity wrapped Dask array."""
q = ureg.Quantity(dask_array, units_)
Expand All @@ -105,7 +109,7 @@ def test_visualize(dask_array):


def test_compute_persist_equivalent(dask_array, numpy_array):
"""Test that compute() and persist() return the same result."""
"""Test that compute() and persist() return the same numeric results."""
q = ureg.Quantity(dask_array, units_)

comps = add_five(q)
Expand Down
1 change: 1 addition & 0 deletions pint/testsuite/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ def test_define(self):

def test_load(self):
import pkg_resources

from pint import unit

data = pkg_resources.resource_filename(unit.__name__, "default_en.txt")
Expand Down

0 comments on commit e529f34

Please sign in to comment.