Skip to content

Commit

Permalink
BUG: Fixes #5524 and adds test
Browse files Browse the repository at this point in the history
argpartition does not fail anymore on non-ndarray array-likes.
Fix as implemented by @maniteja123.
  • Loading branch information
hannaro authored and Hanna committed Feb 25, 2015
1 parent d770034 commit 1b6f46a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
10 changes: 9 additions & 1 deletion numpy/core/fromnumeric.py
Expand Up @@ -691,8 +691,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):
Expand Down
6 changes: 6 additions & 0 deletions numpy/core/tests/test_multiarray.py
Expand Up @@ -1748,6 +1748,12 @@ def test_partition_fuzz(self):
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)
Expand Down

0 comments on commit 1b6f46a

Please sign in to comment.