diff options
| author | Sebastian Berg <sebastianb@nvidia.com> | 2023-01-26 12:16:23 +0100 |
|---|---|---|
| committer | Sebastian Berg <sebastianb@nvidia.com> | 2023-02-10 14:49:16 +0100 |
| commit | c03e84044a05f0b2358a1cbfc4158e83cba4b835 (patch) | |
| tree | d2d6acb05816db3a815f50967c0cb22f3d896c35 /numpy/lib | |
| parent | 624b18090ae567f3cfd528a8ae156b2ae7db6d82 (diff) | |
| download | numpy-c03e84044a05f0b2358a1cbfc4158e83cba4b835.tar.gz | |
API: Modify `gradient` to return a tuple rather than a list
This change is staged for NumPy 2.0, I assume we could get away with
it otherwise, but it is a nice example and probably not pressing.
Diffstat (limited to 'numpy/lib')
| -rw-r--r-- | numpy/lib/function_base.py | 2 | ||||
| -rw-r--r-- | numpy/lib/tests/test_function_base.py | 7 |
2 files changed, 9 insertions, 0 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 0ca3c21c1..1f39ebc71 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1311,6 +1311,8 @@ def gradient(f, *varargs, axis=None, edge_order=1): if len_axes == 1: return outvals[0] + elif np._numpy2_behavior: + return tuple(outvals) else: return outvals diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py index ecba35f2d..fb98a94cd 100644 --- a/numpy/lib/tests/test_function_base.py +++ b/numpy/lib/tests/test_function_base.py @@ -1217,6 +1217,13 @@ class TestGradient: dfdx = gradient(f, x) assert_array_equal(dfdx, [0.5, 0.5]) + def test_return_type(self): + res = np.gradient(([1, 2], [2, 3])) + if np._numpy2_behavior: + assert type(res) is tuple + else: + assert type(res) is list + class TestAngle: |
