Skip to content

Mandatory dtypes on dask-array - #1755

Merged
mrocklin merged 3 commits into
dask:masterfrom
jcrist:array-dtypes
Nov 8, 2016
Merged

mrocklin merged 3 commits into
dask:masterfrom
jcrist:array-dtypes

Conversation

@jcrist

@jcrist jcrist commented Nov 3, 2016 •

Copy link
Copy Markdown
Member

Previously dask.array allowed known dtype to be optional, computing it dynamically as needed. This proved to be difficult to reason about, leading to unexpected computation (#1718). As done in #1422, we remove the optional dtype, falling back to inference if dtype isn't specified (if possible).

  • Make known dtype mandatory for all dask.array.Array objects
  • Fix failing functionality
  • Add inference to map_blocks/atop/reduction as needed.

Fixes #1718

- Make known `dtype` mandatory for all `dask.array.Array` objects
- Still need to add inference to map_blocks/atop/reduction as needed.
- dtype must be specified to atop, due to difficulty of inference
- infer dtype in elemwise and map_blocks
@jcrist

jcrist commented Nov 3, 2016 •

Copy link
Copy Markdown
Member Author

This could use a review. A summary of the changes:

  • This is a breaking change to atop, which now requires that dtype is specified. I suspect that most/all users of atop are already doing this, but it's a breaking change. Performing dtype inference on this function proved extremely tricky
  • dtype is inferred in map_blocks and elemwise, falling back to an informative error on failure.
  • The constructor now requires dtype be specified, and errors if it's not. I doubt many users were using the constructor directly, so I don't think this is a problem.

Note that I still need to add some (direct) tests for the inference bits, but am waiting on feedback on the overall approach before doing that.

Ping @shoyer, @mrocklin for review.

@sinhrks

sinhrks commented Nov 4, 2016 •

Copy link
Copy Markdown
Member

I think we can add Array._meta..., and share the same impl of _emulate and extract_meta between dataframe and array.

@sinhrks sinhrks added the array label Nov 4, 2016

@mrocklin mrocklin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

A cursory look through this seems good to me, although I haven't thoroughly reviewed the tricky atop inference bits.

Comment thread dask/array/core.py Outdated
def _nonempty_data(x):
if isinstance(x, Array):
return np.ones((1,) * x.ndim, dtype=x.dtype)
return x

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does this work with struct dtypes?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes, it just writes int/float/str 1s in all fields.

@jcrist

jcrist commented Nov 4, 2016

Copy link
Copy Markdown
Member Author

I think we can add Array._meta..., and share the same impl of _emulate and extract_meta between dataframe and array.

I'd slightly in favor of keeping them separate. The number of places where we emulate an operation in dask.array is very small, and the implementation is simple. In most cases array/dataframe are not mixable, so sharing the functionality seems less important to me.

@shoyer

shoyer commented Nov 4, 2016 •

Copy link
Copy Markdown
Member

I would also be in favor of keeping Array.dtype separate from DataFrame._meta. dtypes in NumPy are much easier to infer/propagate than in pandas.

This approach does seems pretty sensible. I'm pleased to see how easy it was to make dtypes mandatory.

For dtype inference in atop -- am I correct in understanding that the issue is that there is no easy way to do the NumPy array version of atop? Maybe you could make it work by constructing dummy dask arrays, calling atop itself with an invalid dtype, and then calling .compute() with the debugging/single-threaded executor to get a numpy array with the appropriate type. This gets pretty ugly though, so I am not too wedded to this approach.

@jcrist

jcrist commented Nov 7, 2016

Copy link
Copy Markdown
Member Author

For dtype inference in atop -- am I correct in understanding that the issue is that there is no easy way to do the NumPy array version of atop? Maybe you could make it work by constructing dummy dask arrays, calling atop itself with an invalid dtype, and then calling .compute() with the debugging/single-threaded executor to get a numpy array with the appropriate type. This gets pretty ugly though, so I am not too wedded to this approach.

I thought about that, but am not happy with that approach for a few reasons:

  • It's comparatively heavy (need to create scheduler state, run scheduler, get result)
  • The semantics of atop rely more on the shape/dimensions of the blocks than the simpler map_blocks. As such, I feel that inference will fail more often than may be worthwhile. Making all dimensions 1 would cover many cases though, so this might not a big deal.

Overall, I'm comfortable saying that atop is low-level enough that we make users specify dtype directly. I do realize that this is a breaking change though, but I wouldn't trust the inference to work well enough for any users who weren't specifying dtype directly in atop already. Happy to change though if others disagree.

@shoyer

shoyer commented Nov 7, 2016

Copy link
Copy Markdown
Member

I agree, it's not too much trouble to ask for an output dtype in most cases.

On Mon, Nov 7, 2016 at 10:32 AM, Jim Crist [email protected] wrote:

For dtype inference in atop -- am I correct in understanding that the
issue is that there is no easy way to do the NumPy array version of atop?
Maybe you could make it work by constructing dummy dask arrays, calling
atop itself with an invalid dtype, and then calling .compute() with the
debugging/single-threaded executor to get a numpy array with the
appropriate type. This gets pretty ugly though, so I am not too wedded to
this approach.

I thought about that, but am not happy with that approach for a few
reasons:

  • It's comparatively heavy (need to create scheduler state, run
    scheduler, get result)
  • The semantics of atop rely more on the shape/dimensions of the
    blocks than the simpler map_blocks. As such, I feel that inference
    will fail more often than may be worthwhile. Making all dimensions 1
    would cover many cases though, so this might not a big deal.

Overall, I'm comfortable saying that atop is low-level enough that we
make users specify dtype directly. I do realize that this is a breaking
change though, but I wouldn't trust the inference to work well enough for
any users who weren't specifying dtype directly in atop already. Happy to
change though if others disagree.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
#1755 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/ABKS1uIAVS2wNAQVVHbmWzDMY031D9B6ks5q726-gaJpZM4KotXs
.

@jcrist jcrist changed the title [WIP] Mandatory dtypes on dask-array Mandatory dtypes on dask-array Nov 7, 2016
@jcrist

jcrist commented Nov 7, 2016

Copy link
Copy Markdown
Member Author

I think this is good to go now.

@mrocklin
mrocklin merged commit bd30288 into dask:master Nov 8, 2016
@jcrist
jcrist deleted the array-dtypes branch November 10, 2016 00:01
@sinhrks sinhrks added this to the 0.13.0 milestone Jan 4, 2017
martindurant pushed a commit to martindurant/dask that referenced this pull request Sep 11, 2020
martindurant added a commit that referenced this pull request Sep 11, 2020
kumarprabhu1988 pushed a commit to kumarprabhu1988/dask that referenced this pull request Oct 29, 2020
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.

4 participants