Skip to content
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

generate datatree methods #10146

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft

Conversation

mathause
Copy link
Collaborator

@mathause mathause commented Mar 18, 2025

  • Closes DataTree: missing methods #10015
  • Tests added
  • User visible changes (including notable bug fixes) are documented in whats-new.rst
  • New functions/methods are listed in api.rst

Add a script that generates a mixin so Dataset methods are available on DataTree. Uses inspect.signature to re-generate the call signature and a decorator so we can still use *args, **kwargs, and so we don't need to populate the method body, making the generation relatively trivial (although maybe not trivial to understand).

This is much clunkier than generate_ops or generate_aggregations. However, we cannot profit from common signatures. Thus

  • the docstring is not adapted
  • the examples are not adapted
  • the generated file needs to fixed and formatted with ruff

However, it's a fraction of the work to do this properly. I am really not sure if this is a good idea - feel free to tell me it's not!

@mathause
Copy link
Collaborator Author

The alternative is to inject everything (as in https://github.com/xarray-contrib/datatree/blob/5f3956ffe80e686dd3df54ee8cef9ff56c158e76/datatree/ops.py#L223). (Or to write all methods out, or create mixin classes that work for all data types...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DataTree: missing methods
1 participant