Skip to content

Commit 034cf42

Browse files
committed
DEPR: convert_datetime64 parameter in to_records()
1 parent 316acbf commit 034cf42

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
@@ -216,6 +216,7 @@ Deprecations
216216
- ``Series.valid`` is deprecated. Use :meth:`Series.dropna` instead (:issue:`18800`).
217217
- :func:`read_excel` has deprecated the ``skip_footer`` parameter. Use ``skipfooter`` instead (:issue:`18836`)
218218
- The ``is_copy`` attribute is deprecated and will be removed in a future version (:issue:`18801`).
219+
- 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`).
219220

220221
.. _whatsnew_0230.prior_deprecations:
221222

pandas/core/frame.py

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

11881188
return cls(mgr)
11891189

1190-
def to_records(self, index=True, convert_datetime64=True):
1190+
def to_records(self, index=True, convert_datetime64=False):
11911191
"""
11921192
Convert DataFrame to record array. Index will be put in the
11931193
'index' field of the record array if requested
@@ -1196,14 +1196,23 @@ def to_records(self, index=True, convert_datetime64=True):
11961196
----------
11971197
index : boolean, default True
11981198
Include index in resulting record array, stored in 'index' field
1199-
convert_datetime64 : boolean, default True
1199+
convert_datetime64 : boolean, default False
1200+
.. deprecated:: 0.23.0
1201+
12001202
Whether to convert the index to datetime.datetime if it is a
12011203
DatetimeIndex
12021204
12031205
Returns
12041206
-------
12051207
y : recarray
12061208
"""
1209+
1210+
if convert_datetime64:
1211+
warnings.warn("The 'convert_datetime64' parameter is "
1212+
"deprecated and will be removed in a future "
1213+
"version",
1214+
FutureWarning, stacklevel=2)
1215+
12071216
if index:
12081217
if is_datetime64_any_dtype(self.index) and convert_datetime64:
12091218
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
@@ -78,7 +78,10 @@ def test_to_records_dt64(self):
7878
df = DataFrame([["one", "two", "three"],
7979
["four", "five", "six"]],
8080
index=date_range("2012-01-01", "2012-01-02"))
81-
assert df.to_records()['index'][0] == df.index[0]
81+
with tm.assert_produces_warning(FutureWarning):
82+
expected = df.index[0]
83+
result = df.to_records(convert_datetime64=True)['index'][0]
84+
assert expected == result
8285

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

0 commit comments

Comments
 (0)