Skip to content

BUG: fixed platform int issues on 32-bit #3620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pandas/core/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -1612,13 +1612,13 @@ def _astype_nansafe(arr, dtype, copy = True):
if is_datetime64_dtype(arr):
if dtype == object:
return tslib.ints_to_pydatetime(arr.view(np.int64))
elif issubclass(dtype.type, np.int):
elif dtype == np.int64:
return arr.view(dtype)
elif dtype != _NS_DTYPE:
raise TypeError("cannot astype a datetimelike from [%s] to [%s]" % (arr.dtype,dtype))
return arr.astype(_NS_DTYPE)
elif is_timedelta64_dtype(arr):
if issubclass(dtype.type, np.int):
if dtype == np.int64:
return arr.view(dtype)
elif dtype == object:
return arr.astype(object)
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/indexing.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ def _convert_for_reindex(self, key, axis=0):
keyarr = _asarray_tuplesafe(key)

if _is_integer_dtype(keyarr) and not _is_integer_index(labels):
keyarr = com._ensure_platform_int(keyarr)
return labels.take(keyarr)

return keyarr
Expand Down Expand Up @@ -466,10 +467,11 @@ def _reindex(keys, level=None):
if len(missing):
l = np.arange(len(indexer))

missing = com._ensure_platform_int(missing)
missing_labels = keyarr.take(missing)
missing_labels_indexer = l[~check]
missing_labels_indexer = com._ensure_int64(l[~check])
cur_labels = result._get_axis(axis).values
cur_labels_indexer = l[check]
cur_labels_indexer = com._ensure_int64(l[check])
new_labels = lib.combine_from_indexers(cur_labels, cur_labels_indexer,
missing_labels, missing_labels_indexer)
result = result.reindex_axis(new_labels,axis=axis)
Expand Down
3 changes: 2 additions & 1 deletion pandas/tests/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -1878,10 +1878,11 @@ def test_constructor_dtype_timedelta64(self):
self.assertRaises(TypeError, td.astype, 'm8[%s]' % t)

# valid astype
td.astype('int')
td.astype('int64')

# this is an invalid casting
self.assertRaises(Exception, Series, [ timedelta(days=i) for i in range(3) ] + [ 'foo' ], dtype='m8[ns]' )
self.assertRaises(TypeError, td.astype, 'int32')

# leave as object here
td = Series([ timedelta(days=i) for i in range(3) ] + [ 'foo' ])
Expand Down