From 8d5d566394ba701b80ffdf3c2f9ff42b3bb25073 Mon Sep 17 00:00:00 2001 From: David Mrva Date: Fri, 19 Jun 2020 22:01:01 +0100 Subject: [PATCH 1/5] put back examples as doc string variable to ensure that the correct examples are printed in the docs --- pandas/core/series.py | 44 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 27 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index cab8dd133b579..9899535cd5e96 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1408,8 +1408,7 @@ def to_string( @doc( klass=_shared_doc_kwargs["klass"], examples=dedent( - """ - Examples + """Examples -------- >>> s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal") >>> print(s.to_markdown()) @@ -1419,6 +1418,21 @@ def to_string( | 1 | pig | | 2 | dog | | 3 | quetzal | + + Output markdown with a tabulate option. + + >>> print(s.to_markdown(tablefmt="grid")) + +----+----------+ + | | animal | + +====+==========+ + | 0 | elk | + +----+----------+ + | 1 | pig | + +----+----------+ + | 2 | dog | + +----+----------+ + | 3 | quetzal | + +----+----------+ """ ), ) @@ -1445,31 +1459,7 @@ def to_markdown( str {klass} in Markdown-friendly format. - Examples - -------- - >>> s = pd.Series(["elk", "pig", "dog", "quetzal"], name="animal") - >>> print(s.to_markdown()) - | | animal | - |---:|:---------| - | 0 | elk | - | 1 | pig | - | 2 | dog | - | 3 | quetzal | - - Output markdown with a tabulate option. - - >>> print(s.to_markdown(tablefmt="grid")) - +----+----------+ - | | animal | - +====+==========+ - | 0 | elk | - +----+----------+ - | 1 | pig | - +----+----------+ - | 2 | dog | - +----+----------+ - | 3 | quetzal | - +----+----------+ + {examples} """ return self.to_frame().to_markdown(buf, mode, **kwargs) From 10dca862bd45d59349f120b3d1518ad1ef7054d3 Mon Sep 17 00:00:00 2001 From: David Mrva Date: Fri, 19 Jun 2020 22:35:26 +0100 Subject: [PATCH 2/5] move the use of the doc decorator to the right place --- pandas/core/frame.py | 3 +-- pandas/core/generic.py | 6 ------ 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 39ca7ed47f7fa..b7c362a2094ac 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -3951,8 +3951,7 @@ def align( def set_axis(self, labels, axis: Axis = 0, inplace: bool = False): return super().set_axis(labels, axis=axis, inplace=inplace) - @Substitution(**_shared_doc_kwargs) - @Appender(NDFrame.reindex.__doc__) + @doc(NDFrame.reindex, **_shared_doc_kwargs) @rewrite_axis_style_signature( "labels", [ diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 701909c9df857..13c4243263d55 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4213,12 +4213,6 @@ def sort_values( """ raise AbstractMethodError(self) - @doc( - klass=_shared_doc_kwargs["klass"], - axes=_shared_doc_kwargs["axes"], - optional_labels="", - optional_axis="", - ) def reindex(self: FrameOrSeries, *args, **kwargs) -> FrameOrSeries: """ Conform {klass} to new index with optional filling logic. From 57f8dc16420faf02d049b6b11687730b5f3cd859 Mon Sep 17 00:00:00 2001 From: David Mrva Date: Fri, 19 Jun 2020 22:44:21 +0100 Subject: [PATCH 3/5] removed white spaces from blank lines --- pandas/core/series.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 9899535cd5e96..60d451a0bd2c9 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1418,9 +1418,9 @@ def to_string( | 1 | pig | | 2 | dog | | 3 | quetzal | - + Output markdown with a tabulate option. - + >>> print(s.to_markdown(tablefmt="grid")) +----+----------+ | | animal | From c3b44f125f0a3618064092e9741fd06a53630935 Mon Sep 17 00:00:00 2001 From: David Mrva Date: Sat, 20 Jun 2020 09:45:15 +0100 Subject: [PATCH 4/5] fix dictionary syntax in formatted doc strings --- pandas/core/generic.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 13c4243263d55..44b0d8f9a1424 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -4283,8 +4283,8 @@ def reindex(self: FrameOrSeries, *args, **kwargs) -> FrameOrSeries: Create a dataframe with some fictional data. >>> index = ['Firefox', 'Chrome', 'Safari', 'IE10', 'Konqueror'] - >>> df = pd.DataFrame({{'http_status': [200, 200, 404, 404, 301], - ... 'response_time': [0.04, 0.02, 0.07, 0.08, 1.0]}}, + >>> df = pd.DataFrame(dict(http_status=[200, 200, 404, 404, 301], + ... response_time=[0.04, 0.02, 0.07, 0.08, 1.0]), ... index=index) >>> df http_status response_time @@ -4355,7 +4355,7 @@ def reindex(self: FrameOrSeries, *args, **kwargs) -> FrameOrSeries: of dates). >>> date_index = pd.date_range('1/1/2010', periods=6, freq='D') - >>> df2 = pd.DataFrame({{"prices": [100, 101, np.nan, 100, 89, 88]}}, + >>> df2 = pd.DataFrame(dict(prices=[100, 101, np.nan, 100, 89, 88]), ... index=date_index) >>> df2 prices From f0cf03ac1c44c7b18c80007d336ac162a0af8416 Mon Sep 17 00:00:00 2001 From: David Mrva Date: Tue, 23 Jun 2020 22:38:57 +0100 Subject: [PATCH 5/5] resolved a failing docstring test --- pandas/core/series.py | 1 - 1 file changed, 1 deletion(-) diff --git a/pandas/core/series.py b/pandas/core/series.py index 60d451a0bd2c9..32963c6c4a6a8 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -1458,7 +1458,6 @@ def to_markdown( ------- str {klass} in Markdown-friendly format. - {examples} """ return self.to_frame().to_markdown(buf, mode, **kwargs)