Skip to content

Commit

Permalink
DEPR: convert_datetime64 parameter in to_records()
Browse files Browse the repository at this point in the history
  • Loading branch information
reidy-p committed Dec 27, 2017
1 parent feef904 commit 1e1ebdb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ Deprecations
- ``Series.valid`` is deprecated. Use :meth:`Series.dropna` instead (:issue:`18800`).
- :func:`read_excel` has deprecated the ``skip_footer`` parameter. Use ``skipfooter`` instead (:issue:`18836`)
- The ``is_copy`` attribute is deprecated and will be removed in a future version (:issue:`18801`).
- 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:

Expand Down
13 changes: 11 additions & 2 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1187,7 +1187,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 record array. Index will be put in the
'index' field of the record array if requested
Expand All @@ -1196,14 +1196,23 @@ 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
Returns
-------
y : recarray
"""

if convert_datetime64:
warnings.warn("The 'convert_datetime64' parameter is "
"deprecated and will be removed in a future "
"version",
FutureWarning, stacklevel=2)

if index:
if is_datetime64_any_dtype(self.index) and convert_datetime64:
ix_vals = [self.index.to_pydatetime()]
Expand Down
5 changes: 4 additions & 1 deletion pandas/tests/frame/test_convert_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def test_to_records_dt64(self):
df = DataFrame([["one", "two", "three"],
["four", "five", "six"]],
index=date_range("2012-01-01", "2012-01-02"))
assert df.to_records()['index'][0] == df.index[0]
with tm.assert_produces_warning(FutureWarning):
expected = df.index[0]
result = df.to_records(convert_datetime64=True)['index'][0]
assert expected == result

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

0 comments on commit 1e1ebdb

Please sign in to comment.