Skip to content

DOC: Make explicit in pandas IO doc the imports and options #28089

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Nov 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 6 additions & 13 deletions doc/source/user_guide/io.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,6 @@
.. currentmodule:: pandas


{{ header }}

.. ipython:: python
:suppress:

clipdf = pd.DataFrame({'A': [1, 2, 3], 'B': [4, 5, 6], 'C': ['p', 'q', 'r']},
index=['x', 'y', 'z'])


===============================
IO tools (text, CSV, HDF5, ...)
===============================
Expand Down Expand Up @@ -137,7 +128,8 @@ usecols : list-like or callable, default ``None``

.. ipython:: python

from io import StringIO, BytesIO
import pandas as pd
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I realize I missed the original discussion but just to be clear, is the assumption here that we only show the import the first time it shows up one of the rst files and that the rest of the code blocks use it from there?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think that's an assumption. It is implicitly being proposed, for simplicity and for inertia on how the header worked, but it's surely open to discussion. I thought about that too, and I was also wondering if it'd make sense to split the long pages we have now in the user guide in shorter pages. I guess that could make things easier if we finally make the code runnable.

from io import StringIO
data = ('col1,col2,col3\n'
'a,b,1\n'
'a,b,2\n'
Expand Down Expand Up @@ -363,6 +355,7 @@ columns:

.. ipython:: python

import numpy as np
data = ('a,b,c,d\n'
'1,2,3,4\n'
'5,6,7,8\n'
Expand Down Expand Up @@ -447,7 +440,6 @@ worth trying.
:suppress:

import os

os.remove('foo.csv')

.. _io.categorical:
Expand Down Expand Up @@ -757,6 +749,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')
Expand Down Expand Up @@ -5562,10 +5555,10 @@ Given the next test set:

.. code-block:: python

from numpy.random import randn
import os

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):
Expand Down