Skip to content

Improve code skimmability by adding docstring to tops of .py files #1598

Open

Description

@Sevans711

Proposed new feature or change:

New (and probably, continuing) developer experience could be improved a decent amount by including a docstring at the top of each python file. This can also help any users who utilize help to learn more about how to use the code.

Docstrings could be as simple as:

"""
File Purpose: UxDataArray class
"""

This helps to suggest there's nothing else important going on in the file; it's just all about defining the UxDataArray class.

Or, they can be more complicated, such as the one already in uxarray/core/accessors.py:

"""
Delegation-based accessor classes for UXarray groupby operations.

These classes wrap xarray's groupby/resample/etc objects and ensure that
operations return UxDataArray/UxDataset objects with preserved uxgrid.
"""

This allows you to quickly understand the purpose of the file, and also provides a nice place to include anything that isn't perfectly intuitive immediately from the file name. For example, uxarray/core/api.py currently has no docstring, so it takes a minute to realize this is the core public api, not an internal api, and not some other sort of api. A simple docstring like "File Purpose: core public api methods" would save that time and help avoid getting lost in the code.

Another good example is uxarray/core/zonal.py. When I was first exploring the code, before I read the readthedocs page, I initially thought maybe there could be a whole bunch of "zonal-related" methods. Now that I understand a bit more, I might put a docstring like:

"""
File Purpose: zonal averaging

Averages computed along one or more lines (or bands) of constant latitude.
"""

This defines what "zonal averaging" means, and clarifies that it is the entire purpose of the file; every method in this file is somehow connected to zonal averages, there's not any other type of "zonal" operation to watch out for.

Bonus benefits: these come up when applying introspection to modules directly, e.g. help(ux.core.accessors) includes the docstring above. Additionally, this matches xarray style, for example, you can import xarray as xr; help(xr.plot) or help(xr.tutorial), and you will see a description is included. Doing something like help(ux.grid) is currently sort of disappointing, there isn't any description about the basic purpose, nor any help suggesting where to look for more details.

Activity

  1. added
    documentation
    developer experience
    on Jul 21, 2026
  2. moved this from 📚 Backlog to 📝 To-Do in UXarray Developmenton Aug 13, 2026
  3. Sevans711 commented on Oct 22, 2026

    @Sevans711
    CollaboratorAuthor

    Reportback from internal discussion today: concerns were expressed about keeping signal-to-noise ratio high for top-of-file docstrings. For example, these docstrings should not be filled with any long-winded ramblings of LLMs.

    My personal understanding is that these docstrings would still be appreciated if kept concise, though, especially if explaining anything particularly unexpected within the file.

  4. erogluorhan commented on Oct 23, 2026

    @erogluorhan
    Member

    I am hesitant about doing this for the whole code base because most, if not all, of the files are already self-explanatory with their names and in what namepsace they are present, e.g. plot/contour.py. Such docstrings might only need to be tackled if actually needed.

    That said, if there is no particular file in mind, I'd suggest that we close this as unplanned.

  5. Sevans711 commented on Oct 26, 2026

    @Sevans711
    CollaboratorAuthor

    My personal preference would still be to have this in every file, even if just a one-line docstring, but I can also understand if that's not the direction we end up going with. Some extra thoughts beyond the initial post:

    • I would argue that a one-liner that says exactly what you expect it to is not a waste of space or effort. Rather, it is a confirmation / positive signal that this file is indeed scoped exactly how you would expect; it tells you that there (probably) aren't any surprises here.
      • When most files have no docstrings, it's hard to know for sure if you're looking at one of the "the purpose is obvious" files, or one of the "not fully-self-explanatory and could benefit from a docstring, but it just hasn't been added yet" files.
    • Something that is "self-explanatory" to experienced contributors might not be self-explanatory to newcomers. Even small one-line docstrings might lower the barrier to entry for new contributors.
    • Small docstrings would have helped me while I was getting started. Especially in the examples below, but also even in other files where the other devs might describe the purpose as self-explanatory.

    To make this a bit more concrete, I surveyed the codebase for the "best" candidate files to consider here. If my points above about adding docstrings everywhere aren't particularly convincing, maybe we can just focus on these files which I think are most in need of docstrings?

    # File Why a short file docstring would help
    1 uxarray/grid/integrate.py The name suggests general integration, but the file contains no direct integration methods. It holds helpers for computing zonal face weights, and its only importer is core/zonal.py. A docstring would state that scope and point to zonal averaging.
    2 uxarray/core/zonal.py A docstring could define what "zonal" means here (averages along lines or bands of constant latitude). It would also make clear that this is the file's entire scope and that no other kind of "zonal" operation is intended.
    3 uxarray/core/api.py The name doesn't say which API this is. A docstring could clarify that it is the public API (open_grid, open_dataset, open_mfdataset, concat, ...), not an internal one.
    4 uxarray/conventions/ugrid.py The file contains only constants (lists and dicts of UGRID names and attributes). A docstring could say what "conventions" covers and that these objects are meant to be read, not modified. They are mutable, so they can be edited in place by accident, which UXarray doesn't intend to support.
    5 uxarray/grid/slice.py A docstring could clarify the scope. This file holds internal index-slicing machinery for grids, which backs .isel() and .sel() on UxDataset and UxDataArray. It is not itself user-facing.
    6 uxarray/grid/geometry.py (~1500 lines) This is a large file with a broad name. A docstring stating its purpose and scope would help contributors decide whether new code belongs here or elsewhere, without listing individual functions.
    7 Package __init__.py files (grid, core, plot, io, remap, subset, cross_sections, utils, conventions) Today help(ux.grid) and similar give no description of the subpackage's purpose. A one- or two-line docstring would make that output useful.

    (Table text is from copilot/claude, but reflects my views after some back-and-forth iteration.)

  6. erogluorhan commented on Oct 27, 2026

    @erogluorhan
    Member

    If my points above about adding docstrings everywhere aren't particularly convincing, maybe we can just focus on these files which I think are most in need of docstrings?

    Sure, it would make sense to me if you added docstrings into the files in the above table your provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    developer experiencedocumentation

    Type

    No type

    Fields

    Priority

    Low

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions