Skip to content

Cleanup and modernize dask.array creation functions (e.g. da.ones)#6276

Open
jcrist wants to merge 1 commit intodask:mainfrom
jcrist:modernize-array-creation
Open

Cleanup and modernize dask.array creation functions (e.g. da.ones)#6276
jcrist wants to merge 1 commit intodask:mainfrom
jcrist:modernize-array-creation

Conversation

@jcrist
Copy link
Copy Markdown
Member

@jcrist jcrist commented Jun 1, 2020

These are some of the oldest methods in dask.array, and stylistically
no longer matched much of the codebase. The implementation was also
overcomplicated to support ones and ones_like with the same wrapper
code, even though we no longer used the ones_like defined in that file
(that had since moved to da.creation from da.wrap). The wrapping
code also didn't properly handle the differences between *args and
**kwargs well, leading to issues if e.g. dtype was passed as an
arg not a kwarg.

This fixes all of that, removing the old code in wrap, and moving
everything under da.creation.
da.ones/da.zeros/da.full/da.empty all have proper signatures
now, and the underlying implementation is much simpler.

Also fixes a bug where calling da.full(large_shape, 1) with no dtype
would actually create that array in memory when inferring the dtype.

Fixes #6275.

  • Tests added / passed
  • Passes black dask / flake8 dask

These are some of the oldest methods in `dask.array`, and stylistically
no longer matched much of the codebase. The implementation was also
overcomplicated to support `ones` and `ones_like` with the same wrapper
code, even though we no longer used the `ones_like` defined in that file
(that had since moved to `da.creation` from `da.wrap`). The wrapping
code also didn't properly handle the differences between `*args` and
`**kwargs` well, leading to issues if e.g. `dtype` was passed as an
`arg` not a `kwarg`.

This fixes all of that, removing the old code in `wrap`, and moving
everything under `da.creation`.
`da.ones`/`da.zeros`/`da.full`/`da.empty` all have proper signatures
now, and the underlying implementation is much simpler.

Also fixes a bug where calling `da.full(large_shape, 1)` with no `dtype`
would actually create that array in memory when inferring the dtype.
@TomAugspurger
Copy link
Copy Markdown
Member

Haven't looked closely, but will this conflict with #6129?

@jcrist
Copy link
Copy Markdown
Member Author

jcrist commented Jun 2, 2020

There will be merge conflicts, but it doesn't go against what's done in that PR.

@jsignell
Copy link
Copy Markdown
Member

Note that there are also changes in #6064 that will make more conflicts for this PR.

@martindurant
Copy link
Copy Markdown
Member

ping @jcrist on cleaning up the conflicts here

def full(shape, fill_value, dtype=None, chunks="auto", **kwargs):
if dtype is None:
dtype = np.array(fill_value).dtype
return _handle_creation(np.full, shape, dtype, fill_value, chunks=chunks)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these functions be forwarding their kwargs to _handle_creation?

Base automatically changed from master to main March 8, 2021 20:19
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.

ones() and zeros() got multiple values for argument 'dtype'

6 participants