-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Only calculate lengths of iterable arguments to map
#6513
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like really reasonable behavior, but I want to point out a change that I wasn't expecting. The original issue was that parameter defaults were not implicitly treated as unmapped
e.g.
@task
def foo(x: int, y: int = 2)
return x + y
foo.map(x=[1, 2, 3]) # Fails since `y` is not an iterable
The writer of the task should not need to account for it being used in mapping, hence this bug fix. However, this implementation comes with an interesting side-effect where the following will succeed as well:
@task
def foo(x: int, y: int = 2)
return x + y + z
foo.map(x=[1,2,3], y=10)
The user has explicitly provided a value for y
but it is not mapped. I think this is a nice way to prevent the user from having to explicitly use unmapped
in most cases! However, it might be confusing if they intended to pass an iterable and did not get a error when it was a scalar. I think this trade-off is worth it, but we should probably get feedback from @billpalombi
Agreed, and I started down the route of implicitly marking the default arguments as unmapped (you can check out that version over here: 60f3d8b But it felt like we were just coding around our own limitations. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementation LGTM. Can you explain this behavior in the map
docstring? Is there a good place to clarify this behavior in the concepts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for tagging me in @madkinsz! I agree that the trade off is worth it. This change is definitely an improvement over the current state. I'll keep a look out for users that are confused by the implicitly unmapped values, but it seems pretty intuitive to me.
5f34463
to
82afe31
Compare
* Implicitly mark default kewyord arguments to the task function as being unmapped. * Only calculate lengths of iterable arguments to `map` * Update `map` docstring to detail new behavior * Update `map` section of task concepts
Summary
Issue #6383 calls out that a task with a default keyword argument fails when being mapped unless the task has defaulted that keyword argument to an
unmapped
value. This PR alters the waymap
works so that it only calculates the length of iterable arguments, which makes the use ofunmapped
un-needed in most cases.This does result in a change to behavior. When
map
is called without any parameters, previously it would run the task a single time, now it will fail with aMappingMissingIterable
exception. The thinking behind the exception is that if a user calls.map
without an iterable then it's no different than calling the task directly and the user is either using an incorrect way of callingmap
or the arguments they're passing are incorrect.Closes #6383
Steps Taken to QA Changes
Checklist
This pull request is:
<link to issue>
" in this Pull Request's summary section.<link to issue>
" in this Pull Request's summary section.Happy engineering!