Skip to content

Commit 7e6095a

Browse files
committed
DEPR: convert_datetime64 parameter in to_records()
1 parent d2ab407 commit 7e6095a

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

doc/source/whatsnew/v0.23.0.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -832,6 +832,7 @@ Deprecations
832832
- ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`)
833833
- ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`)
834834
- ``NDFrame.get_ftype_counts()`` is deprecated and will be removed in a future version (:issue:`18243`)
835+
- 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`).
835836

836837
.. _whatsnew_0230.prior_deprecations:
837838

pandas/core/frame.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1297,7 +1297,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None,
12971297

12981298
return cls(mgr)
12991299

1300-
def to_records(self, index=True, convert_datetime64=True):
1300+
def to_records(self, index=True, convert_datetime64=False):
13011301
"""
13021302
Convert DataFrame to a NumPy record array.
13031303
@@ -1308,7 +1308,9 @@ def to_records(self, index=True, convert_datetime64=True):
13081308
----------
13091309
index : boolean, default True
13101310
Include index in resulting record array, stored in 'index' field.
1311-
convert_datetime64 : boolean, default True
1311+
convert_datetime64 : boolean, default False
1312+
.. deprecated:: 0.23.0
1313+
13121314
Whether to convert the index to datetime.datetime if it is a
13131315
DatetimeIndex.
13141316
@@ -1362,6 +1364,13 @@ def to_records(self, index=True, convert_datetime64=True):
13621364
('2018-01-01T09:01:00.000000000', 2, 0.75)],
13631365
dtype=[('index', '<M8[ns]'), ('A', '<i8'), ('B', '<f8')])
13641366
"""
1367+
1368+
if convert_datetime64:
1369+
warnings.warn("The 'convert_datetime64' parameter is "
1370+
"deprecated and will be removed in a future "
1371+
"version",
1372+
FutureWarning, stacklevel=2)
1373+
13651374
if index:
13661375
if is_datetime64_any_dtype(self.index) and convert_datetime64:
13671376
ix_vals = [self.index.to_pydatetime()]

pandas/tests/frame/test_convert_to.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ def test_to_records_dt64(self):
7979
df = DataFrame([["one", "two", "three"],
8080
["four", "five", "six"]],
8181
index=date_range("2012-01-01", "2012-01-02"))
82-
assert df.to_records()['index'][0] == df.index[0]
82+
with tm.assert_produces_warning(FutureWarning):
83+
expected = df.index[0]
84+
result = df.to_records(convert_datetime64=True)['index'][0]
85+
assert expected == result
8386

8487
rs = df.to_records(convert_datetime64=False)
8588
assert rs['index'][0] == df.index.values[0]

0 commit comments

Comments
 (0)