Skip to content

Commit cd11b49

Browse files
Merge c27dfb2 into 044feb5
2 parents 044feb5 + c27dfb2 commit cd11b49

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-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

+8-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,13 @@ 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+
218+
# this construction raises IndexError in pandas=0.20.1
219+
result = DataFrame(np.array([[NaT, 'a', 'b', 0],
220+
[NaT, 'c', 'd', 1]]))
221+
assert result.size
222+
216223

217224
class TestConvert(object):
218225

0 commit comments

Comments
 (0)