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

Tilde expansion for paths (~/...) inconsistent between read_csv and to_csv #11438

Closed
aechase opened this issue Oct 27, 2015 · 6 comments
Closed
Labels
Enhancement good first issue IO Data IO issues that don't fit into a more specific label

Comments

@aechase
Copy link
Contributor

aechase commented Oct 27, 2015

When specifying a path in DataFrame.read_csv(), pandas has no problem with the tilde expansion:

In[1]:
    import pandas as pd
    test = pd.read_csv('~/Documents/test.csv', index_col=0)
    test.head()

Out[1]:
        Foo Bar
    0   1   2
    1   3   4
    2   5   6
    3   7   8
    4   9   10

But DataFrame.to_csv() doesn't understand this:

In[2]:
    test.to_csv('~/Documents/test1.csv')

Out[2]:
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
<ipython-input-4-ef1160d6e930> in <module>()
----> 1 test.to_csv("~/Documents/test1.csv")

//anaconda/lib/python3.4/site-packages/pandas/core/frame.py in to_csv(self, path_or_buf, sep, na_rep, float_format, columns, header, index, index_label, mode, encoding, quoting, quotechar, line_terminator, chunksize, tupleize_cols, date_format, doublequote, escapechar, decimal, **kwds)
   1287                                      escapechar=escapechar,
   1288                                      decimal=decimal)
-> 1289         formatter.save()
   1290 
   1291         if path_or_buf is None:

//anaconda/lib/python3.4/site-packages/pandas/core/format.py in save(self)
   1467         else:
   1468             f = com._get_handle(self.path_or_buf, self.mode,
-> 1469                                 encoding=self.encoding)
   1470             close = True
   1471 

//anaconda/lib/python3.4/site-packages/pandas/core/common.py in _get_handle(path, mode, encoding, compression)
   2865                 f = open(path, mode, encoding=encoding)
   2866             else:
-> 2867                 f = open(path, mode, errors='replace')
   2868         else:
   2869             f = open(path, mode)

FileNotFoundError: [Errno 2] No such file or directory: '~/Documents/test1.csv'

Instead, it needs the file name alone, or the full path: test.to_csv('/Users/alexchase/Documents/test1.csv').

INSTALLED VERSIONS
------------------
commit: None
python: 3.4.3.final.0
python-bits: 64
OS: Darwin
OS-release: 15.0.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_GB.UTF-8

pandas: 0.17.0
nose: 1.3.7
pip: 7.1.2
setuptools: 18.4
Cython: 0.22.1
numpy: 1.10.1
scipy: 0.15.1
statsmodels: 0.6.1
IPython: 4.0.0
sphinx: 1.3.1
patsy: 0.3.0
dateutil: 2.4.2
pytz: 2015.6
blosc: None
bottleneck: 1.0.0
tables: 3.2.0
numexpr: 2.4.3
matplotlib: 1.4.3
openpyxl: 1.8.5
xlrd: 0.9.3
xlwt: 1.0.0
xlsxwriter: 0.7.3
lxml: 3.4.4
bs4: 4.3.2
html5lib: None
httplib2: None
apiclient: None
sqlalchemy: 1.0.5
pymysql: None
psycopg2: None
@TomAugspurger TomAugspurger added Bug IO Data IO issues that don't fit into a more specific label labels Oct 27, 2015
@TomAugspurger TomAugspurger added this to the 0.17.1 milestone Oct 27, 2015
@TomAugspurger
Copy link
Contributor

Thanks for the report. Interested in submitting a Pull Request?

@aechase
Copy link
Contributor Author

aechase commented Oct 27, 2015

Sure, I'll try to take a look this weekend.

@jreback
Copy link
Contributor

jreback commented Oct 27, 2015

@jreback jreback added Enhancement and removed Bug labels Oct 27, 2015
@jreback jreback modified the milestones: Next Major Release, 0.17.1 Oct 27, 2015
@aechase
Copy link
Contributor Author

aechase commented Oct 28, 2015

Many thanks!

jreback added a commit that referenced this issue Nov 19, 2015
yarikoptic added a commit to neurodebian/pandas that referenced this issue Dec 3, 2015
Version 0.17.1

* tag 'v0.17.1': (168 commits)
  add nbviewer link
  Revert "DOC: fix sponsor notice"
  DOC: a few touchups
  DOC: fix sponsor notice
  DOC: warnings and remove HTML
  COMPAT: compat of scalars on all platforms, xref pandas-dev#11638
  DOC: fix build errors/warnings
  DOC: whatsnew edits
  DOC: fix link syntax
  DOC: update release.rst / whatsnew edits
  BUG: fix col iteration in DataFrame.round, pandas-dev#11611
  DOC: Clarify foramtting
  BUG: pandas-dev#11638 return correct dtype for int and float
  BUG: pandas-dev#11637 fix to_csv incorrect output.
  DOC: sponsor notice
  BUG: indexing with a range , pandas-dev#11652
  Fix link to numexpr
  ENH: fixup tilde expansion, xref pandas-dev#11438
  ENH: tilde expansion for write output formatting functions, pandas-dev#11438
  DOC: fix up doc-string creations in generic.py
  ...
@puneet988
Copy link

hi @aechase !! Are you still working on the issue?

@gfyoung
Copy link
Member

gfyoung commented Feb 2, 2019

@puneet988 : This was actually resolved in #11458. We just forgot to close.

You're more than welcome to checkout any of our other open issues if you want to contribute! 👍

@gfyoung gfyoung closed this as completed Feb 2, 2019
@gfyoung gfyoung removed this from the Contributions Welcome milestone Feb 2, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement good first issue IO Data IO issues that don't fit into a more specific label
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants