From 65adc50a2bf587d0de6199428b8b9d89d4aad27a Mon Sep 17 00:00:00 2001 From: Paul Reidy Date: Wed, 20 Dec 2017 23:27:05 +0000 Subject: [PATCH 1/6] 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 408a52e0526ee..e432c456f0cb2 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -842,6 +842,7 @@ Deprecations - ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`) - ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`) - ``NDFrame.get_ftype_counts()`` is deprecated and will be removed in a future version (:issue:`18243`) +- 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 9e57579ddfc05..7453755528ecf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1311,7 +1311,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 a NumPy record array. @@ -1322,7 +1322,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. @@ -1376,6 +1378,13 @@ def to_records(self, index=True, convert_datetime64=True): ('2018-01-01T09:01:00.000000000', 2, 0.75)], dtype=[('index', ' Date: Fri, 22 Dec 2017 09:38:48 +0000 Subject: [PATCH 2/6] error in whatsnew --- doc/source/whatsnew/v0.23.0.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index e432c456f0cb2..dc857291adeb9 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -842,7 +842,7 @@ Deprecations - ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`) - ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`) - ``NDFrame.get_ftype_counts()`` is deprecated and will be removed in a future version (:issue:`18243`) -- 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`). +- The ``convert_datetime64`` parameter in :func:`DataFrame.to_records` has been deprecated and the default value is now ``False``. The NumPy bug motivating this parameter has been resolved (:issue:`18160`). .. _whatsnew_0230.prior_deprecations: From c13e7242748e9d2f28f1b0e2929a659018ea0bfb Mon Sep 17 00:00:00 2001 From: Paul Reidy Date: Sun, 24 Dec 2017 13:17:43 +0000 Subject: [PATCH 3/6] changing default to None --- doc/source/whatsnew/v0.23.0.txt | 2 +- pandas/core/frame.py | 4 ++-- pandas/tests/frame/test_convert_to.py | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index dc857291adeb9..70aefff61986c 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -842,7 +842,7 @@ Deprecations - ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`) - ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`) - ``NDFrame.get_ftype_counts()`` is deprecated and will be removed in a future version (:issue:`18243`) -- The ``convert_datetime64`` parameter in :func:`DataFrame.to_records` has been deprecated and the default value is now ``False``. The NumPy bug motivating this parameter has been resolved (:issue:`18160`). +- The ``convert_datetime64`` parameter in :func:`DataFrame.to_records` has been deprecated and will be removed in a future version. 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 7453755528ecf..1132288a97c90 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1311,7 +1311,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None, return cls(mgr) - def to_records(self, index=True, convert_datetime64=False): + def to_records(self, index=True, convert_datetime64=None): """ Convert DataFrame to a NumPy record array. @@ -1379,7 +1379,7 @@ def to_records(self, index=True, convert_datetime64=False): dtype=[('index', ' Date: Wed, 27 Dec 2017 21:29:30 +0000 Subject: [PATCH 4/6] convert_datetime64 defaults to True if not passed --- pandas/core/frame.py | 2 ++ pandas/tests/frame/test_convert_to.py | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 1132288a97c90..af6ea3e3ba9d6 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1384,6 +1384,8 @@ def to_records(self, index=True, convert_datetime64=None): "deprecated and will be removed in a future " "version", FutureWarning, stacklevel=2) + else: + convert_datetime64 = True if index: if is_datetime64_any_dtype(self.index) and convert_datetime64: diff --git a/pandas/tests/frame/test_convert_to.py b/pandas/tests/frame/test_convert_to.py index 75259dcc1584f..e4c69771e7019 100644 --- a/pandas/tests/frame/test_convert_to.py +++ b/pandas/tests/frame/test_convert_to.py @@ -79,11 +79,17 @@ def test_to_records_dt64(self): df = DataFrame([["one", "two", "three"], ["four", "five", "six"]], index=date_range("2012-01-01", "2012-01-02")) + with tm.assert_produces_warning(FutureWarning): expected = df.index[0] result = df.to_records(convert_datetime64=True)['index'][0] assert expected == result + expected = df.index[0] + # convert_datetime64 defaults to True if not passed + result = df.to_records()['index'][0] + assert expected == result + with tm.assert_produces_warning(FutureWarning): rs = df.to_records(convert_datetime64=False) assert rs['index'][0] == df.index.values[0] From 9837eb0446725db72746ed47fbe001ec92e2a938 Mon Sep 17 00:00:00 2001 From: reidy-p Date: Sat, 3 Mar 2018 12:42:13 +0000 Subject: [PATCH 5/6] change default back to False --- pandas/core/frame.py | 6 ++---- pandas/tests/frame/test_convert_to.py | 15 ++++++--------- 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/pandas/core/frame.py b/pandas/core/frame.py index af6ea3e3ba9d6..7453755528ecf 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1311,7 +1311,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None, return cls(mgr) - def to_records(self, index=True, convert_datetime64=None): + def to_records(self, index=True, convert_datetime64=False): """ Convert DataFrame to a NumPy record array. @@ -1379,13 +1379,11 @@ def to_records(self, index=True, convert_datetime64=None): dtype=[('index', ' Date: Sat, 14 Apr 2018 16:46:39 +0100 Subject: [PATCH 6/6] Make default for convert_datetime64=None and adjust tests --- doc/source/whatsnew/v0.23.0.txt | 2 +- pandas/core/frame.py | 6 +++--- pandas/tests/frame/test_convert_to.py | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/doc/source/whatsnew/v0.23.0.txt b/doc/source/whatsnew/v0.23.0.txt index 70aefff61986c..856e36fc24202 100644 --- a/doc/source/whatsnew/v0.23.0.txt +++ b/doc/source/whatsnew/v0.23.0.txt @@ -842,7 +842,7 @@ Deprecations - ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`) - ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`) - ``NDFrame.get_ftype_counts()`` is deprecated and will be removed in a future version (:issue:`18243`) -- The ``convert_datetime64`` parameter in :func:`DataFrame.to_records` has been deprecated and will be removed in a future version. The NumPy bug motivating this parameter has been resolved (:issue:`18160`). +- The ``convert_datetime64`` parameter in :func:`DataFrame.to_records` has been deprecated and will be removed in a future version. The NumPy bug motivating this parameter has been resolved. The default value for this parameter has also changed from ``True`` to ``None`` (:issue:`18160`). .. _whatsnew_0230.prior_deprecations: diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 7453755528ecf..7c0e367e74ffa 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1311,7 +1311,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None, return cls(mgr) - def to_records(self, index=True, convert_datetime64=False): + def to_records(self, index=True, convert_datetime64=None): """ Convert DataFrame to a NumPy record array. @@ -1322,7 +1322,7 @@ def to_records(self, index=True, convert_datetime64=False): ---------- index : boolean, default True Include index in resulting record array, stored in 'index' field. - convert_datetime64 : boolean, default False + convert_datetime64 : boolean, default None .. deprecated:: 0.23.0 Whether to convert the index to datetime.datetime if it is a @@ -1379,7 +1379,7 @@ def to_records(self, index=True, convert_datetime64=False): dtype=[('index', '