summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJon Thielen <github@jont.cc>2020-02-18 13:57:39 -0600
committerJon Thielen <github@jont.cc>2020-02-18 15:50:45 -0600
commite82b9b059ddf30739b362b6a233e832c3d3eddb5 (patch)
tree3d0063f3f698f0fd9ea4dfa62afe38a3f2db59fa
parent41bcb6358621c1684a560620d81b50277743953c (diff)
downloadpint-e82b9b059ddf30739b362b6a233e832c3d3eddb5.tar.gz
Remove array function warning on first creation
-rw-r--r--CHANGES3
-rw-r--r--pint/compat.py23
-rw-r--r--pint/quantity.py11
-rw-r--r--pint/testsuite/test_numpy.py1
-rw-r--r--pint/testsuite/test_quantity.py9
5 files changed, 6 insertions, 41 deletions
diff --git a/CHANGES b/CHANGES
index a4f5f4a..933afc4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,9 @@ Pint Changelog
0.11 (unreleased)
-----------------
+- Quantities wrapping NumPy arrays will no longer warning for the changed
+ array function behavior introduced in 0.10.
+ (Issue #1029, Thanks Jon Thielen)
- **BREAKING CHANGE**:
The array protocol fallback deprecated in version 0.10 has been removed.
(Issue #1029, Thanks Jon Thielen)
diff --git a/pint/compat.py b/pint/compat.py
index e6037b2..e8e1a1b 100644
--- a/pint/compat.py
+++ b/pint/compat.py
@@ -36,27 +36,6 @@ class BehaviorChangeWarning(UserWarning):
pass
-array_function_change_msg = """The way Pint handles NumPy operations has changed with the
-implementation of NEP 18. Unimplemented NumPy operations will now fail instead of making
-assumptions about units. Some functions, eg concat, will now return Quanties with units, where
-they returned ndarrays previously. See https://github.com/hgrecco/pint/pull/905.
-
-To hide this warning, wrap your first creation of an array Quantity with
-warnings.catch_warnings(), like the following:
-
-import numpy as np
-import warnings
-from pint import Quantity
-
-with warnings.catch_warnings():
- warnings.simplefilter("ignore")
- Quantity([])
-
-To disable the new behavior, see
-https://www.numpy.org/neps/nep-0018-array-function-protocol.html#implementation
-"""
-
-
try:
import numpy as np
from numpy import ndarray
@@ -92,7 +71,6 @@ try:
return False
HAS_NUMPY_ARRAY_FUNCTION = _test_array_function_protocol()
- SKIP_ARRAY_FUNCTION_CHANGE_WARNING = not HAS_NUMPY_ARRAY_FUNCTION
NP_NO_VALUE = np._NoValue
@@ -107,7 +85,6 @@ except ImportError:
NUMPY_VER = "0"
NUMERIC_TYPES = (Number, Decimal)
HAS_NUMPY_ARRAY_FUNCTION = False
- SKIP_ARRAY_FUNCTION_CHANGE_WARNING = True
NP_NO_VALUE = None
def _to_magnitude(value, force_ndarray=False, force_ndarray_like=False):
diff --git a/pint/quantity.py b/pint/quantity.py
index 59b97d2..91eee2a 100644
--- a/pint/quantity.py
+++ b/pint/quantity.py
@@ -20,12 +20,9 @@ import warnings
from pkg_resources.extern.packaging import version
-from .compat import SKIP_ARRAY_FUNCTION_CHANGE_WARNING # noqa: F401
from .compat import (
NUMPY_VER,
- BehaviorChangeWarning,
_to_magnitude,
- array_function_change_msg,
babel_parse,
eq,
is_duck_array_type,
@@ -160,8 +157,6 @@ class Quantity(PrettyIPython, SharedRegistryObject):
return _unpickle, (Quantity, self.magnitude, self._units)
def __new__(cls, value, units=None):
- global SKIP_ARRAY_FUNCTION_CHANGE_WARNING
-
if is_upcast_type(type(value)):
raise TypeError(f"Quantity cannot wrap upcast type {type(value)}")
elif units is None:
@@ -214,12 +209,6 @@ class Quantity(PrettyIPython, SharedRegistryObject):
inst.__used = False
inst.__handling = None
- if not SKIP_ARRAY_FUNCTION_CHANGE_WARNING and isinstance(
- inst._magnitude, ndarray
- ):
- warnings.warn(array_function_change_msg, BehaviorChangeWarning)
- SKIP_ARRAY_FUNCTION_CHANGE_WARNING = True
-
return inst
@property
diff --git a/pint/testsuite/test_numpy.py b/pint/testsuite/test_numpy.py
index 05aea96..3eeab6c 100644
--- a/pint/testsuite/test_numpy.py
+++ b/pint/testsuite/test_numpy.py
@@ -1,7 +1,6 @@
import copy
import operator as op
import unittest
-from unittest.mock import patch
from pint import DimensionalityError, OffsetUnitCalculusError, UnitStrippedWarning
from pint.compat import np
diff --git a/pint/testsuite/test_quantity.py b/pint/testsuite/test_quantity.py
index fbfd773..51faf1a 100644
--- a/pint/testsuite/test_quantity.py
+++ b/pint/testsuite/test_quantity.py
@@ -6,7 +6,7 @@ import warnings
from unittest.mock import patch
from pint import DimensionalityError, OffsetUnitCalculusError, UnitRegistry
-from pint.compat import BehaviorChangeWarning, np
+from pint.compat import np
from pint.testsuite import QuantityTestCase, helpers
from pint.testsuite.parameterized import ParameterizedTestCase
from pint.unit import UnitsContainer
@@ -531,11 +531,8 @@ class TestQuantity(QuantityTestCase):
iter(x)
@helpers.requires_array_function_protocol()
- @patch("pint.quantity.SKIP_ARRAY_FUNCTION_CHANGE_WARNING", False)
- def test_array_function_warning_on_creation(self):
- # Test that warning is raised on first creation, but not second
- with self.assertWarns(BehaviorChangeWarning):
- self.Q_([])
+ def test_no_longer_array_function_warning_on_creation(self):
+ # Test that warning is no longer raised on first creation
with warnings.catch_warnings():
warnings.filterwarnings("error")
self.Q_([])