Skip to content

Array.random.choice: handle array-like non-arrays#5283

Merged
jakirkham merged 1 commit intodask:masterfrom
gjoseph92:array/random/choice_array_like
Aug 18, 2019
Merged

Array.random.choice: handle array-like non-arrays#5283
jakirkham merged 1 commit intodask:masterfrom
gjoseph92:array/random/choice_array_like

Conversation

@gjoseph92
Copy link
Copy Markdown
Collaborator

In [1]: import dask.array as da

In [2]: import numpy as np

In [3]: np.random.choice([True, False], 4)
Out[3]: array([ True, False,  True, False])

In [4]: da.random.choice([True, False], 4)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-4-33075a6cbfe5> in <module>()
----> 1 da.random.choice([True, False], 4)

/home/gabejoseph/.cache/bazel/_bazel_gabejoseph/cbd078f976ef86a52da9fe15f5a84af9/execroot/__main__/bazel-out/k8-opt/bin/descarteslabs/services/workbench/impl/repl.runf
iles/requirements_py3_pypi__dask_1_2_2_41_g32f0fac0/dask/array/random.py in choice(self, a, size, replace, p, chunks)
    201                     raise ValueError("a must be greater than 0")
    202             else:
--> 203                 a = asarray(a).rechunk(a.shape)
    204                 dtype = a.dtype
    205                 if a.ndim != 1:

AttributeError: 'list' object has no attribute 'shape'
  • Tests added / passed
  • Passes black dask / flake8 dask

@jakirkham jakirkham merged commit 8d2e0dc into dask:master Aug 18, 2019
@jakirkham
Copy link
Copy Markdown
Member

cc @TomAugspurger

@jakirkham
Copy link
Copy Markdown
Member

Thanks for the PR, @gjoseph92! This is great 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants