Skip to content

Commit d5d5a71

Browse files
reidy-pjreback
authored andcommitted
DEPR: convert_datetime64 parameter in to_records() (pandas-dev#18902)
1 parent ec7968d commit d5d5a71

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

doc/source/whatsnew/v0.23.0.txt

+1
Original file line numberDiff line numberDiff line change
@@ -842,6 +842,7 @@ Deprecations
842842
- ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`)
843843
- ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`)
844844
- ``NDFrame.get_ftype_counts()`` is deprecated and will be removed in a future version (:issue:`18243`)
845+
- 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`).
845846

846847
.. _whatsnew_0230.prior_deprecations:
847848

pandas/core/frame.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -1311,7 +1311,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None,
13111311

13121312
return cls(mgr)
13131313

1314-
def to_records(self, index=True, convert_datetime64=True):
1314+
def to_records(self, index=True, convert_datetime64=None):
13151315
"""
13161316
Convert DataFrame to a NumPy record array.
13171317
@@ -1322,7 +1322,9 @@ def to_records(self, index=True, convert_datetime64=True):
13221322
----------
13231323
index : boolean, default True
13241324
Include index in resulting record array, stored in 'index' field.
1325-
convert_datetime64 : boolean, default True
1325+
convert_datetime64 : boolean, default None
1326+
.. deprecated:: 0.23.0
1327+
13261328
Whether to convert the index to datetime.datetime if it is a
13271329
DatetimeIndex.
13281330
@@ -1376,6 +1378,13 @@ def to_records(self, index=True, convert_datetime64=True):
13761378
('2018-01-01T09:01:00.000000000', 2, 0.75)],
13771379
dtype=[('index', '<M8[ns]'), ('A', '<i8'), ('B', '<f8')])
13781380
"""
1381+
1382+
if convert_datetime64 is not None:
1383+
warnings.warn("The 'convert_datetime64' parameter is "
1384+
"deprecated and will be removed in a future "
1385+
"version",
1386+
FutureWarning, stacklevel=2)
1387+
13791388
if index:
13801389
if is_datetime64_any_dtype(self.index) and convert_datetime64:
13811390
ix_vals = [self.index.to_pydatetime()]

pandas/tests/frame/test_convert_to.py

+16-3
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,23 @@ 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]
8382

84-
rs = df.to_records(convert_datetime64=False)
85-
assert rs['index'][0] == df.index.values[0]
83+
# convert_datetime64 defaults to None
84+
expected = df.index.values[0]
85+
result = df.to_records()['index'][0]
86+
assert expected == result
87+
88+
# check for FutureWarning if convert_datetime64=False is passed
89+
with tm.assert_produces_warning(FutureWarning):
90+
expected = df.index.values[0]
91+
result = df.to_records(convert_datetime64=False)['index'][0]
92+
assert expected == result
93+
94+
# check for FutureWarning if convert_datetime64=True is passed
95+
with tm.assert_produces_warning(FutureWarning):
96+
expected = df.index[0]
97+
result = df.to_records(convert_datetime64=True)['index'][0]
98+
assert expected == result
8699

87100
def test_to_records_with_multindex(self):
88101
# GH3189

0 commit comments

Comments
 (0)