Skip to content

BUG: Index set operations issues #13432

Closed
@pijucha

Description

@pijucha

Issues:


Index.difference and symmetric_difference raise for mixed types

Code Sample, a copy-pastable example if possible

idx1 = pd.Index([0, 1, 'A', 'B'])
idx2 = pd.Index([0, 2, 'A', 'C'])

idx1.difference(idx2)
...
  File "/usr/local/lib64/python3.5/site-packages/pandas/indexes/base.py", line 1861, in difference
    theDiff = sorted(set(self) - set(other))
TypeError: unorderable types: str() < int()

idx1.symmetric_difference(idx2)
...
  File "/usr/local/lib64/python3.5/site-packages/pandas/indexes/base.py", line 1861, in difference
    theDiff = sorted(set(self) - set(other))
TypeError: unorderable types: str() < int()

But union and intersection work:

idx1.union(idx2)
Out[14]: Index([0, 1, 'A', 'B', 2, 'C'], dtype='object')
idx1.intersection(idx2)
Out[15]: Index([0, 'A'], dtype='object')

Expected Output

idx1.difference(idx2)
Out[]: Index([1, 'B'], dtype='object')

idx1.symmetric_difference(idx2)
Out[]: Index([1, 'B', 2, 'C'], dtype='object')

output of pd.show_versions()

INSTALLED VERSIONS
------------------
commit: 4a6621fcaa9a3b98172b90a69de574ec94b108df
python: 3.5.1.final.0
python-bits: 64
OS: Linux
machine: x86_64
byteorder: little

pandas: 0.18.1
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions