Skip to content
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

exception joining dataframes with different datatypes #486

CRP opened this issue Dec 14, 2011 · 1 comment


Copy link

commented Dec 14, 2011

In [71]: a=DataFrame(randn(10,2),columns=['a','b'])

In [72]: b=DataFrame(randn(10,1),columns=['c']).astype(np.float32)

In [73]: a.join(b)

TypeError Traceback (most recent call last)
/Users/c.prinoth/ in ()
----> 1 a.join(b)

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/frame.pyc in join(self, other, on, how, lsuffix, rsuffix)
2614 return self._join_on(other, on, how, lsuffix, rsuffix)
2615 else:
-> 2616 return self._join_index(other, how, lsuffix, rsuffix)
2618 def _join_on(self, other, on, how, lsuffix, rsuffix):

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/frame.pyc in _join_index(self, other, how, lsuffix, rsuffix)
2650 # this will always ensure copied data

-> 2651 merged_data = join_managers(thisdata, otherdata, axis=1, how=how)
2652 return self._constructor(merged_data)

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/internals.pyc in join_managers(left, right, axis, how, copy)
1032 def join_managers(left, right, axis=1, how='left', copy=True):
1033 op = _JoinOperation(left, right, axis=axis, how=how)
-> 1034 return op.get_result(copy=copy)
1036 class _JoinOperation(object):

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/internals.pyc in get_result(self, copy)
1090 if lblk and rblk:
1091 # true merge, do not produce intermediate copy

-> 1092 res_blk = self._merge_blocks(lblk, rblk)
1093 elif lblk:
1094 res_blk = self._reindex_block(lblk, side='left')

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/internals.pyc in _merge_blocks(self, lblk, rblk)
1206 else:
1207 common.take_fast(rblk.values, ridx, None, False,
-> 1208 axis=self.axis, out=out[lk:])
1210 # does not sort

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/common.pyc in take_fast(arr, indexer, mask, needs_masking, axis, out)
247 return take_2d(arr, indexer, out=out, mask=mask,
248 needs_masking=needs_masking,
--> 249 axis=axis)
251 result = arr.take(indexer, axis=axis, out=out)

/usr/local/Cellar/python/2.7.2/lib/python2.7/site-packages/pandas/core/common.pyc in take_2d(arr, indexer, out, mask, needs_masking, axis)
232 needs_masking = mask.any()
--> 234 result = arr.take(indexer, axis=axis, out=out)
235 result = _maybe_mask(result, mask, needs_masking, axis=axis,
236 out_passed=out is not None)

TypeError: array cannot be safely cast to required type

In [77]: a.dtypes
a float64
b float64

In [78]: b.dtypes
Out[78]: c float32


This comment has been minimized.

Copy link

commented Dec 15, 2011

Fixed the underlying cause of this. Thanks for reporting

@wesm wesm closed this Dec 15, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.