diff options
author | Jules Chéron <jules.cheron@gmail.com> | 2022-01-23 22:15:13 +0100 |
---|---|---|
committer | Jules Chéron <jules.cheron@gmail.com> | 2022-01-23 22:24:13 +0100 |
commit | 18fb0b214179a897a5fb31da8f73f8817546cf69 (patch) | |
tree | 18db54e45862f3b4302b15ae1a809fe39a1c9996 /pint/quantity.py | |
parent | befdffb9d767fb354fc756660a33268c0f8d48e1 (diff) | |
download | pint-18fb0b214179a897a5fb31da8f73f8817546cf69.tar.gz |
Use default numpy `np.printoptions` available since numpy 1.15
Diffstat (limited to 'pint/quantity.py')
-rw-r--r-- | pint/quantity.py | 21 |
1 files changed, 4 insertions, 17 deletions
diff --git a/pint/quantity.py b/pint/quantity.py index 138e17a..f79f1a9 100644 --- a/pint/quantity.py +++ b/pint/quantity.py @@ -9,7 +9,6 @@ from __future__ import annotations import bisect -import contextlib import copy import datetime import functools @@ -168,20 +167,6 @@ def check_dask_array(f): return wrapper -@contextlib.contextmanager -def printoptions(*args, **kwargs): - """Numpy printoptions context manager released with version 1.15.0 - https://docs.scipy.org/doc/numpy/reference/generated/numpy.printoptions.html - """ - - opts = np.get_printoptions() - try: - np.set_printoptions(*args, **kwargs) - yield np.get_printoptions() - finally: - np.set_printoptions(**opts) - - # Workaround to bypass dynamically generated Quantity with overload method Magnitude = TypeVar("Magnitude") @@ -413,7 +398,9 @@ class Quantity(PrettyIPython, SharedRegistryObject, Generic[_MagnitudeType]): allf = plain_allf = "{} {}" mstr = formatter.format(obj.magnitude) else: - with printoptions(formatter={"float_kind": formatter.format}): + with np.printoptions( + formatter={"float_kind": formatter.format} + ): mstr = ( "<pre>" + format(obj.magnitude).replace("\n", "<br>") @@ -440,7 +427,7 @@ class Quantity(PrettyIPython, SharedRegistryObject, Generic[_MagnitudeType]): if obj.magnitude.ndim == 0: mstr = formatter.format(obj.magnitude) else: - with printoptions(formatter={"float_kind": formatter.format}): + with np.printoptions(formatter={"float_kind": formatter.format}): mstr = format(obj.magnitude).replace("\n", "") else: mstr = format(obj.magnitude, mspec).replace("\n", "") |