Skip to content

Commit 7ad1e7d

Browse files
RobinFiveWordsRobinFiveWords
RobinFiveWords
authored and
RobinFiveWords
committed
redid lost changes to cast.py and test_cast.py
1 parent afa2eeb commit 7ad1e7d

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pandas/core/dtypes/cast.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ def try_timedelta(v):
837837
try:
838838
return to_timedelta(v)._values.reshape(shape)
839839
except:
840-
return v
840+
return v.reshape(shape)
841841

842842
inferred_type = lib.infer_datetimelike_array(_ensure_object(v))
843843

pandas/tests/dtypes/test_cast.py

+12-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from datetime import datetime, timedelta, date
1010
import numpy as np
1111

12-
from pandas import Timedelta, Timestamp, DatetimeIndex
12+
from pandas import Timedelta, Timestamp, DatetimeIndex, DataFrame, NaT
1313

1414
from pandas.core.dtypes.cast import (
1515
maybe_downcast_to_dtype,
@@ -213,6 +213,17 @@ def test_maybe_convert_scalar(self):
213213
result = maybe_convert_scalar(Timedelta('1 day 1 min'))
214214
assert result == Timedelta('1 day 1 min').value
215215

216+
def test_maybe_infer_to_datetimelike(self):
217+
# GH16362
218+
# pandas=0.20.1 raises IndexError: tuple index out of range
219+
result = DataFrame(np.array([[NaT, 'a', 'b', 0],
220+
[NaT, 'b', 'c', 1]]))
221+
assert result.size == 8
222+
# this construction was fine
223+
result = DataFrame(np.array([[NaT, 'a', 0],
224+
[NaT, 'b', 1]]))
225+
assert result.size == 6
226+
216227

217228
class TestConvert(object):
218229

0 commit comments

Comments
 (0)