From 4b97692d9d1b1feba76b55b90df51385b9bbbbf2 Mon Sep 17 00:00:00 2001 From: Keewis Date: Thu, 20 Aug 2020 19:32:31 +0200 Subject: [PATCH 1/3] override the signature of plotfunc --- xarray/plot/plot.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/xarray/plot/plot.py b/xarray/plot/plot.py index 305405d4e5a..bc6c9ec52f9 100644 --- a/xarray/plot/plot.py +++ b/xarray/plot/plot.py @@ -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 @@ -572,6 +581,10 @@ def _plot2d(plotfunc): # Build on the original docstring plotfunc.__doc__ = f"{plotfunc.__doc__}\n{commondoc}" + def signature(darray, x, y, **kwargs): + pass + + @override_signature(signature) @functools.wraps(plotfunc) def newplotfunc( darray, From 9b7479cacfc9e9fcc75fa52a0954855d5d4e5633 Mon Sep 17 00:00:00 2001 From: Keewis Date: Thu, 20 Aug 2020 19:40:06 +0200 Subject: [PATCH 2/3] update whats-new.rst --- doc/whats-new.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/whats-new.rst b/doc/whats-new.rst index 823c3e2e1b2..60201418873 100644 --- a/doc/whats-new.rst +++ b/doc/whats-new.rst @@ -73,6 +73,7 @@ Bug fixes and :py:meth:`DataArray.str.wrap` (:issue:`4334`). By `Mathias Hauser `_. - Fixed overflow issue causing incorrect results in computing means of :py:class:`cftime.datetime` arrays (:issue:`4341`). By `Spencer Clark `_. +- fix the signature of the plot methods. (:pull:`4359`) By `Justus Magin `_. Documentation ~~~~~~~~~~~~~ From 1154d199d0ba5b42e02921e8eb8eee557d0dc8f6 Mon Sep 17 00:00:00 2001 From: Keewis Date: Tue, 25 Aug 2020 15:12:35 +0200 Subject: [PATCH 3/3] explain the reasons for the signature dummy --- xarray/plot/plot.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/xarray/plot/plot.py b/xarray/plot/plot.py index bc6c9ec52f9..0d44d5fd64a 100644 --- a/xarray/plot/plot.py +++ b/xarray/plot/plot.py @@ -581,6 +581,12 @@ 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