Skip to content

repr(da.xrs.slope) prints the whole accessor catalog instead of the tool's own info #3478

Description

@brendancol

Description

Commit 8bb7c16 (#3476/#3477) gave the .xrs accessor a categorized __repr__, so da.xrs and ds.xrs list the available operations grouped by category. That part works.

The problem shows up one level down. Evaluating a single tool without calling it, e.g. da.xrs.slope, prints the entire accessor listing again instead of information about slope:

>>> da.xrs.slope
<bound method XrsSpatialDataArrayAccessor.slope of <XrsSpatialDataArrayAccessor> xarray-spatial tools for this DataArray
call as: .xrs.<name>(...)

Plot:
    plot
Surface:
    slope, aspect, hillshade, curvature
... (the whole catalog) ...>

da.xrs.slope is a bound method. Python builds a bound method's repr as <bound method Cls.name of {repr(self)}>, and repr(self) now routes through the accessor's custom __repr__, so the full catalog ends up embedded in the bound-method repr.

Expected behavior

Evaluating da.xrs.slope should show information scoped to slope only: its call signature and docstring, the same documentation help(da.xrs.slope) already surfaces. The docstring is already attached to each accessor method (see _attach_delegated_docs), so the per-tool repr can reuse it.

Steps to reproduce

import numpy as np, xarray as xr, xrspatial
da = xr.DataArray(np.ones((4, 4)), dims=['y', 'x'])
da.xrs.slope   # prints the whole accessor catalog instead of slope's info

Environment

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiAPI design and consistencybugSomething isn't working

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions