Skip to content

smaller than microsecond timedelta64 Series are not saved correctly with to_csv #6783

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

Closed
cpcloud opened this issue Apr 3, 2014 · 5 comments · Fixed by #30554
Closed

smaller than microsecond timedelta64 Series are not saved correctly with to_csv #6783

cpcloud opened this issue Apr 3, 2014 · 5 comments · Fixed by #30554
Labels
good first issue IO CSV read_csv, to_csv Needs Tests Unit test(s) needed to prevent regressions
Milestone

Comments

@cpcloud
Copy link
Member

cpcloud commented Apr 3, 2014

In [24]: x = Series(np.around(randn(10) * 100).astype('timedelta64[ns]'))

In [25]: x
Out[25]:
0   -00:00:00.000000
1    00:00:00.000000
2   -00:00:00.000000
3   -00:00:00.000000
4    00:00:00.000000
5   -00:00:00.000000
6   -00:00:00.000000
7   -00:00:00.000000
8   -00:00:00.000000
9   -00:00:00.000000
dtype: timedelta64[ns]

In [26]: x.values
Out[26]: array([-259,   31,  -49,  -41,  141,  -14, -111, -117,  -20,  -35], dtype='timedelta64[ns]')

In [27]: buf = StringIO()

In [28]: x.to_csv(buf)

In [29]: print(buf.getvalue())
0,-00:00:00.000000
1,00:00:00.000000
2,-00:00:00.000000
3,-00:00:00.000000
4,00:00:00.000000
5,-00:00:00.000000
6,-00:00:00.000000
7,-00:00:00.000000
8,-00:00:00.000000
9,-00:00:00.000000
@cpcloud
Copy link
Member Author

cpcloud commented Apr 3, 2014

somewhat of an edge case ... not sure how many people need or are using this level of precision

@jreback jreback added this to the 0.15.0 milestone Apr 3, 2014
@jreback
Copy link
Contributor

jreback commented Apr 3, 2014

yep....part of the whole, formatting for csv output.....welcome to figure this out in a general way! (the timedelta formatting pretty trivial (as it already takes a format kw, just need to interpret it), bigger issue is how to tell to_csv the formats that you want...

e.g. dict of column -> format, or prob better to have a Class that you can override, call to set state, etc.

@jreback jreback modified the milestones: 0.16.0, Next Major Release Mar 3, 2015
@mroeschke
Copy link
Member

Looks like this is fixed on master. Could use a test

In [8]: print(buf.getvalue())
0,-1 days +23:59:59.999999925
1,-1 days +23:59:59.999999964
2,-1 days +23:59:59.999999957
3,-1 days +23:59:59.999999912
4,-1 days +23:59:59.999999996
5,0 days 00:00:00.000000094
6,0 days 00:00:00.000000130
7,-1 days +23:59:59.999999893
8,0 days 00:00:00.000000078
9,0 days 00:00:00.000000016

@mroeschke mroeschke added good first issue Needs Tests Unit test(s) needed to prevent regressions and removed IO CSV read_csv, to_csv Output-Formatting __repr__ of pandas objects, to_string Timedelta Timedelta data type labels Oct 11, 2019
@jbrockmendel jbrockmendel added the IO CSV read_csv, to_csv label Oct 16, 2019
@baevpetr
Copy link
Contributor

Hi, can I take it ?

@simonjayhawkins simonjayhawkins modified the milestones: Contributions Welcome, 1.0 Dec 30, 2019
@TomAugspurger
Copy link
Contributor

@baevpetr I think this is already being fixed in #30554.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue IO CSV read_csv, to_csv Needs Tests Unit test(s) needed to prevent regressions
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants