Repository: pandas-dev/pandas

Issue:
DOC/TST: doctests leaving extraneous files
after running

``LINT=1 ci/code_check.sh``

we get some garbage left around

```
(pandas) bash-3.2$ git st
On branch PR_TOOL_MERGE_PR_23096
Untracked files:
  (use "git add <file>..." to include in what will be committed)

        df.parquet.gzip
        df_info.txt
        output.xlsx
        output1.xlsx

nothing added to commit but untracked files present (use "git add" to track)
```


Discussion:
cc @datapythonista 

prob from some of the doc-tests
Didn't realize, but likely to be from the doctests. Not sure what's the best option here, what comes to my mind:
- Save to temp: `df.to_csv('/tmp/data.csv')`
- Remove the file after saving in the doctest (I don't like that it may be confusing and verbose to the users)
- Avoid saving to disk in the doctests (I don't like it, as we won't be able to show several methods)
- Saving to StringIO objects (probably too complex for beginners)
- Having a clean up function (we'll have to maintain the list of files, and we have several ways to run the doctests, so we can't run it automaitcally in all cases)

Any other idea? I think the first option is probably the best, even if it's not ideal.
Is using a tempfile / namedtempfile not an option?
yes these should use a named temp file i think
In terms of cleaning up after running the doctests there is no doubt that using Python stdlib `tempfile` is the best option. But in terms of documentation I think we're doing a poor favor to our users if instead of showing a method like `to_csv` as:

```
df.to_csv('/tmp/my_dataframe.csv')
```

we show:
```
import tempfile
with tempfile.NamedTemporaryFile() as csv_fd:
    df.to_csv(csv_fd)
```
How about we add `doctest: +SKIP` to the lines writing to disk, and lines that read afterwards?

Writing to `/tmp` isn't great, since users may be copy-pasting and may not have a `/tmp` directory.

Anything with cleaning up or writing to a StringIO will, I think, just muddy the example. We shouldn't compromise on the documentation here.
+1 on `doctest: +SKIP`.


Working on it!

Resolving patch:
diff --git a/pandas/core/frame.py b/pandas/core/frame.py
--- a/pandas/core/frame.py
+++ b/pandas/core/frame.py
@@ -2028,8 +2028,9 @@ def to_parquet(self, fname, engine='auto', compression='snappy',
         Examples
         --------
         >>> df = pd.DataFrame(data={'col1': [1, 2], 'col2': [3, 4]})
-        >>> df.to_parquet('df.parquet.gzip', compression='gzip')
-        >>> pd.read_parquet('df.parquet.gzip')
+        >>> df.to_parquet('df.parquet.gzip',
+        ...               compression='gzip')  # doctest: +SKIP
+        >>> pd.read_parquet('df.parquet.gzip')  # doctest: +SKIP
            col1  col2
         0     1     3
         1     2     4
@@ -2243,7 +2244,8 @@ def info(self, verbose=None, buf=None, max_cols=None, memory_usage=None,
         >>> buffer = io.StringIO()
         >>> df.info(buf=buffer)
         >>> s = buffer.getvalue()
-        >>> with open("df_info.txt", "w", encoding="utf-8") as f:
+        >>> with open("df_info.txt", "w",
+        ...           encoding="utf-8") as f:  # doctest: +SKIP
         ...     f.write(s)
         260
 
diff --git a/pandas/core/generic.py b/pandas/core/generic.py
--- a/pandas/core/generic.py
+++ b/pandas/core/generic.py
@@ -2069,17 +2069,18 @@ def _repr_latex_(self):
     >>> df1 = pd.DataFrame([['a', 'b'], ['c', 'd']],
     ...                   index=['row 1', 'row 2'],
     ...                   columns=['col 1', 'col 2'])
-    >>> df1.to_excel("output.xlsx")
+    >>> df1.to_excel("output.xlsx")  # doctest: +SKIP
 
     To specify the sheet name:
 
-    >>> df1.to_excel("output.xlsx", sheet_name='Sheet_name_1')
+    >>> df1.to_excel("output.xlsx",
+    ...              sheet_name='Sheet_name_1')  # doctest: +SKIP
 
     If you wish to write to more than one sheet in the workbook, it is
     necessary to specify an ExcelWriter object:
 
     >>> df2 = df1.copy()
-    >>> with pd.ExcelWriter('output.xlsx') as writer:
+    >>> with pd.ExcelWriter('output.xlsx') as writer:  # doctest: +SKIP
     ...     df1.to_excel(writer, sheet_name='Sheet_name_1')
     ...     df2.to_excel(writer, sheet_name='Sheet_name_2')
 
@@ -2087,7 +2088,7 @@ def _repr_latex_(self):
     you can pass the `engine` keyword (the default engine is
     automatically chosen depending on the file extension):
 
-    >>> df1.to_excel('output1.xlsx', engine='xlsxwriter')
+    >>> df1.to_excel('output1.xlsx', engine='xlsxwriter')  # doctest: +SKIP
     """
 
     def to_json(self, path_or_buf=None, orient=None, date_format=None,


Test patch: