From 13b3fcd01a1f0e6a23381dbb7b6132f94a0b827a Mon Sep 17 00:00:00 2001 From: thoo Date: Sat, 10 Nov 2018 11:39:23 -0500 Subject: [PATCH 1/9] Fix docstrings --- pandas/core/frame.py | 40 ++++++++++++++----------------------- pandas/io/formats/format.py | 6 ++++-- 2 files changed, 19 insertions(+), 27 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index b24f79e89902a..5e75d927fa2bf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -2048,24 +2048,21 @@ def to_parquet(self, fname, engine='auto', compression='snappy', def to_string(self, buf=None, columns=None, col_space=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, sparsify=None, index_names=True, justify=None, - line_width=None, max_rows=None, max_cols=None, - show_dimensions=False): + max_rows=None, max_cols=None, show_dimensions=False, + decimal='.', line_width=None): """ Render a DataFrame to a console-friendly tabular output. - %(shared_params)s line_width : int, optional Width to wrap a line in characters. - %(returns)s - See Also -------- to_html : Convert DataFrame to HTML. Examples -------- - >>> d = {'col1' : [1, 2, 3], 'col2' : [4, 5, 6]} + >>> d = {'col1': [1, 2, 3], 'col2': [4, 5, 6]} >>> df = pd.DataFrame(d) >>> print(df.to_string()) col1 col2 @@ -2081,42 +2078,37 @@ def to_string(self, buf=None, columns=None, col_space=None, header=True, sparsify=sparsify, justify=justify, index_names=index_names, header=header, index=index, - line_width=line_width, max_rows=max_rows, max_cols=max_cols, - show_dimensions=show_dimensions) + show_dimensions=show_dimensions, + decimal=decimal, + line_width=line_width) formatter.to_string() if buf is None: result = formatter.buf.getvalue() return result - @Substitution(header='whether to print column labels, default True') + @Substitution(header='Whether to print column labels, default True') @Substitution(shared_params=fmt.common_docstring, returns=fmt.return_docstring) def to_html(self, buf=None, columns=None, col_space=None, header=True, index=True, na_rep='NaN', formatters=None, float_format=None, - sparsify=None, index_names=True, justify=None, bold_rows=True, - classes=None, escape=True, max_rows=None, max_cols=None, - show_dimensions=False, notebook=False, decimal='.', - border=None, table_id=None): + sparsify=None, index_names=True, justify=None, max_rows=None, + max_cols=None, show_dimensions=False, decimal='.', + bold_rows=True, classes=None, escape=True, + notebook=False, border=None, table_id=None): """ Render a DataFrame as an HTML table. - %(shared_params)s - bold_rows : boolean, default True - Make the row labels bold in the output + bold_rows : bool, default True + Make the row labels bold in the output. classes : str or list or tuple, default None - CSS class(es) to apply to the resulting html table - escape : boolean, default True + CSS class(es) to apply to the resulting html table. + escape : bool, default True Convert the characters <, >, and & to HTML-safe sequences. notebook : {True, False}, default False Whether the generated HTML is for IPython Notebook. - decimal : string, default '.' - Character recognized as decimal separator, e.g. ',' in Europe - - .. versionadded:: 0.18.0 - border : int A ``border=border`` attribute is included in the opening `` tag. Default ``pd.options.html.border``. @@ -2127,9 +2119,7 @@ def to_html(self, buf=None, columns=None, col_space=None, header=True, A css id is included in the opening `
` tag if specified. .. versionadded:: 0.23.0 - %(returns)s - See Also -------- to_string : Convert DataFrame to a string. diff --git a/pandas/io/formats/format.py b/pandas/io/formats/format.py index 6f64605bcf175..4c8de0856de08 100644 --- a/pandas/io/formats/format.py +++ b/pandas/io/formats/format.py @@ -88,6 +88,10 @@ Maximum number of columns to display in the console. show_dimensions : bool, default False Display DataFrame dimensions (number of rows by number of columns). + decimal : str, default '.' + Character recognized as decimal separator, e.g. ',' in Europe. + + .. versionadded:: 0.18.0 """ _VALID_JUSTIFY_PARAMETERS = ("left", "right", "center", "justify", @@ -101,8 +105,6 @@ String representation of the dataframe. """ -docstring_to_string = common_docstring + return_docstring - class CategoricalFormatter(object): From c41c1ea42957f2e8d09e7d9103a39d8f8cf6cf74 Mon Sep 17 00:00:00 2001 From: thoo Date: Sat, 10 Nov 2018 12:51:33 -0500 Subject: [PATCH 2/9] Retrigger Travis CI From 910cfea9e4bb37cf7f96491f472b68d8d6330d91 Mon Sep 17 00:00:00 2001 From: thoo Date: Sun, 11 Nov 2018 01:29:41 -0500 Subject: [PATCH 3/9] Add whatnews and to_string decimal test --- doc/source/whatsnew/v0.24.0.txt | 4 +++- pandas/tests/io/formats/test_format.py | 5 +++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index eb20d5368ef15..40ab5f1ead4f2 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -20,7 +20,8 @@ New features the user to override the engine's default behavior to include or omit the dataframe's indexes from the resulting Parquet file. (:issue:`20768`) - :meth:`DataFrame.corr` and :meth:`Series.corr` now accept a callable for generic calculation methods of correlation, e.g. histogram intersection (:issue:`22684`) - +- :func:`DataFrame.to_string` now accepts ``decimal`` as an argument, allowing +the user to use a decimal separator. (:issue:`23614`) .. _whatsnew_0240.enhancements.extension_array_operators: @@ -945,6 +946,7 @@ Other API Changes - :class:`DateOffset` attribute `_cacheable` and method `_should_cache` have been removed (:issue:`23118`) - Comparing :class:`Timedelta` to be less or greater than unknown types now raises a ``TypeError`` instead of returning ``False`` (:issue:`20829`) - :meth:`Index.hasnans` and :meth:`Series.hasnans` now always return a python boolean. Previously, a python or a numpy boolean could be returned, depending on circumstances (:issue:`23294`). +- The order of the arguments of `DataFrame.to_html` and `DataFrame.to_string` is rearranged. .. _whatsnew_0240.deprecations: diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 28aa8a92cc410..e7839dd75e26c 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -1451,6 +1451,11 @@ def test_to_string_format_na(self): '4 4.0 bar') assert result == expected + def test_to_string_decimal(self): + df = DataFrame({'A': [6.0, 3.1, 2.2]}) + expected = ' A\n0 6,0\n1 3,1\n2 2,2' + assert df.to_string(decimal=',') == expected + def test_to_string_line_width(self): df = DataFrame(123, lrange(10, 15), lrange(30)) s = df.to_string(line_width=80) From 831aa90cfb9fd86a57ae2fbfc84a5d78ae4de904 Mon Sep 17 00:00:00 2001 From: thoo Date: Sun, 11 Nov 2018 01:45:18 -0500 Subject: [PATCH 4/9] Add issue no. --- doc/source/whatsnew/v0.24.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 40ab5f1ead4f2..e9ab46a2511d3 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -946,7 +946,7 @@ Other API Changes - :class:`DateOffset` attribute `_cacheable` and method `_should_cache` have been removed (:issue:`23118`) - Comparing :class:`Timedelta` to be less or greater than unknown types now raises a ``TypeError`` instead of returning ``False`` (:issue:`20829`) - :meth:`Index.hasnans` and :meth:`Series.hasnans` now always return a python boolean. Previously, a python or a numpy boolean could be returned, depending on circumstances (:issue:`23294`). -- The order of the arguments of `DataFrame.to_html` and `DataFrame.to_string` is rearranged. +- The order of the arguments of `DataFrame.to_html` and `DataFrame.to_string` is rearranged. (:issue:`23614`) .. _whatsnew_0240.deprecations: From b87dc8cb988628c05241fb90a7d663f77c6af291 Mon Sep 17 00:00:00 2001 From: thoo Date: Sun, 11 Nov 2018 13:57:27 -0500 Subject: [PATCH 5/9] Add issue no. in test_format.py and add func ref --- doc/source/whatsnew/v0.24.0.txt | 2 +- pandas/tests/io/formats/test_format.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index e9ab46a2511d3..cf40e068114c4 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -946,7 +946,7 @@ Other API Changes - :class:`DateOffset` attribute `_cacheable` and method `_should_cache` have been removed (:issue:`23118`) - Comparing :class:`Timedelta` to be less or greater than unknown types now raises a ``TypeError`` instead of returning ``False`` (:issue:`20829`) - :meth:`Index.hasnans` and :meth:`Series.hasnans` now always return a python boolean. Previously, a python or a numpy boolean could be returned, depending on circumstances (:issue:`23294`). -- The order of the arguments of `DataFrame.to_html` and `DataFrame.to_string` is rearranged. (:issue:`23614`) +- :func:The order of the arguments of `DataFrame.to_html` and `DataFrame.to_string` is rearranged to be consistent with each other. (:issue:`23614`) .. _whatsnew_0240.deprecations: diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index e7839dd75e26c..abf0a61652d89 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -1452,6 +1452,7 @@ def test_to_string_format_na(self): assert result == expected def test_to_string_decimal(self): + #Issue #23614 df = DataFrame({'A': [6.0, 3.1, 2.2]}) expected = ' A\n0 6,0\n1 3,1\n2 2,2' assert df.to_string(decimal=',') == expected From ef872e9b06870ee22f4d8e30dfe855370609cf88 Mon Sep 17 00:00:00 2001 From: thoo Date: Sun, 11 Nov 2018 15:09:20 -0500 Subject: [PATCH 6/9] Retrigger circleci From 87297cdcc934e82b73061e0e5d776c54a39ab58b Mon Sep 17 00:00:00 2001 From: thoo Date: Sun, 11 Nov 2018 18:36:56 -0500 Subject: [PATCH 7/9] Fix flake8 E265 --- pandas/tests/io/formats/test_format.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index abf0a61652d89..cee625d5b24a8 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -1452,7 +1452,7 @@ def test_to_string_format_na(self): assert result == expected def test_to_string_decimal(self): - #Issue #23614 + # Issue #23614 df = DataFrame({'A': [6.0, 3.1, 2.2]}) expected = ' A\n0 6,0\n1 3,1\n2 2,2' assert df.to_string(decimal=',') == expected From 7186aaf5f143d3be74edec243fe77798a98f37c8 Mon Sep 17 00:00:00 2001 From: thoo Date: Mon, 12 Nov 2018 10:22:10 -0500 Subject: [PATCH 8/9] Change as recommended --- doc/source/whatsnew/v0.24.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.txt b/doc/source/whatsnew/v0.24.0.txt index 8cd6331410d73..59f15f0a3ea1f 100644 --- a/doc/source/whatsnew/v0.24.0.txt +++ b/doc/source/whatsnew/v0.24.0.txt @@ -21,7 +21,7 @@ the user to override the engine's default behavior to include or omit the dataframe's indexes from the resulting Parquet file. (:issue:`20768`) - :meth:`DataFrame.corr` and :meth:`Series.corr` now accept a callable for generic calculation methods of correlation, e.g. histogram intersection (:issue:`22684`) - :func:`DataFrame.to_string` now accepts ``decimal`` as an argument, allowing -the user to use a decimal separator. (:issue:`23614`) +the user to specify which decimal separator should be used in the output. (:issue:`23614`) .. _whatsnew_0240.enhancements.extension_array_operators: From 2bb90d4d8b69211dac058986472b4b14982c22f7 Mon Sep 17 00:00:00 2001 From: thoo Date: Thu, 15 Nov 2018 09:55:59 -0500 Subject: [PATCH 9/9] Fix at whatsnew --- doc/source/whatsnew/v0.24.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.24.0.rst b/doc/source/whatsnew/v0.24.0.rst index 24f7bcc4aa805..7bfe3b1f253f3 100644 --- a/doc/source/whatsnew/v0.24.0.rst +++ b/doc/source/whatsnew/v0.24.0.rst @@ -962,7 +962,7 @@ Other API Changes - :class:`DateOffset` attribute `_cacheable` and method `_should_cache` have been removed (:issue:`23118`) - Comparing :class:`Timedelta` to be less or greater than unknown types now raises a ``TypeError`` instead of returning ``False`` (:issue:`20829`) - :meth:`Index.hasnans` and :meth:`Series.hasnans` now always return a python boolean. Previously, a python or a numpy boolean could be returned, depending on circumstances (:issue:`23294`). -- :func:The order of the arguments of `DataFrame.to_html` and `DataFrame.to_string` is rearranged to be consistent with each other. (:issue:`23614`) +- The order of the arguments of :func:`DataFrame.to_html` and :func:`DataFrame.to_string` is rearranged to be consistent with each other. (:issue:`23614`) .. _whatsnew_0240.deprecations: