Skip to content

Commit

Permalink
Make default for convert_datetime64=None and adjust tests
Browse files Browse the repository at this point in the history
  • Loading branch information
reidy-p committed Apr 14, 2018
1 parent 9837eb0 commit b0cc2be
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v0.23.0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -842,7 +842,7 @@ Deprecations
- ``pandas.tseries.plotting.tsplot`` is deprecated. Use :func:`Series.plot` instead (:issue:`18627`)
- ``Index.summary()`` is deprecated and will be removed in a future version (:issue:`18217`)
- ``NDFrame.get_ftype_counts()`` is deprecated and will be removed in a future version (:issue:`18243`)
- 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 (:issue:`18160`).
- 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`).

.. _whatsnew_0230.prior_deprecations:

Expand Down
6 changes: 3 additions & 3 deletions pandas/core/frame.py
Original file line number Diff line number Diff line change
Expand Up @@ -1311,7 +1311,7 @@ def from_records(cls, data, index=None, exclude=None, columns=None,

return cls(mgr)

def to_records(self, index=True, convert_datetime64=False):
def to_records(self, index=True, convert_datetime64=None):
"""
Convert DataFrame to a NumPy record array.
Expand All @@ -1322,7 +1322,7 @@ def to_records(self, index=True, convert_datetime64=False):
----------
index : boolean, default True
Include index in resulting record array, stored in 'index' field.
convert_datetime64 : boolean, default False
convert_datetime64 : boolean, default None
.. deprecated:: 0.23.0
Whether to convert the index to datetime.datetime if it is a
Expand Down Expand Up @@ -1379,7 +1379,7 @@ def to_records(self, index=True, convert_datetime64=False):
dtype=[('index', '<M8[ns]'), ('A', '<i8'), ('B', '<f8')])
"""

if convert_datetime64:
if convert_datetime64 is not None:
warnings.warn("The 'convert_datetime64' parameter is "
"deprecated and will be removed in a future "
"version",
Expand Down
15 changes: 11 additions & 4 deletions pandas/tests/frame/test_convert_to.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,17 +80,24 @@ def test_to_records_dt64(self):
["four", "five", "six"]],
index=date_range("2012-01-01", "2012-01-02"))

# convert_datetime64 defaults to False if not passed
expected = df.index.values[0]
result = df.to_records()['index'][0]
assert expected == result
# convert_datetime64 defaults to None
expected = df.index.values
result = df.to_records()['index']
tm.assert_numpy_array_equal(expected, result)

# check for FutureWarning if convert_datetime64=False is passed
with tm.assert_produces_warning(FutureWarning):
expected = df.index.values
result = df.to_records(convert_datetime64=False)['index']
tm.assert_numpy_array_equal(expected, result)

# check for FutureWarning if convert_datetime64=True is passed
with tm.assert_produces_warning(FutureWarning):
expected = df.index[0]
result = df.to_records(convert_datetime64=True)['index'][0]
assert expected == result


def test_to_records_with_multindex(self):
# GH3189
index = [['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux'],
Expand Down

0 comments on commit b0cc2be

Please sign in to comment.