Skip to content

Improving map_blocks/map_overlap #3437

Open

Description

@jakirkham

Currently the map_blocks/map_overlap interfaces provide one main way to pass arguments and keyword arguments that is a variadic **kwargs argument. However if one has keyword arguments that overlap with those that map_blocks/map_overlap take, then one is either not able to pass them or has to write a shim function to map the arguments to something that won't conflict. With variadic arguments, one can pass them along to map_blocks (not to map_overlap), but they may or may not work. In the case of map_overlap, variadic arguments are simply unsupported.

This could be fixed by adding two arguments to map_blocks/map_overlap. Namely func_args and func_kwargs. These would be regular arguments taking a sequence and a mapping respectively. Also these would not be treated as non-Dask collection arguments. In the implementation detail, these would be unpacked in the function call. This would avoid confusion caused by trying to have these arguments live alongside arguments to map_blocks/map_overlap. Longer term, the old strategy of passing arguments could be deprecated and dropped by 1.0.

xref: #3263
xref: #3081

Activity

  1. mrocklin commented on Apr 24, 2018

    @mrocklin
    Member
  2. jakirkham commented on Apr 24, 2018

    @jakirkham
    MemberAuthor

    To be clear my objection is to *args and **kwargs. :)

    The problem with *args and **kwargs is they live in the same space as all the other arguments of map_blocks and map_overlap*. This means that if we are ever to add another argument to map_blocks and map_overlap it would clash with user specified arguments to their function of the same. In fact this already happens with existing arguments. dtype is one of these (many NumPy functions take it and we use it here too). In these cases, the user is stuck making some sort of wrapper function to bridge this problem effectively coming up with the same solution proposed in this issue, but in a per function way in user code. IMHO would be better to just solve this once at the library level.

    Adding *args to map_overlap is a bit problematic as we have to decide where they go relative to depth, which is a required positional argument. Independently there is a question of what variadic positional arguments mean here and what might need to accompany them, which can be saved for other issues.

    If we don't like the original proposal, another option would be to turn map_blocks and map_overlap into decorators instead. This would allow arguments to the function to be simply applied in second call. Has the advantage of nice readability and potentially the ability to easily reuse the function. Not sure of an easy deprecation path for this case though.

    * Note: map_overlap does not currently take *args

  3. mrocklin commented on Apr 24, 2018

    @mrocklin
    Member

    I have found *args and **kwargs to be very convenient both for myself as a developer and for users as I work with them using Dask. I understand the concerns about overlapping with dask-specific keywords. I find the user convenience to be large enough to overwhelm this concern, at least by my metric.

  4. jakirkham commented on Jun 12, 2018

    @jakirkham
    MemberAuthor

    Sure these are convenient things generally, but not in there current formulation. In fact because of the current formulation one spends a fair bit of time writing trivial kernel functions to shoehorn in the arguments correctly. Here are a few examples from our own codebase piecewise, apply_along_axis, and gradient. Have countless others personally that live outside this codebase. Not to mention other things like the mishandling of kwargs ( #3263 ), which also calls for similar trivial kernel functions. Having distinct arguments for the wrapper from the function (instead of comingling them) would cutdown boilerplate, improve user experience, and improve maintainability.

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

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