-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
support passing a function to combine_attrs #4896
Conversation
One thing to think about is IIUC we want to treat One option would be
|
sounds reasonable, but that would require a bigger change than just extending |
Shall we merge? |
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) |
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 @keewis
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]: import inspect
...:
...: def current_function_name():
...: frame = inspect.currentframe()
...: try:
...: caller = frame.f_back
...: name = caller.f_code.co_name
...: finally:
...: del frame
...: del caller
...:
...: return name
...:
...: def func():
...: print(current_function_name())
...:
...: def another_func():
...: print(current_function_name())
...:
...: class A:
...: def method(self):
...: print(current_function_name())
...:
...: f = func
...:
...: func()
...: another_func()
...: f()
...:
...: a = A()
...: a.method()
func
another_func
func
method With 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. |
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. |
let's merge this as-is (unless there are any comments on the current state?) and I'll add the construction of the |
Works for me. Once merged perhaps @huard or @DamienIrving can help us iterate on |
thanks for the reviews, @shoyer, @dcherian, @max-sixty |
Allowing to pass a function to
combine_attrs
is important if a user wants to do something the builtin merge strategies don't support.pre-commit run --all-files
whats-new.rst