Skip to content

df.join(df2, how='right') TypeError: Argument 'left' has incorrect type (expected numpy.ndarray, got Int64Index) #11519

Closed
@dragoljub

Description

@dragoljub

I have found that 'right' joins on index values raise TypeEerror: Argument 'left' has incorrect type (expected numpy.ndarray, got Int64Index).

Both index types are the same Int64Index index. This works in pandas 0.13.1.

Pandas: 0.17.0
Numpy: 1.9.2

import pandas as pd
import numpy as np

df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar',
                          'foo', 'bar', 'foo', 'foo'],
                    'B' : ['one', 'one', 'two', 'three',
                          'two', 'two', 'one', 'three'],
                    'C' : np.random.randn(8),
                    'D' : np.random.randn(8)})

s = pd.Series(np.repeat(np.arange(8),2), index=np.repeat(np.arange(8),2), name='TEST')

In []: s.head()

Out[]:
0    0
0    0
1    1
1    1
2    2
dtype: int32

# The following all work as expected
df.join(s, how='inner') 
df.join(s, how='outer')
df.join(s, how='left')

# Right Joins Type Error
df.join(s, how='right') 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-80-26e8bf54fd8f> in <module>()
----> 1 df.join(s, how='right')

D:\Python27\lib\site-packages\pandas\core\frame.pyc in join(self, other, on, how, lsuffix, rsuffix, sort)
   4218         # For SparseDataFrame's benefit
   4219         return self._join_compat(other, on=on, how=how, lsuffix=lsuffix,
-> 4220                                  rsuffix=rsuffix, sort=sort)
   4221 
   4222     def _join_compat(self, other, on=None, how='left', lsuffix='', rsuffix='',

D:\Python27\lib\site-packages\pandas\core\frame.pyc in _join_compat(self, other, on, how, lsuffix, rsuffix, sort)
   4232             return merge(self, other, left_on=on, how=how,
   4233                          left_index=on is None, right_index=True,
-> 4234                          suffixes=(lsuffix, rsuffix), sort=sort)
   4235         else:
   4236             if on is not None:

D:\Python27\lib\site-packages\pandas\tools\merge.pyc in merge(left, right, how, on, left_on, right_on, left_index, right_index, sort, suffixes, copy, indicator)
     33                          right_index=right_index, sort=sort, suffixes=suffixes,
     34                          copy=copy, indicator=indicator)
---> 35     return op.get_result()
     36 if __debug__:
     37     merge.__doc__ = _merge_doc % '\nleft : DataFrame'

D:\Python27\lib\site-packages\pandas\tools\merge.pyc in get_result(self)
    194             self.left, self.right = self._indicator_pre_merge(self.left, self.right)
    195 
--> 196         join_index, left_indexer, right_indexer = self._get_join_info()
    197 
    198         ldata, rdata = self.left._data, self.right._data

D:\Python27\lib\site-packages\pandas\tools\merge.pyc in _get_join_info(self)
    309         if self.left_index and self.right_index:
    310             join_index, left_indexer, right_indexer = \
--> 311                 left_ax.join(right_ax, how=self.how, return_indexers=True)
    312         elif self.right_index and self.how == 'left':
    313             join_index, left_indexer, right_indexer = \

D:\Python27\lib\site-packages\pandas\core\index.pyc in join(self, other, how, level, return_indexers)
   2212             if self.is_monotonic and other.is_monotonic:
   2213                 return self._join_monotonic(other, how=how,
-> 2214                                             return_indexers=return_indexers)
   2215             else:
   2216                 return self._join_non_unique(other, how=how,

D:\Python27\lib\site-packages\pandas\core\index.pyc in _join_monotonic(self, other, how, return_indexers)
   2463                 join_index, lidx, ridx = self._left_indexer(sv, ov)
   2464             elif how == 'right':
-> 2465                 join_index, ridx, lidx = self._left_indexer(other, self)
   2466             elif how == 'inner':
   2467                 join_index, lidx, ridx = self._inner_indexer(sv, ov)

TypeError: Argument 'left' has incorrect type (expected numpy.ndarray, got Int64Index)

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions