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

BUG: Error while saving DataFrame with TimedeltaIndex to .csv #10833

Closed
soupault opened this issue Aug 17, 2015 · 4 comments
Closed

BUG: Error while saving DataFrame with TimedeltaIndex to .csv #10833

soupault opened this issue Aug 17, 2015 · 4 comments
Labels
Bug IO CSV read_csv, to_csv Timedelta Timedelta data type
Milestone

Comments

@soupault
Copy link
Contributor

I'm trying to save pd.DataFrame using .to_csv method.
If DataFrame has TimedeltaIndex the error is risen:

>>> dt = pd.Timedelta(seconds=10)
>>> timestamps = [dt, 2*dt, 3*dt]
>>> df = pd.DataFrame({'obs': [11,22,33]}, index=timestamps)
>>> df
          obs
00:00:10   11
00:00:20   22
00:00:30   33

>>> df.to_csv('test')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-27-9b2e5ea53beb> in <module>()
----> 1 df.to_csv('test')

C:\Python34\lib\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, doub
lequote, escapechar, decimal, **kwds)
   1187                                      escapechar=escapechar,
   1188                                      decimal=decimal)
-> 1189         formatter.save()
   1190
   1191         if path_or_buf is None:

C:\Python34\lib\site-packages\pandas\core\format.py in save(self)
   1465
   1466             else:
-> 1467                 self._save()
   1468
   1469         finally:

C:\Python34\lib\site-packages\pandas\core\format.py in _save(self)
   1565                 break
   1566
-> 1567             self._save_chunk(start_i, end_i)
   1568
   1569     def _save_chunk(self, start_i, end_i):

C:\Python34\lib\site-packages\pandas\core\format.py in _save_chunk(self, start_i
, end_i)
   1592                                         quoting=self.quoting)
   1593
-> 1594         lib.write_csv_rows(self.data, ix, self.nlevels, self.cols, self.
writer)
   1595
   1596 # from collections import namedtuple

TypeError: Argument 'data_index' has incorrect type (expected numpy.ndarray, got
 list)

But if Timedelta is not an Index, but a regular column, everything is OK:

>>> df['timedelta'] = df.index
>>> df.reset_index(drop=True, inplace=True)
>>> df.to_csv('test')

Python 3.4.2 x64 Windows version.
pandas (0.16.2), numpy (1.9.2)

@jreback
Copy link
Contributor

jreback commented Aug 17, 2015

seems a little buggy. I think you can just insert a np.array(.....,) here

want to do a pull-request ?

@jreback jreback added Bug IO CSV read_csv, to_csv labels Aug 17, 2015
@jreback jreback added this to the 0.17.0 milestone Aug 17, 2015
@soupault
Copy link
Contributor Author

@jreback yes, please. Give me a day.

@jreback
Copy link
Contributor

jreback commented Aug 17, 2015

awesome!

@jreback jreback added the Timedelta Timedelta data type label Aug 18, 2015
@jreback jreback modified the milestones: Next Major Release, 0.17.0 Aug 19, 2015
@soupault soupault changed the title Error while saving DataFrame with TimedeltaIndex to .csv BUG: Error while saving DataFrame with TimedeltaIndex to .csv Aug 21, 2015
jreback added a commit that referenced this issue Aug 21, 2015
BUG: Error while saving DataFrame with TimedeltaIndex to .csv #10833
@jreback
Copy link
Contributor

jreback commented Aug 21, 2015

closed by #10845

@jreback jreback closed this as completed Aug 21, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO CSV read_csv, to_csv Timedelta Timedelta data type
Projects
None yet
Development

No branches or pull requests

2 participants