Skip to content

Commit

Permalink
BUG: datetime64 formatting issues in DataFrame.to_csv. close #1993
Browse files Browse the repository at this point in the history
  • Loading branch information
wesm committed Oct 1, 2012
1 parent 5c47d72 commit 0523d98
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ pandas 0.9.0
(#1970)
- Fix reset_index bug if both drop and level are specified (#1957)
- Work around unsafe NumPy object->int casting with Cython function (#1987)
- Fix datetime64 formatting bug in DataFrame.to_csv (#1993)


pandas 0.8.1
Expand Down
5 changes: 4 additions & 1 deletion pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1106,8 +1106,11 @@ def _helper_csvexcel(self, writer, na_rep=None, cols=None,
val = series[col][j]
if lib.checknull(val):
val = na_rep

if float_format is not None and com.is_float(val):
val = float_format % val
elif isinstance(val, np.datetime64):
val = lib.Timestamp(val)._repr_base

row_fields.append(val)

Expand Down Expand Up @@ -4391,7 +4394,7 @@ def var(self, axis=0, skipna=True, level=None, ddof=1):

@Substitution(name='standard deviation', shortname='std',
na_action=_doc_exclude_na, extras='')
@Appender(_stat_doc +
@Appender(_stat_doc +
"""
Normalized by N-1 (unbiased estimator).
""")
Expand Down
10 changes: 10 additions & 0 deletions pandas/tseries/tests/test_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
from pandas.util.testing import assert_series_equal, assert_almost_equal
import pandas.util.testing as tm

from pandas.util.py3compat import StringIO

from pandas.lib import NaT, iNaT
import pandas.lib as lib
import cPickle as pickle
Expand Down Expand Up @@ -1185,6 +1187,14 @@ def test_to_html_timestamp(self):
result = df.to_html()
self.assert_('2000-01-01' in result)

def test_to_csv_numpy_16_bug(self):
frame = DataFrame({'a': date_range('1/1/2000', periods=10)})

buf = StringIO()
frame.to_csv(buf)

result = buf.getvalue()
self.assert_('2000-01-01' in result)

def _simple_ts(start, end, freq='D'):
rng = date_range(start, end, freq=freq)
Expand Down

0 comments on commit 0523d98

Please sign in to comment.