From 1e1ebdbc464495d16f6d1170ba7f5275b37984c2 Mon Sep 17 00:00:00 2001 From: Paul Reidy Date: Wed, 20 Dec 2017 23:27:05 +0000 Subject: [PATCH] DEPR: convert_datetime64 parameter in to_records() --- doc/source/whatsnew/v0.23.0.txt | 1 + pandas/core/frame.py | 13 +++++++++++-- pandas/tests/frame/test_convert_to.py | 5 ++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 8c94cef4d8ea7c..295291099855fd 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -219,6 +219,7 @@ Deprecations - ``Series.valid`` is deprecated. Use :meth:`Series.dropna` instead (:issue:`18800`). - :func:`read_excel` has deprecated the ``skip_footer`` parameter. Use ``skipfooter`` instead (:issue:`18836`) - The ``is_copy`` attribute is deprecated and will be removed in a future version (:issue:`18801`). +- The ``convert_datetime64`` parameter has been deprecated and the default value is now ``False`` in :func:`to_records` as the NumPy bug motivating this parameter has been resolved (:issue:`18160`). .. _whatsnew_0230.prior_deprecations: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 26257f6ecbc37a..3779f3c66f22c2 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1187,7 +1187,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None, return cls(mgr) - def to_records(self, index=True, convert_datetime64=True): + def to_records(self, index=True, convert_datetime64=False): """ Convert DataFrame to record array. Index will be put in the 'index' field of the record array if requested @@ -1196,7 +1196,9 @@ def to_records(self, index=True, convert_datetime64=True): ---------- index : boolean, default True Include index in resulting record array, stored in 'index' field - convert_datetime64 : boolean, default True + convert_datetime64 : boolean, default False + .. deprecated:: 0.23.0 + Whether to convert the index to datetime.datetime if it is a DatetimeIndex @@ -1204,6 +1206,13 @@ def to_records(self, index=True, convert_datetime64=True): ------- y : recarray """ + + if convert_datetime64: + warnings.warn("The 'convert_datetime64' parameter is " + "deprecated and will be removed in a future " + "version", + FutureWarning, stacklevel=2) + if index: if is_datetime64_any_dtype(self.index) and convert_datetime64: ix_vals = [self.index.to_pydatetime()] diff --git a/pandas/tests/frame/test_convert_to.py b/pandas/tests/frame/test_convert_to.py index 024de8bc13f721..f380a7ed606a2b 100644 --- a/pandas/tests/frame/test_convert_to.py +++ b/pandas/tests/frame/test_convert_to.py @@ -78,7 +78,10 @@ def test_to_records_dt64(self): df = DataFrame([["one", "two", "three"], ["four", "five", "six"]], index=date_range("2012-01-01", "2012-01-02")) - assert df.to_records()['index'][0] == df.index[0] + with tm.assert_produces_warning(FutureWarning): + expected = df.index[0] + result = df.to_records(convert_datetime64=True)['index'][0] + assert expected == result rs = df.to_records(convert_datetime64=False) assert rs['index'][0] == df.index.values[0]