-
Notifications
You must be signed in to change notification settings - Fork 14
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
Possible to avoid translating tuple
parameter values as strings, or else allow a user-supplied Translator
?
#86
Comments
We want to keep compatibility with papermill (although I agree that converting tuples into strings is an odd API choice). I'm open to extending the API so users can customize the translator, what's the use case for this? wouldn't it be easier to convert the tuple into a list before executing the notebook? |
Yeah, the papermill compatibility guarantee is understandable.
Yes, that's what I ended up doing in my case.
I think I'm hitting these surprises because I'm interacting with namespaces of parametrized notebooks, a less-common use-case. I chose I am injecting parameters and handling namespaces in calling code. One rationale is to keep file-IO logic out of the notebook logic. In tests, I pass different parameters through a notebook and assert certain namespace results. Allowing a substitute translator would probably be better than special-casing the existing translator. I figured it could be a slippery-slope if you do But a reasonable choice is also "the translator works the way that it does, we'll make sure the surprises are well-documented". It's really not that big of a deal to be limited to As an aside, I've provided more implementation details of this use-case below. DetailsFunction
|
Thanks for the detailed answer! I think we can break down the action items:
Subclassing class MyCustomClient(PloomberClient):
def translate_parameters(self, parameters):
# custom translation logic
client = MyCustomClient(...)
client.execute(...) This would imply modifying |
Thanks! It was so detailed, that I got self-conscious and folded half of it under Also, it's nearly Thanksgiving, so know our communication will likely pause abruptly. I plan to work on it a bit over the weekend, but have enough to do in dev environment setup/documentation that I won't get into the implementation details this week, I'm sure.
(3) I'll open an issue on this sometime soon, but I'll prioritize working on the current matter first. If someone else comes along and wants to work the other PR in the meantime, that's fine, too. Plan(4) Unless otherwise noted, I'll assume the following work happens in one PR. Let me know if you recommend a different grouping/sequence of work, e.g. if certain tasks should wait for a follow-up. Documentation
Modification of
|
@neelasha23: looping you so you're aware of this
That's fine, opening a draft PR won't create any noise
you can tag me and @neelasha23, she'll be reviewing your code as well
Please add an "added in version" in the docstring for the new
we can use
Unsure about this, where in the codebase are we calling the translate parameters? I'm tempted to keep those as is since calling
Fair point. I think let's leave this point out of the initial work. We can think of ways for users to call
Good catch. If you feel like there are missing unit tests, please add them. This can be the first thing to tackle, as it'll ensure you that your changes aren't breaking existing functionality.
Right I hope I didn't miss anything important! Feel free to tag me in your draft PR if you have questions |
Thanks for the thorough response. I created a draft PR, so I'll continue the discussion over there and ping you both as needed for clarification. First I'll establish a rough scope, set up my environment, and write tests covering existing subclass usage as needed, before getting into the actual implementation. |
sounds good! |
It looks like time has gotten away from me here, so I figured I'd chime in to say I'm still alive. I haven't gotten around to the implementation, though I do still intend to, and would like to put time into it this month. If any passers-by see this and are eager to work on this themselves, just @ me and I'll try to respond promptly. |
Parametrizing a notebook on
parameters={"list_param": [0,1], "tuple_param": (0,1)}
will result inlist_param
value being injected as a list, but thetuple_param
value being injected as the stringified representation of atuple
, e.g."(0, 1)"
(literally with the quotes). I understand thatploomber-engine
strives to match thepapermill
API, so maybe this is intentional to maintain that compatibility, but is there a chance for the parameter translator to faithfully inject tuples?Maybe a more sensible request would be to allow the user to pass a custom
Translator
toPloomberClient
, which could pass the customTranslator
subclass toparametrize_notebook
(below), allowing the user to customize behavior, in the case that it is desired to mimic thepapermill
API surface by default?Contents of
translate
Here we see that
tuple
falls through to the "last resort" translator which stringifies it.ploomber-engine/src/ploomber_engine/_translator.py
Lines 76 to 95 in e00bdc2
Abbreviated contents of
parametrize_notebook
ploomber-engine/src/ploomber_engine/_util.py
Lines 72 to 73 in e00bdc2
ploomber-engine/src/ploomber_engine/_util.py
Lines 92 to 94 in e00bdc2
The text was updated successfully, but these errors were encountered: