summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Göries <43136580+dgoeries@users.noreply.github.com>2023-03-23 18:51:28 +0100
committerGitHub <noreply@github.com>2023-03-23 18:51:28 +0100
commit238fdc151ed5fe7cdf3ac2933b90d3d7bdf2e4c5 (patch)
treeed92f1cf9421199c5f99439cc87d0cf416f00036
parent3c6f5ffcb9304089caf4be07ded2c3644c2c0e13 (diff)
downloadpint-238fdc151ed5fe7cdf3ac2933b90d3d7bdf2e4c5.tar.gz
Support numpy delete (#1699)
* Support numpy delete --------- Co-authored-by: Jules Chéron <43635101+jules-ch@users.noreply.github.com>
-rw-r--r--CHANGES2
-rw-r--r--pint/facets/numpy/numpy_func.py1
-rw-r--r--pint/testsuite/test_numpy.py18
3 files changed, 21 insertions, 0 deletions
diff --git a/CHANGES b/CHANGES
index 1245268..16c25e7 100644
--- a/CHANGES
+++ b/CHANGES
@@ -12,6 +12,8 @@ Pint Changelog
(PR #1663)
- Changed frequency to angular frequency in the docs.
(PR #1668)
+- Implementation for numpy.delete added for Quantity.
+ (PR #1669)
- Fixed Quantity type returned from `__dask_postcompute__`.
(PR #1722)
diff --git a/pint/facets/numpy/numpy_func.py b/pint/facets/numpy/numpy_func.py
index aa5886c..ee6ef31 100644
--- a/pint/facets/numpy/numpy_func.py
+++ b/pint/facets/numpy/numpy_func.py
@@ -830,6 +830,7 @@ for func_str, unit_arguments, wrap_output in [
("lib.stride_tricks.sliding_window_view", "x", True),
("rot90", "m", True),
("insert", ["arr", "values"], True),
+ ("delete", ["arr"], True),
("resize", "a", True),
("reshape", "a", True),
("allclose", ["a", "b"], False),
diff --git a/pint/testsuite/test_numpy.py b/pint/testsuite/test_numpy.py
index 47485a3..88a3be4 100644
--- a/pint/testsuite/test_numpy.py
+++ b/pint/testsuite/test_numpy.py
@@ -1222,6 +1222,24 @@ class TestNumpyUnclassified(TestNumpyMethods):
np.array([[1, 0, 2], [3, 0, 4]]) * self.ureg.m,
)
+ @helpers.requires_array_function_protocol()
+ def test_delete(self):
+ q = self.Q_(np.array([[1, 2, 3, 4], [5, 6, 7, 8], [9, 10, 11, 12]]), "m")
+ helpers.assert_quantity_equal(
+ np.delete(q, 1, axis=0),
+ np.array([[1, 2, 3, 4], [9, 10, 11, 12]]) * self.ureg.m,
+ )
+
+ helpers.assert_quantity_equal(
+ np.delete(q, np.s_[::2], 1),
+ np.array([[2, 4], [6, 8], [10, 12]]) * self.ureg.m,
+ )
+
+ helpers.assert_quantity_equal(
+ np.delete(q, [1, 3, 5], None),
+ np.array([1, 3, 5, 7, 8, 9, 10, 11, 12]) * self.ureg.m,
+ )
+
def test_ndarray_downcast(self):
with pytest.warns(UnitStrippedWarning):
np.asarray(self.q)