From 1089f01a6fe71ef1b7761bcf2cd3e7bc8dc0b061 Mon Sep 17 00:00:00 2001 From: Micael Jarniac Date: Tue, 12 Jan 2021 23:20:52 -0300 Subject: [PATCH 1/6] BUG: Placeholders not being filled on docstrings --- pandas/core/generic.py | 2 ++ pandas/util/_decorators.py | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0daeed0e393e6..991bbb676ed95 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9527,6 +9527,7 @@ def truncate( return result @final + @doc(klass=_shared_doc_kwargs["klass"]) def tz_convert( self: FrameOrSeries, tz, axis=0, level=None, copy: bool_t = True ) -> FrameOrSeries: @@ -10488,6 +10489,7 @@ def prod( product = prod + @doc() def mad(self, axis=None, skipna=None, level=None): """ {desc} diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index d002e8a4ebd43..2de22b1f0f85b 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -375,7 +375,7 @@ def decorator(decorated: F) -> F: decorated.__doc__ = "".join( [ component.format(**params) - if isinstance(component, str) + if isinstance(component, str) and params != {} else dedent(component.__doc__ or "") for component in docstring_components ] From ea7bc4781337f91bf0ca059108abed0ffcfe0ab0 Mon Sep 17 00:00:00 2001 From: Micael Jarniac Date: Tue, 12 Jan 2021 23:28:26 -0300 Subject: [PATCH 2/6] BUG: Placeholders not being filled on docstrings --- doc/source/whatsnew/v1.2.1.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/source/whatsnew/v1.2.1.rst b/doc/source/whatsnew/v1.2.1.rst index 36b4b4fa77c4a..71850e99b5913 100644 --- a/doc/source/whatsnew/v1.2.1.rst +++ b/doc/source/whatsnew/v1.2.1.rst @@ -28,6 +28,7 @@ Fixed regressions - Fixed regression in :meth:`DataFrame.replace` raising ``ValueError`` when :class:`DataFrame` has dtype ``bytes`` (:issue:`38900`) - Fixed regression in :meth:`DataFrameGroupBy.diff` raising for ``int8`` and ``int16`` columns (:issue:`39050`) - Fixed regression that raised ``AttributeError`` with PyArrow versions [0.16.0, 1.0.0) (:issue:`38801`) +- Fixed regression that caused templated docstrings to not get parsed (:issue:`39115`) - - From 3e655dc752436d09ff2aaee11983890655547447 Mon Sep 17 00:00:00 2001 From: Micael Jarniac Date: Wed, 13 Jan 2021 11:38:26 -0300 Subject: [PATCH 3/6] Revert "BUG: Placeholders not being filled on docstrings" This reverts commit ea7bc4781337f91bf0ca059108abed0ffcfe0ab0. --- doc/source/whatsnew/v1.2.1.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/whatsnew/v1.2.1.rst b/doc/source/whatsnew/v1.2.1.rst index 71850e99b5913..36b4b4fa77c4a 100644 --- a/doc/source/whatsnew/v1.2.1.rst +++ b/doc/source/whatsnew/v1.2.1.rst @@ -28,7 +28,6 @@ Fixed regressions - Fixed regression in :meth:`DataFrame.replace` raising ``ValueError`` when :class:`DataFrame` has dtype ``bytes`` (:issue:`38900`) - Fixed regression in :meth:`DataFrameGroupBy.diff` raising for ``int8`` and ``int16`` columns (:issue:`39050`) - Fixed regression that raised ``AttributeError`` with PyArrow versions [0.16.0, 1.0.0) (:issue:`38801`) -- Fixed regression that caused templated docstrings to not get parsed (:issue:`39115`) - - From 050509c8b4b816f649c7cc816b4eb9d40cd723cc Mon Sep 17 00:00:00 2001 From: Micael Jarniac Date: Wed, 13 Jan 2021 16:09:59 -0300 Subject: [PATCH 4/6] BUG: str.__doc__ ending up on final documentation --- pandas/util/_decorators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 2de22b1f0f85b..05d7b8434ee52 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -374,8 +374,8 @@ def decorator(decorated: F) -> F: # formatting templates and concatenating docstring decorated.__doc__ = "".join( [ - component.format(**params) - if isinstance(component, str) and params != {} + (component.format(**params) if params != {} else component) + if isinstance(component, str) else dedent(component.__doc__ or "") for component in docstring_components ] From b17d31271be979f1ef1d043ea4c0fe1bc919c0f0 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Fri, 15 Jan 2021 20:41:28 +0000 Subject: [PATCH 5/6] temp fix for Series.mad and DataFrame.mad --- pandas/core/generic.py | 4 +--- pandas/util/_decorators.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 0a646c43ad4d1..b50da014aa98a 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -9546,7 +9546,6 @@ def truncate( return result @final - @doc(klass=_shared_doc_kwargs["klass"]) def tz_convert( self: FrameOrSeries, tz, axis=0, level=None, copy: bool_t = True ) -> FrameOrSeries: @@ -10508,7 +10507,6 @@ def prod( product = prod - @doc() def mad(self, axis=None, skipna=None, level=None): """ {desc} @@ -10590,7 +10588,7 @@ def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): cls.all = all # type: ignore[assignment] @doc( - NDFrame.mad, + NDFrame.mad.__doc__, desc="Return the mean absolute deviation of the values " "over the requested axis.", name1=name1, diff --git a/pandas/util/_decorators.py b/pandas/util/_decorators.py index 05d7b8434ee52..d002e8a4ebd43 100644 --- a/pandas/util/_decorators.py +++ b/pandas/util/_decorators.py @@ -374,7 +374,7 @@ def decorator(decorated: F) -> F: # formatting templates and concatenating docstring decorated.__doc__ = "".join( [ - (component.format(**params) if params != {} else component) + component.format(**params) if isinstance(component, str) else dedent(component.__doc__ or "") for component in docstring_components From 133db32537bdd75217b258150a6461d50e4079d0 Mon Sep 17 00:00:00 2001 From: Simon Hawkins Date: Sat, 16 Jan 2021 12:52:32 +0000 Subject: [PATCH 6/6] add ignore for mypy --- pandas/core/generic.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index b50da014aa98a..6a80fa3e93362 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -10587,8 +10587,10 @@ def all(self, axis=0, bool_only=None, skipna=True, level=None, **kwargs): # [assignment] cls.all = all # type: ignore[assignment] + # error: Argument 1 to "doc" has incompatible type "Optional[str]"; expected + # "Union[str, Callable[..., Any]]" @doc( - NDFrame.mad.__doc__, + NDFrame.mad.__doc__, # type: ignore[arg-type] desc="Return the mean absolute deviation of the values " "over the requested axis.", name1=name1,