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

add support for nested accessors in documenter #108

Merged

Conversation

fraserdominicdavid
Copy link
Contributor

Move AccessorDocumenter after AccessorLevelDocumenter and inherit the latter for the modified resolve_name() method which adds support for nested accessors.

This should fix import failure warnings for nested accessors documented using the autoaccessor directive which I think is the proper directive for documenting non-callable nested accessors.

Move `AccessorDocumenter` after `AccessorLevelDocumenter` and inherit
the latter for the modified `resolve_name()` method which adds support
for nested accessors. This allows the usage of the `autoaccessor`
directive for nested accessors.
@keewis
Copy link
Collaborator

keewis commented Oct 22, 2023

as a heads-up, it has been a while since I understood what exactly the purpose of the class hierarchy is, so reviewing might take a while. To help with that, could you post a minimal example of the accessor you're trying to document that would work with this fix? The accessor itself doesn't have to actually do anything.

@fraserdominicdavid
Copy link
Contributor Author

Good day, apologies for the lack of examples.

There may be instances where a user would want to document the namespace of nested accessors to explain the general usage of the subaccessor or any other relevant information.

To demonstrate this, I would modify example.py and examples.rst from this repo as follows:

# example.py
...
class SubAccessor:
    """Relevant documentation about SubAccessor shall be placed here.
    
    For instance, providing a general description to the namespace."""
    def __init__(self, obj):
        self._obj = obj
...

# in examples.rst, add
...
A summary of nested accessors:

.. autosummary::
   :toctree: generated/
   :template: autosummary/accessor.rst

   Example.test2.sub

In the current version, autdoc will raise a warning stating that it failed to import test2.sub from module Example. This is because the accessor.rst template uses the autoaccessor directive thereby using the AccessorDocumenter class. However, this documenter has not inherited the modified resolve_name() method which adds support to nested accessors.

This PR makes it so that the documenter also inherits the modified resolve_name() method. This would allow autodoc to generate properly, however, I don't know why Example.test2.sub's autosummary description is generated as alias of SubAccessor when it should instead be Relevant documentation about SubAccessor shall be placed here..

In the end, this may just be a misuse of the autoaccessor directive from my end, so if this is not the intended use of the autoaccessor directive and the corresponding template, then please feel free to reject this PR.

@keewis
Copy link
Collaborator

keewis commented Dec 22, 2023

apologies for dropping the ball here. It took me a while to fully understand the change, but I agree that it makes sense if we want to support nested accessors (which I'd say is pretty untypical in itself).

For my own sake, I'll also note how the accessor template is typically used: most if not all of the templates were taken from the pandas documentation (rendered version). Here's an example for the pages this creates here: Series.cat (though obviously they don't deal with nested accessors).

We might need to add this to the docs at some point (in a different PR, though).

@keewis keewis closed this Dec 22, 2023
@keewis keewis reopened this Dec 22, 2023
@keewis keewis merged commit c0acf6d into xarray-contrib:main Dec 22, 2023
35 checks passed
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.

2 participants