Skip to content

Commit 5d6a734

Browse files
authored
override the signature of plotfunc (#4359)
* override the signature of plotfunc * update whats-new.rst * explain the reasons for the signature dummy
1 parent a6eccfa commit 5d6a734

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

doc/whats-new.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ Bug fixes
7777
and :py:meth:`DataArray.str.wrap` (:issue:`4334`). By `Mathias Hauser <https://github.com/mathause>`_.
7878
- Fixed overflow issue causing incorrect results in computing means of :py:class:`cftime.datetime`
7979
arrays (:issue:`4341`). By `Spencer Clark <https://github.com/spencerkclark>`_.
80+
- fix the signature of the plot methods. (:pull:`4359`) By `Justus Magin <https://github.com/keewis>`_.
8081
- Fix :py:func:`xarray.apply_ufunc` with ``vectorize=True`` and ``exclude_dims`` (:issue:`3890`).
8182
By `Mathias Hauser <https://github.com/mathause>`_.
8283
- Fix `KeyError` when doing linear interpolation to an nd `DataArray`

xarray/plot/plot.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,15 @@ def step(self, *args, **kwargs):
463463
return step(self._da, *args, **kwargs)
464464

465465

466+
def override_signature(f):
467+
def wrapper(func):
468+
func.__wrapped__ = f
469+
470+
return func
471+
472+
return wrapper
473+
474+
466475
def _plot2d(plotfunc):
467476
"""
468477
Decorator for common 2d plotting logic
@@ -572,6 +581,16 @@ def _plot2d(plotfunc):
572581
# Build on the original docstring
573582
plotfunc.__doc__ = f"{plotfunc.__doc__}\n{commondoc}"
574583

584+
# plotfunc and newplotfunc have different signatures:
585+
# - plotfunc: (x, y, z, ax, **kwargs)
586+
# - newplotfunc: (darray, x, y, **kwargs)
587+
# where plotfunc accepts numpy arrays, while newplotfunc accepts a DataArray
588+
# and variable names. newplotfunc also explicitly lists most kwargs, so we
589+
# need to shorten it
590+
def signature(darray, x, y, **kwargs):
591+
pass
592+
593+
@override_signature(signature)
575594
@functools.wraps(plotfunc)
576595
def newplotfunc(
577596
darray,

0 commit comments

Comments
 (0)