Uh oh!
There was an error while loading. Please reload this page.
support passing a function to combine_attrs - #4896
Conversation
dcherian
commented
Feb 16, 2021
One thing to think about is IIUC we want to treat One option would be |
keewis
commented
Feb 17, 2021
sounds reasonable, but that would require a bigger change than just extending |
max-sixty
commented
Apr 18, 2021
Shall we merge? |
keewis
commented
Apr 19, 2021
not sure. There are a few questions about the signature of the user functions (see #4896 (comment) and #3891 (comment)), which I would like to answer before including this in a release (I might be wrong, but I think changing the signature after releasing is pretty hard) |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
there's two remaining issues: should we use a Also, how do we best construct that object without a lot of overhead? We need to get at least the function name, but if we pass that manually it's one more place to update when renaming something (not that we do that very often). Using In [5]: importinspect
...: ...: defcurrent_function_name():
...: frame=inspect.currentframe()
...: try:
...: caller=frame.f_back
...: name=caller.f_code.co_name
...: finally:
...: delframe
...: delcaller
...: ...: returnname
...: ...: deffunc():
...: print(current_function_name())
...: ...: defanother_func():
...: print(current_function_name())
...: ...: classA:
...: defmethod(self):
...: print(current_function_name())
...: ...: f=func
...: ...: func()
...: another_func()
...: f()
...: ...: a=A()
...: a.method()
funcanother_funcfuncmethodWith this we can only get the name of the definition so this might break for injected methods, but I guess for injected methods it would be difficult to manually pass the function name, anyways. |
shoyer
commented
May 27, 2021
Rather than introspection, I think we should try to be fully explicit about the function being called. Trying to introspect it from stack-frames is madness :) So in that case, we would need to pass down the context information from the top level functions in xarray, e.g., everything that takes a In terms of the overall interface, one other concern I have is about the information we make available to users of this API. I can imagine that they might not only want attributes but also the complete xarray objects on which the function is being called. If that's the case, then they would also need more information from the global context. |
keewis
commented
Jun 8, 2021
let's merge this as-is (unless there are any comments on the current state?) and I'll add the construction of the |
dcherian
commented
Jun 8, 2021
Works for me. Once merged perhaps @huard or @DamienIrving can help us iterate on |
keewis
commented
Jun 8, 2021
thanks for the reviews, @shoyer, @dcherian, @max-sixty |
Allowing to pass a function to
combine_attrsis important if a user wants to do something the builtin merge strategies don't support.pre-commit run --all-fileswhats-new.rst