Skip to content

Document meta kwarg in map_blocks and map_overlap.#6763

Merged
TomAugspurger merged 4 commits intodask:masterfrom
pentschev:map-functions-meta-docs
Oct 27, 2020
Merged

Document meta kwarg in map_blocks and map_overlap.#6763
TomAugspurger merged 4 commits intodask:masterfrom
pentschev:map-functions-meta-docs

Conversation

@pentschev
Copy link
Member

This should address #6690 partially, documenting how/when one should need meta= in map_blocks and map_overlap, as well as providing some very simple examples.

Copy link
Member

@quasiben quasiben left a comment

Choose a reason for hiding this comment

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

Thank you @pentschev for adding these updates! I left a few small typo comments

@pentschev
Copy link
Member Author

@quasiben everything should be addressed in 67ce0dc .

@pentschev pentschev changed the title Documenta meta kwarg in map_blocks and map_overlap. Document meta kwarg in map_blocks and map_overlap. Oct 22, 2020
@pentschev
Copy link
Member Author

cc @TomAugspurger @oarcher for awareness.

@quasiben
Copy link
Member

LGTM! Thanks @pentschev. I'll wait for @TomAugspurger before merging

Comment on lines +456 to +457
Note that this function will attempt to automatically determine the output
array type before computing it, please refer to the ``meta`` keyword argument
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Note that this function will attempt to automatically determine the output
array type before computing it, please refer to the ``meta`` keyword argument
Note that ``map_blocks`` will attempt to automatically determine the output
array type by calling ``func`` on 0-d versions of the inputs. Please refer to the ``meta`` keyword argument

Might have made that line too long.

will be determined by a hash of the arguments.
meta : array-like, optional
The ``meta`` of the output array, when specified is expected to be an
array of the same type of that returned when calling ``.compute()`` on
Copy link
Member

Choose a reason for hiding this comment

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

Same type and dtype?

Comment on lines +491 to +492
0-d array. It's important to ensure that ``func`` can successfully complete
computation without raising exceptions when 0-d is passed to it. If the
Copy link
Member

Choose a reason for hiding this comment

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

It may not be feasible for the user to write func to work on 0-d arrays. So perhaps rephrase this as something like "Consider providing meta if your func does not work on 0-d arrays are has expensive side-effects."

0-d array. It's important to ensure that ``func`` can successfully complete
computation without raising exceptions when 0-d is passed to it. If the
output type is known beforehand (e.g., ``np.ndarray``, ``cupy.ndarray``),
an empty array of such type can be passed, for example: ``meta=np.array(())``.
Copy link
Member

Choose a reason for hiding this comment

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

Does the dtype need to mach, or just the type?

dask.array<increment, shape=(100,), dtype=int64, chunksize=(10,), chunktype=numpy.ndarray>

For functions that may not handle 0-d arrays, it's also possible to specify
``meta`` with an empty array matching the type of the expected result. In
Copy link
Member

Choose a reason for hiding this comment

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

"type and dtype"

@pentschev
Copy link
Member Author

@TomAugspurger I believe all your suggestions are addressed in ba212ec , please take another look when you have a chance.

Copy link
Member

@TomAugspurger TomAugspurger left a comment

Choose a reason for hiding this comment

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

LGTM once the doctest issues are resolved.

Comment on lines +628 to +629
>>> da.map_blocks(lambda x: x[2], rs.random(5, dtype=dt), meta=cupy.array((), dtype=dt))
dask.array<lambda, shape=(5,), dtype=float64, chunksize=(5,), chunktype=cupy.ndarray>
Copy link
Member

Choose a reason for hiding this comment

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

Comment on lines +2308 to +2310
>>> y
dask.array<_trim, shape=(4, 4), dtype=float64, chunksize=(2, 2), chunktype=cupy.ndarray>
>>> y.compute()
Copy link
Member

Choose a reason for hiding this comment

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

Another pair of skips needed I think.

Comment on lines +675 to +678
>>> y = d.map_overlap(lambda x: x + x[2], depth=1, meta=cupy.array(()))
>>> y
dask.array<_trim, shape=(4, 4), dtype=float64, chunksize=(2, 2), chunktype=cupy.ndarray>
>>> y.compute()
Copy link
Member

Choose a reason for hiding this comment

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

More doctest skips.

@pentschev
Copy link
Member Author

Thanks @TomAugspurger , I had no idea that we could parse docs with doctests, that's super neat!

Running that locally I found some mistakes and added the skips in bff4584, hopefully it will succeed now.

@pentschev
Copy link
Member Author

Everything passed now, could you take another look when you have a chance @TomAugspurger ?

@TomAugspurger TomAugspurger merged commit 0ca7704 into dask:master Oct 27, 2020
@TomAugspurger
Copy link
Member

Thanks!

@pentschev
Copy link
Member Author

Thanks for reviews and merging @TomAugspurger !

@pentschev pentschev deleted the map-functions-meta-docs branch October 27, 2020 11:08
@oarcher
Copy link

oarcher commented Oct 27, 2020

Many thanks @pentschev and @TomAugspurger , the documentation is now as I would have like to be !

kumarprabhu1988 pushed a commit to kumarprabhu1988/dask that referenced this pull request Oct 29, 2020
* Documenta `meta` kwarg in `map_blocks` and `map_overlap`.

* Small fixes to ``meta`` text

* Document using `dtype` with `meta` in `map_blocks`

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants