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

override the signature of plotfunc #4359

Merged
merged 6 commits into from
Sep 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/whats-new.rst
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ Bug fixes
and :py:meth:`DataArray.str.wrap` (:issue:`4334`). By `Mathias Hauser <https://github.com/mathause>`_.
- Fixed overflow issue causing incorrect results in computing means of :py:class:`cftime.datetime`
arrays (:issue:`4341`). By `Spencer Clark <https://github.com/spencerkclark>`_.
- fix the signature of the plot methods. (:pull:`4359`) By `Justus Magin <https://github.com/keewis>`_.
- Fix :py:func:`xarray.apply_ufunc` with ``vectorize=True`` and ``exclude_dims`` (:issue:`3890`).
By `Mathias Hauser <https://github.com/mathause>`_.
- Fix `KeyError` when doing linear interpolation to an nd `DataArray`
Expand Down
19 changes: 19 additions & 0 deletions xarray/plot/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,15 @@ def step(self, *args, **kwargs):
return step(self._da, *args, **kwargs)


def override_signature(f):
def wrapper(func):
func.__wrapped__ = f

return func

return wrapper


def _plot2d(plotfunc):
"""
Decorator for common 2d plotting logic
Expand Down Expand Up @@ -572,6 +581,16 @@ def _plot2d(plotfunc):
# Build on the original docstring
plotfunc.__doc__ = f"{plotfunc.__doc__}\n{commondoc}"

# plotfunc and newplotfunc have different signatures:
# - plotfunc: (x, y, z, ax, **kwargs)
# - newplotfunc: (darray, x, y, **kwargs)
# where plotfunc accepts numpy arrays, while newplotfunc accepts a DataArray
# and variable names. newplotfunc also explicitly lists most kwargs, so we
# need to shorten it
def signature(darray, x, y, **kwargs):
pass

@override_signature(signature)
@functools.wraps(plotfunc)
def newplotfunc(
darray,
Expand Down