Skip to content

Commit d9c9d7c

Browse files
committed
convert_datetime64 defaults to True if not passed
1 parent 529fbbc commit d9c9d7c

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pandas/core/frame.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ def to_records(self, index=True, convert_datetime64=None):
12121212
----------
12131213
index : boolean, default True
12141214
Include index in resulting record array, stored in 'index' field
1215-
convert_datetime64 : boolean, optional
1215+
convert_datetime64 : boolean, default True
12161216
.. deprecated:: 0.23.0
12171217
12181218
Whether to convert the index to datetime.datetime if it is a
@@ -1228,6 +1228,8 @@ def to_records(self, index=True, convert_datetime64=None):
12281228
"deprecated and will be removed in a future "
12291229
"version",
12301230
FutureWarning, stacklevel=2)
1231+
else:
1232+
convert_datetime64 = True
12311233

12321234
if index:
12331235
if is_datetime64_any_dtype(self.index) and convert_datetime64:

pandas/tests/frame/test_convert_to.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,17 @@ 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+
8182
with tm.assert_produces_warning(FutureWarning):
8283
expected = df.index[0]
8384
result = df.to_records(convert_datetime64=True)['index'][0]
8485
assert expected == result
8586

87+
expected = df.index[0]
88+
# convert_datetime64 defaults to True if not passed
89+
result = df.to_records()['index'][0]
90+
assert expected == result
91+
8692
with tm.assert_produces_warning(FutureWarning):
8793
rs = df.to_records(convert_datetime64=False)
8894
assert rs['index'][0] == df.index.values[0]

0 commit comments

Comments
 (0)