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
I couldn't find a class factory in the source and it looks like all the nodes are instantiated directlly with Stream when it should use the type of the main instance.
@martindurant, the issue with @Stream.register_api is that it will mutate the original Stream class which will impact all the instances everywere else. So it doesn't fullfill the requirement for extending a stream. For instance, if I were to override the sink method, it would mess/break the other streams. What I'm expecting is basic polymorphism.
I think I see what you are trying to do, but you face the following problem: map is a method on Stream (and defined by the map class), so that when you call .map, there is no easy way to know that this was called from within a subclass - map is not a child of your custom class and cannot be made so dynamically.
That leaves you with the two obvious paths, as you point out: come up with unique names for all node types, or allow name clashes and understand that you may clobber for all streams. For your example, I'm not totally sure how you expect the method draw to be called, since it doesn't actually take any events. All existing nodes are implemented at the update (incoming events) and emit (outgoing events) points.
However, another possibility, is maybe what you are actually after. You can use Stream.connect to tie together nodes without using the register_api route. For example, the following are equivalent, where the second and third versions avoid using the automatically created method.
map is a method on Stream (and defined by the map class), so that when you call .map, there is no easy way to know that this was called from within a subclass
map is a wrapped function. The class/subclass is available at the time it's registered and called :
I haven't had a chance yet to understand what difference your alternate decorator has, but please do propose a PR to demonstrate it! I daresay there are others who have thought along these lines and not known how to proceed.
Activity
martindurant commentedon Dec 5, 2021
It would work with
@Stream.register_api- will that suffice?florentbr commentedon Dec 6, 2021
@martindurant, the issue with
@Stream.register_apiis that it will mutate the originalStream classwhich will impact all the instances everywere else. So it doesn't fullfill the requirement for extending a stream. For instance, if I were to override thesinkmethod, it would mess/break the other streams. What I'm expecting is basic polymorphism.florentbr commentedon Dec 6, 2021
It's called subclassing in the
pandasdocumentation :https://pandas.pydata.org/docs/development/extending.html#subclassing-pandas-data-structures
martindurant commentedon Dec 6, 2021
I think I see what you are trying to do, but you face the following problem:
mapis a method onStream(and defined by themapclass), so that when you call.map, there is no easy way to know that this was called from within a subclass -mapis not a child of your custom class and cannot be made so dynamically.That leaves you with the two obvious paths, as you point out: come up with unique names for all node types, or allow name clashes and understand that you may clobber for all streams. For your example, I'm not totally sure how you expect the method
drawto be called, since it doesn't actually take any events. All existing nodes are implemented at theupdate(incoming events) andemit(outgoing events) points.However, another possibility, is maybe what you are actually after. You can use
Stream.connectto tie together nodes without using the register_api route. For example, the following are equivalent, where the second and third versions avoid using the automatically created method.or
or
florentbr commentedon Dec 7, 2021
mapis a wrapped function. The class/subclass is available at the time it's registered and called :streamz/streamz/core.py
Line 161 in 7453431
The following
Stream.register_api()would adds the expected inheritance at registration :This is just an example to demonstrate the issue with inheritance. Don't read too much into it.
This library threats it's methods as plugings but doesn't keep track of them.
So I'd have to rewrite all the methods that are registered by
Stream.register_apito connect the nodes. It kind of defeat the purpose of inheritance.martindurant commentedon Dec 7, 2021
I haven't had a chance yet to understand what difference your alternate decorator has, but please do propose a PR to demonstrate it! I daresay there are others who have thought along these lines and not known how to proceed.
Fix Stream subclassing python-streamz#442
Fix Stream subclassing python-streamz#442
Add Stream node constructor for sub-classing python-streamz#442
Add Stream node constructor for sub-classing python-streamz#442