summaryrefslogtreecommitdiff
path: root/pint
diff options
context:
space:
mode:
authorJon Thielen <github@jont.cc>2020-01-08 11:23:39 -0600
committerJon Thielen <github@jont.cc>2020-01-08 11:34:41 -0600
commit6a0098a26e7811df09e2b0f40f0a28aed14f6233 (patch)
treec855c116122c097dd6fae1928b3897444acc6c0d /pint
parent5da3a2da7f3a4f25cd9da4065f4d3cc7a671a1f0 (diff)
downloadpint-6a0098a26e7811df09e2b0f40f0a28aed14f6233.tar.gz
Add implementations and tests for allclose and intersect1d
Diffstat (limited to 'pint')
-rw-r--r--pint/numpy_func.py2
-rw-r--r--pint/testsuite/test_numpy.py16
2 files changed, 18 insertions, 0 deletions
diff --git a/pint/numpy_func.py b/pint/numpy_func.py
index 2eda4fa..1fd7d8c 100644
--- a/pint/numpy_func.py
+++ b/pint/numpy_func.py
@@ -772,6 +772,8 @@ for func_str, unit_arguments, wrap_output in [
("insert", ["arr", "values"], True),
("resize", "a", True),
("reshape", "a", True),
+ ("allclose", ["a", "b"], False),
+ ("intersect1d", ["ar1", "ar2"], True),
]:
implement_consistent_units_by_argument(func_str, unit_arguments, wrap_output)
diff --git a/pint/testsuite/test_numpy.py b/pint/testsuite/test_numpy.py
index 13a773f..0efb476 100644
--- a/pint/testsuite/test_numpy.py
+++ b/pint/testsuite/test_numpy.py
@@ -1153,6 +1153,22 @@ class TestNumpyUnclassified(TestNumpyMethods):
),
) # Note: Does not support Quantity pad_with vectorized callable use
+ @helpers.requires_array_function_protocol()
+ def test_allclose(self):
+ self.assertTrue(
+ np.allclose([1e10, 1e-8] * self.ureg.m, [1.00001e10, 1e-9] * self.ureg.m)
+ )
+ self.assertFalse(
+ np.allclose([1e10, 1e-8] * self.ureg.m, [1.00001e10, 1e-9] * self.ureg.mm)
+ )
+
+ @helpers.requires_array_function_protocol()
+ def test_intersect1d(self):
+ self.assertQuantityEqual(
+ np.intersect1d([1, 3, 4, 3] * self.ureg.m, [3, 1, 2, 1] * self.ureg.m),
+ [1, 3] * self.ureg.m,
+ )
+
@unittest.skip
class TestBitTwiddlingUfuncs(TestUFuncs):