Skip to content

Commit 95d67ea

Browse files
committed
FIX: Fix downcasting of float to timedelta.
1 parent f5ff061 commit 95d67ea

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

pandas/core/common.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1271,14 +1271,23 @@ def _possibly_downcast_to_dtype(result, dtype):
12711271
dtype = np.dtype(dtype)
12721272

12731273
try:
1274-
12751274
# don't allow upcasts here (except if empty)
1275+
print dtype.kind, result.dtype.kind
12761276
if dtype.kind == result.dtype.kind:
12771277
if result.dtype.itemsize <= dtype.itemsize and np.prod(result.shape):
12781278
return result
12791279

12801280
if issubclass(dtype.type, np.floating):
12811281
return result.astype(dtype)
1282+
1283+
# a datetimelike
1284+
elif ((dtype.kind == 'M' and result.dtype.kind == 'i') or
1285+
dtype.kind == 'm'):
1286+
try:
1287+
result = result.astype(dtype)
1288+
except:
1289+
pass
1290+
12821291
elif dtype == np.bool_ or issubclass(dtype.type, np.integer):
12831292

12841293
# if we don't have any elements, just astype it
@@ -1309,13 +1318,6 @@ def _possibly_downcast_to_dtype(result, dtype):
13091318
if (new_result == result).all():
13101319
return new_result
13111320

1312-
# a datetimelike
1313-
elif dtype.kind in ['M','m'] and result.dtype.kind in ['i']:
1314-
try:
1315-
result = result.astype(dtype)
1316-
except:
1317-
pass
1318-
13191321
except:
13201322
pass
13211323

0 commit comments

Comments
 (0)