From 0523d98aee41f0579524cc0a40895eee26e4369d Mon Sep 17 00:00:00 2001 From: Wes McKinney Date: Sun, 30 Sep 2012 21:19:16 -0400 Subject: [PATCH] BUG: datetime64 formatting issues in DataFrame.to_csv. close #1993 --- RELEASE.rst | 1 + pandas/core/frame.py | 5 ++++- pandas/tseries/tests/test_timeseries.py | 10 ++++++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/RELEASE.rst b/RELEASE.rst index 8e276e60c2b57..38312a5c49ac8 100644 --- a/RELEASE.rst +++ b/RELEASE.rst @@ -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 diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 56e764980447c..30147a77d40cd 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -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) @@ -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). """) diff --git a/pandas/tseries/tests/test_timeseries.py b/pandas/tseries/tests/test_timeseries.py index 29a128e63a785..9d098c55b4417 100644 --- a/pandas/tseries/tests/test_timeseries.py +++ b/pandas/tseries/tests/test_timeseries.py @@ -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 @@ -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)