Skip to content

Commit ea758cd

Browse files
aechasejreback
authored andcommitted
ENH: tilde expansion for write output formatting functions, #11438
1 parent 06c195d commit ea758cd

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

doc/source/whatsnew/v0.17.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ Enhancements
9393

9494
- ``pivot_table`` now has a ``margins_name`` argument so you can use something other than the default of 'All' (:issue:`3335`)
9595
- Implement export of ``datetime64[ns, tz]`` dtypes with a fixed HDF5 store (:issue:`11411`)
96+
- The ``DataFrame`` and ``Series`` functions ``.to_csv()``, ``.to_html()`` and ``.to_latex()`` can now handle paths beginning with tildes (e.g. ``~/Documents/``). (:issue:`11438`)
9697

9798
.. _whatsnew_0171.api:
9899

pandas/core/frame.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
from pandas.tseries.period import PeriodIndex
5454
from pandas.tseries.index import DatetimeIndex
5555
from pandas.tseries.tdi import TimedeltaIndex
56-
56+
from pandas.io.common import _expand_user
5757

5858
import pandas.core.algorithms as algos
5959
import pandas.core.base as base
@@ -1315,7 +1315,7 @@ def to_csv(self, path_or_buf=None, sep=",", na_rep='', float_format=None,
13151315
.. versionadded:: 0.16.0
13161316
13171317
"""
1318-
1318+
path_or_buf = _expand_user(path_or_buf)
13191319
formatter = fmt.CSVFormatter(self, path_or_buf,
13201320
line_terminator=line_terminator,
13211321
sep=sep, encoding=encoding,
@@ -1518,6 +1518,7 @@ def to_html(self, buf=None, columns=None, col_space=None, colSpace=None,
15181518
FutureWarning, stacklevel=2)
15191519
col_space = colSpace
15201520

1521+
buf = _expand_user(buf)
15211522
formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns,
15221523
col_space=col_space, na_rep=na_rep,
15231524
formatters=formatters,
@@ -1568,6 +1569,7 @@ def to_latex(self, buf=None, columns=None, col_space=None, colSpace=None,
15681569
FutureWarning, stacklevel=2)
15691570
col_space = colSpace
15701571

1572+
buf = _expand_user(buf)
15711573
formatter = fmt.DataFrameFormatter(self, buf=buf, columns=columns,
15721574
col_space=col_space, na_rep=na_rep,
15731575
header=header, index=index,

0 commit comments

Comments
 (0)