From d167d47488c841f208ff2f186f06a161d95f6138 Mon Sep 17 00:00:00 2001 From: William Andrea Date: Mon, 3 Jul 2023 14:16:17 -0400 Subject: [PATCH 1/2] Clean up sniffing and chunking examples Sniffing: - Had an unused "to_csv" call Chunking: - Used an unnecessary "sep" - Had "reader" as a no-op statement, which seems like it was meant to be printed Both - Put the index as a column unnecessarily --- doc/source/user_guide/io.rst | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 0084e885db2b5..5aa3c6105fc47 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -1568,8 +1568,7 @@ class of the csv module. For this, you have to specify ``sep=None``. .. ipython:: python df = pd.DataFrame(np.random.randn(10, 4)) - df.to_csv("tmp.csv", sep="|") - df.to_csv("tmp2.csv", sep=":") + df.to_csv("tmp2.csv", sep=":", index=False) pd.read_csv("tmp2.csv", sep=None, engine="python") .. ipython:: python @@ -1597,8 +1596,8 @@ rather than reading the entire file into memory, such as the following: .. ipython:: python df = pd.DataFrame(np.random.randn(10, 4)) - df.to_csv("tmp.csv", sep="|") - table = pd.read_csv("tmp.csv", sep="|") + df.to_csv("tmp.csv", index=False) + table = pd.read_csv("tmp.csv") table @@ -1607,8 +1606,8 @@ value will be an iterable object of type ``TextFileReader``: .. ipython:: python - with pd.read_csv("tmp.csv", sep="|", chunksize=4) as reader: - reader + with pd.read_csv("tmp.csv", chunksize=4) as reader: + print(reader) for chunk in reader: print(chunk) From dc0e7ea7deba5863e850bc664feb9c1e51cdb067 Mon Sep 17 00:00:00 2001 From: William Andrea Date: Mon, 3 Jul 2023 14:26:20 -0400 Subject: [PATCH 2/2] Fix chunking example (I missed this part) Unnecessary "sep" Another statement that seems like it was meant to be printed --- doc/source/user_guide/io.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/user_guide/io.rst b/doc/source/user_guide/io.rst index 5aa3c6105fc47..ec0e7d0636b07 100644 --- a/doc/source/user_guide/io.rst +++ b/doc/source/user_guide/io.rst @@ -1619,8 +1619,8 @@ Specifying ``iterator=True`` will also return the ``TextFileReader`` object: .. ipython:: python - with pd.read_csv("tmp.csv", sep="|", iterator=True) as reader: - reader.get_chunk(5) + with pd.read_csv("tmp.csv", iterator=True) as reader: + print(reader.get_chunk(5)) .. ipython:: python :suppress: