diff options
author | hannaro <hroehling@gmx.net> | 2015-02-19 14:47:52 +0100 |
---|---|---|
committer | Julian Taylor <jtaylor.debian@googlemail.com> | 2015-02-28 13:33:40 +0100 |
commit | 43c8313a3bae730b1f6ef7a35adb935959f892c8 (patch) | |
tree | 6010ebc5e45021f312e060df87886ac2f4f50b2e | |
parent | 1f72899ac674c9e44c1be2948ad5b2eef008a32f (diff) | |
download | numpy-43c8313a3bae730b1f6ef7a35adb935959f892c8.tar.gz |
BUG: Fixes #5524 and adds test
argpartition does not fail anymore on non-ndarray array-likes.
Fix as implemented by @maniteja123.
-rw-r--r-- | numpy/core/fromnumeric.py | 10 | ||||
-rw-r--r-- | numpy/core/tests/test_multiarray.py | 6 |
2 files changed, 15 insertions, 1 deletions
diff --git a/numpy/core/fromnumeric.py b/numpy/core/fromnumeric.py index 49fd57e29..72d59fd0c 100644 --- a/numpy/core/fromnumeric.py +++ b/numpy/core/fromnumeric.py @@ -679,8 +679,16 @@ def argpartition(a, kth, axis=-1, kind='introselect', order=None): >>> x[np.argpartition(x, (1, 3))] array([1, 2, 3, 4]) + >>> x = [3, 4, 2, 1] + >>> np.array(x)[np.argpartition(x, 3)] + array([2, 1, 3, 4]) + """ - return a.argpartition(kth, axis, kind=kind, order=order) + try: + argpartition = a.argpartition + except AttributeError: + return _wrapit(a, 'argpartition',kth, axis, kind, order) + return argpartition(kth, axis, kind=kind, order=order) def sort(a, axis=-1, kind='quicksort', order=None): diff --git a/numpy/core/tests/test_multiarray.py b/numpy/core/tests/test_multiarray.py index 1ca06500a..d93211471 100644 --- a/numpy/core/tests/test_multiarray.py +++ b/numpy/core/tests/test_multiarray.py @@ -1702,6 +1702,12 @@ class TestMethods(TestCase): assert_array_equal(np.partition(d, kth)[kth], tgt, err_msg="data: %r\n kth: %r" % (d, kth)) + def test_argpartition_gh5524(self): + # A test for functionality of argpartition on lists. + d = [6,7,3,2,9,0] + p = np.argpartition(d,1) + self.assert_partitioned(np.array(d)[p],[1]) + def test_flatten(self): x0 = np.array([[1, 2, 3], [4, 5, 6]], np.int32) x1 = np.array([[[1, 2], [3, 4]], [[5, 6], [7, 8]]], np.int32) |