-
Notifications
You must be signed in to change notification settings - Fork 609
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
Generator support in ExternalSource #1832
Conversation
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
!build |
CI MESSAGE: [1206920]: BUILD STARTED |
If `True`, the source will be wrapped. Otherwise, StopIteration error wil be raised | ||
when end of data is reached. This flag requires that `source` is either a collection, i.e. an | ||
iteratble object where ``iter(source)`` will return a fresh iterator on each call or a | ||
generator function. In the latter case, the generator function will be called again when more | ||
data is requried than was yielded by the function. |
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.
If `True`, the source will be wrapped. Otherwise, StopIteration error wil be raised | |
when end of data is reached. This flag requires that `source` is either a collection, i.e. an | |
iteratble object where ``iter(source)`` will return a fresh iterator on each call or a | |
generator function. In the latter case, the generator function will be called again when more | |
data is requried than was yielded by the function. | |
If ``True``, the source will be wrapped. Otherwise, ``StopIteration`` will be raised | |
when end of data is reached. This flag requires that ``source`` is either a collection, i.e. an | |
iterable object where ``iter(source)`` will return a fresh iterator on each call, or a | |
generator function. In the latter case, the generator function will be called again when more | |
data is requested than was yielded by the function. |
My suggestions:
- I'm not sure if we should call
StopIteration
"error", since it's regular python flow-control mechanism - typo in
wil
- typo in
iteratble
requried
->requested
- I'd wrap argument names etc. in double-back-ticks. It renders better, IMHO
if cycle is not None: | ||
raise ValueError("The argument `cycle` can only be specified if `source` is iterable") | ||
if not callable(source): | ||
raise TypeError("Source must be iterable or callable") | ||
raise TypeError("Source must be callable, iterable or a perameterless generator function") |
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.
raise TypeError("Source must be callable, iterable or a perameterless generator function") | |
raise TypeError("Source must be callable, iterable or a parameterless generator function") |
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.
Some typos found, other than that LGTM.
I guess that using functools.partial
we might be able to let the generator function have some arguments (prolly another argument to the op might be neccesary there), but that's for consideration and another PR
def _is_generator_function(x): | ||
"""Checks whether x is a generator function or a callable object | ||
where __call__ is a generator function""" | ||
import inspect |
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.
Why can't we import it globally?
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.
We can.
def _get_callback_from_source(source, cycle): | ||
iterable = False | ||
if source is not None: | ||
import inspect |
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.
As above
pipe.set_outputs(fn.external_source(gen, cycle = True)) | ||
pipe.build() | ||
|
||
for cycle in range(3): |
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.
You can add a negative test for a generator and cycle set to True.
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.
Done
3829127
to
08dfccb
Compare
Signed-off-by: Michał Zientkiewicz <mzient@gmail.com>
08dfccb
to
7371412
Compare
!build |
CI MESSAGE: [1207039]: BUILD FAILED |
CI MESSAGE: [1207088]: BUILD STARTED |
CI MESSAGE: [1207088]: BUILD PASSED |
Why we need this PR?
Pick one, remove the rest
What happened in this PR?
Fill relevant points, put NA otherwise. Replace anything inside []
_get_callback_from_source
- see if there's some use case not handled or badly handledJIRA TASK: N/A