You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
No objection to having func_args and func_kwargs. Personally I like also
using *args and **kwargs. I think that this is intuitive and convenient
for users and so I would prefer not to see it dropped.
On Tue, Apr 24, 2018 at 10:42 AM, jakirkham ***@***.***> wrote:
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, but they may or
may not work.
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 <#3263>
xref: #3081 <#3081>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#3437>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AASszG9Wl1ouFjR76bkJute-vAe5BGvFks5trznrgaJpZM4Th0bj>
.
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.
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.
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.
Activity
mrocklin commentedon Apr 24, 2018
jakirkham commentedon Apr 24, 2018
To be clear my objection is to
*argsand**kwargs. :)The problem with
*argsand**kwargsis they live in the same space as all the other arguments ofmap_blocksandmap_overlap*. This means that if we are ever to add another argument tomap_blocksandmap_overlapit would clash with user specified arguments to their function of the same. In fact this already happens with existing arguments.dtypeis 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
*argstomap_overlapis a bit problematic as we have to decide where they go relative todepth, 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_blocksandmap_overlapinto 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_overlapdoes not currently take*argsmrocklin commentedon Apr 24, 2018
I have found
*argsand**kwargsto 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.jakirkham commentedon Jun 12, 2018
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, andgradient. Have countless others personally that live outside this codebase. Not to mention other things like the mishandling ofkwargs( #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.