Skip to content
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

Use expanduser when writing dataframes to files? #23473

Closed
gte620v opened this issue Nov 3, 2018 · 2 comments

Comments

Projects
None yet
4 participants
@gte620v
Copy link
Contributor

commented Nov 3, 2018

Code Sample, a copy-pastable example if possible

The following to_XXX do not work:

df = pd.DataFrame([[1,1],[2,2]])
df.to_pickle('~/df.pkl')
df.to_json('~/df.json')
 # etc.

Problem description

to_XXX do not work when the path argument includes a ~. This may be fine, but it is strange that dataframe reading from files does support ~. i.e. pd.read_json('~/df.json') works fine.

Expected Output

I expect to_json and friends to support expanding the home directory.

Perhaps the fix is to add expanduser to

def _stringify_path(filepath_or_buffer):

as we have in
return _expand_user(filepath_or_buffer), None, compression, False

Output of pd.show_versions()

INSTALLED VERSIONS ------------------ commit: None python: 3.6.6.final.0 python-bits: 64 OS: Darwin OS-release: 17.7.0 machine: x86_64 processor: i386 byteorder: little LC_ALL: None LANG: en_US.UTF-8 LOCALE: en_US.UTF-8

pandas: 0.23.4
pytest: 3.9.1
pip: 9.0.1
setuptools: 40.4.1
Cython: 0.27.3
numpy: 1.15.2
scipy: 1.1.0
pyarrow: 0.10.0
xarray: None
IPython: 5.3.0
sphinx: 1.5.1
patsy: 0.4.1
dateutil: 2.7.3
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: 3.4.4
numexpr: 2.6.5
feather: None
matplotlib: 2.2.2
openpyxl: 2.4.1
xlrd: 1.0.0
xlwt: 1.2.0
xlsxwriter: 0.9.6
lxml: 4.1.1
bs4: 4.5.3
html5lib: 0.9999999
sqlalchemy: 1.1.15
pymysql: None
psycopg2: 2.7.1 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: 0.1.5
fastparquet: 0.1.3
pandas_gbq: None
pandas_datareader: None

@gfyoung

This comment has been minimized.

Copy link
Member

commented Nov 4, 2018

@gte620v : I think that's a perfectly valid enhancement. Go for it!

@gfyoung gfyoung added the Compat label Nov 4, 2018

@gte620v

This comment has been minimized.

Copy link
Contributor Author

commented Nov 5, 2018

Actually, there is support in to_html, to_csv, and to_latex from #11458. I will look at adding to other write functions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.