Skip to content

Corner cases for topk of array #2965

@rzu512

Description

@rzu512

Kind of silly, but I run into this when I try to define topk(k, x, axis=None).
Test:

import numpy as np
import dask.array as da
x = da.from_array(np.array([0]), chunks=1)
da.topk(x, 0)

Result:

Traceback (most recent call last):
  File "test_topk2.py", line 4, in <module>
    da.topk(x, 0)
  File "<python dir>/site-packages/dask/array/routines.py", line 790, in topk
    if x.ndim != 1:

Tests:

import numpy as np
import dask.array as da
cases = [(0, 0, 0), (0, 1, 0), (0, 1, 1), ([0], 1, 0), ([0], 1, 1)]

for a, b, c in cases:
    x = da.from_array(np.array(a), chunks=b)
    try:
        da.topk(x, c)
    except Exception as err:
        print("[ case: (%s, %s, %s) ]" % (a, b, c))
        print('fail', err)

Result:

[ case: (0, 0, 0) ]
fail 'int' object has no attribute 'ndim'
[ case: (0, 1, 0) ]
fail 'int' object has no attribute 'ndim'
[ case: (0, 1, 1) ]
fail 'int' object has no attribute 'ndim'
[ case: ([0], 1, 0) ]
fail 'int' object has no attribute 'ndim'
[ case: ([0], 1, 1) ]
fail 'int' object has no attribute 'ndim'

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions