Skip to content

Commit ef72e04

Browse files
committed
DEPR: convert_datetime64 parameter in to_records()
1 parent 14889f1 commit ef72e04

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
@@ -774,6 +774,7 @@ Deprecations
774774
- ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`)
775775
- ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`)
776776
- ``NDFrame.get_ftype_counts()`` is deprecated and will be removed in a future version (:issue:`18243`)
777+
- 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`).
777778

778779
.. _whatsnew_0230.prior_deprecations:
779780

pandas/core/frame.py

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

12891289
return cls(mgr)
12901290

1291-
def to_records(self, index=True, convert_datetime64=True):
1291+
def to_records(self, index=True, convert_datetime64=False):
12921292
"""
12931293
Convert DataFrame to a NumPy record array.
12941294
@@ -1299,7 +1299,9 @@ def to_records(self, index=True, convert_datetime64=True):
12991299
----------
13001300
index : boolean, default True
13011301
Include index in resulting record array, stored in 'index' field.
1302-
convert_datetime64 : boolean, default True
1302+
convert_datetime64 : boolean, default False
1303+
.. deprecated:: 0.23.0
1304+
13031305
Whether to convert the index to datetime.datetime if it is a
13041306
DatetimeIndex.
13051307
@@ -1353,6 +1355,13 @@ def to_records(self, index=True, convert_datetime64=True):
13531355
('2018-01-01T09:01:00.000000000', 2, 0.75)],
13541356
dtype=[('index', '<M8[ns]'), ('A', '<i8'), ('B', '<f8')])
13551357
"""
1358+
1359+
if convert_datetime64:
1360+
warnings.warn("The 'convert_datetime64' parameter is "
1361+
"deprecated and will be removed in a future "
1362+
"version",
1363+
FutureWarning, stacklevel=2)
1364+
13561365
if index:
13571366
if is_datetime64_any_dtype(self.index) and convert_datetime64:
13581367
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)