From 5e0fbe38a8d4bba5ef91230b26958a66dc087310 Mon Sep 17 00:00:00 2001 From: TanyaaCJain Date: Thu, 22 Aug 2019 18:28:01 +0530 Subject: [PATCH 1/5] DOC: Make explicit in pandas IO doc the iports and options - Removes code header in IO doc page. - Uses explicit imports in the IO page of user guide on first occurence of requirement. - In reference to #28038 --- doc/source/user_guide/io.rst | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 1d49dbdee9c03..f92de56558d2d 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -2,12 +2,11 @@ .. currentmodule:: pandas - -{{ header }} - .. ipython:: python :suppress: + import pandas as pd + pd.options.display.max_rows = 15 clipdf = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': ['p', 'q', 'r']}, index=['x', 'y', 'z']) @@ -363,6 +362,8 @@ columns: .. ipython:: python + import numpy as np + np.set_printoptions(precision=4, suppress=True) data = ('a,b,c,d\n' '1,2,3,4\n' '5,6,7,8\n' @@ -447,7 +448,6 @@ worth trying. :suppress: import os - os.remove('foo.csv') .. _io.categorical: @@ -1579,6 +1579,7 @@ class of the csv module. For this, you have to specify ``sep=None``. .. ipython:: python :suppress: + np.random.seed(123456) df = pd.DataFrame(np.random.randn(10, 4)) df.to_csv('tmp.sv', sep='|') df.to_csv('tmp2.sv', sep=':') @@ -5562,10 +5563,8 @@ Given the next test set: .. code-block:: python - from numpy.random import randn - sz = 1000000 - df = pd.DataFrame({'A': randn(sz), 'B': [1] * sz}) + df = pd.DataFrame({'A': np.random.randn(sz), 'B': [1] * sz}) def test_sql_write(df): From 18a9b7cd22f9ad39f3391aeabaf65d81d79dc474 Mon Sep 17 00:00:00 2001 From: TanyaaCJain Date: Fri, 23 Aug 2019 02:40:15 +0530 Subject: [PATCH 2/5] DOC: Update io.rst to explicitly add imports and options - imported pandas and added its options in the first visible code block - moved the suppressed or invisible code block using clipdf just before the code block using the clipdf variable - imported `BytesIO` in its first occurrence of requirement unlike previously imported along with `StringIO` - imported os again for adding it on its first occurrence of requirement in a visible code block and is earlier imported in a suppressed code block. --- doc/source/user_guide/io.rst | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index f92de56558d2d..4e6ecdb8a4dac 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -2,14 +2,6 @@ .. currentmodule:: pandas -.. ipython:: python - :suppress: - - import pandas as pd - pd.options.display.max_rows = 15 - clipdf = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': ['p', 'q', 'r']}, - index=['x', 'y', 'z']) - =============================== IO tools (text, CSV, HDF5, ...) @@ -136,7 +128,9 @@ usecols : list-like or callable, default ``None`` .. ipython:: python - from io import StringIO, BytesIO + import pandas as pd + pd.options.display.max_rows = 15 + from io import StringIO data = ('col1,col2,col3\n' 'a,b,1\n' 'a,b,2\n' @@ -757,6 +751,7 @@ result in byte strings being decoded to unicode in the result: .. ipython:: python + from io import BytesIO data = (b'word,length\n' b'Tr\xc3\xa4umen,7\n' b'Gr\xc3\xbc\xc3\x9fe,5') @@ -3267,6 +3262,12 @@ clipboard (CTRL-C on many operating systems): And then import the data directly to a ``DataFrame`` by calling: +.. ipython:: python + :suppress: + + clipdf = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': ['p', 'q', 'r']}, + index=['x', 'y', 'z']) + .. code-block:: python >>> clipdf = pd.read_clipboard() @@ -5563,6 +5564,8 @@ Given the next test set: .. code-block:: python + import os + sz = 1000000 df = pd.DataFrame({'A': np.random.randn(sz), 'B': [1] * sz}) From d3036f3408ccaefd97777c67e88a85f32a1835b7 Mon Sep 17 00:00:00 2001 From: TanyaaCJain Date: Fri, 23 Aug 2019 18:12:50 +0530 Subject: [PATCH 3/5] DOC: Removed pandas row display option because it is not required at the moment --- doc/source/user_guide/io.rst | 1 - 1 file changed, 1 deletion(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 4e6ecdb8a4dac..ef1264fb62875 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -129,7 +129,6 @@ usecols : list-like or callable, default ``None`` .. ipython:: python import pandas as pd - pd.options.display.max_rows = 15 from io import StringIO data = ('col1,col2,col3\n' 'a,b,1\n' From f80331e3c8aa8a7fa034ec169f670511038633e8 Mon Sep 17 00:00:00 2001 From: TanyaaCJain Date: Fri, 23 Aug 2019 22:27:40 +0530 Subject: [PATCH 4/5] DOC: Remove unused clipdf assignment, numpy print options and seed --- doc/source/user_guide/io.rst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index ef1264fb62875..5548c71ad0484 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -3261,12 +3261,6 @@ clipboard (CTRL-C on many operating systems): And then import the data directly to a ``DataFrame`` by calling: -.. ipython:: python - :suppress: - - clipdf = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': ['p', 'q', 'r']}, - index=['x', 'y', 'z']) - .. code-block:: python >>> clipdf = pd.read_clipboard() From 6487a6884febdd590fe722cab5328c1b3b8704dd Mon Sep 17 00:00:00 2001 From: TanyaaCJain Date: Fri, 23 Aug 2019 22:31:07 +0530 Subject: [PATCH 5/5] DOC: Remove unused clipdf assignment, numpy print options and seed --- doc/source/user_guide/io.rst | 2 -- 1 file changed, 2 deletions(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 5548c71ad0484..5e58494f3e1fc 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -356,7 +356,6 @@ columns: .. ipython:: python import numpy as np - np.set_printoptions(precision=4, suppress=True) data = ('a,b,c,d\n' '1,2,3,4\n' '5,6,7,8\n' @@ -1573,7 +1572,6 @@ class of the csv module. For this, you have to specify ``sep=None``. .. ipython:: python :suppress: - np.random.seed(123456) df = pd.DataFrame(np.random.randn(10, 4)) df.to_csv('tmp.sv', sep='|') df.to_csv('tmp2.sv', sep=':')