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

Symmetric difference on equal MultiIndexes raises TypeError #13490

Closed
adament opened this issue Jun 20, 2016 · 2 comments · Fixed by #16486
Closed

Symmetric difference on equal MultiIndexes raises TypeError #13490

adament opened this issue Jun 20, 2016 · 2 comments · Fixed by #16486
Labels
Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves
Milestone

Comments

@adament
Copy link

adament commented Jun 20, 2016

Calling symmetric_difference on two equal multiindices results in a TypeError rather than an empty MultiIndex. This is surprising since calling difference on the same multiindices results in the expected empty MultiIndex.

Code Sample, a copy-pastable example if possible

a = pandas.MultiIndex.from_product([['a', 'b'], [0, 1]])
b = pandas.MultiIndex.from_product([['a', 'b'], [0, 1]])
print(a.symmetric_difference(b))

Which gives the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Miniconda3\envs\balancedbeta\lib\site-packages\pandas\indexes\base.py", line 1674, in __xor__
    return self.symmetric_difference(other)
  File "C:\Miniconda3\envs\balancedbeta\lib\site-packages\pandas\indexes\base.py", line 1911, in symmetric_difference
    return self._shallow_copy_with_infer(the_diff, **attribs)
  File "C:\Miniconda3\envs\balancedbeta\lib\site-packages\pandas\indexes\multi.py", line 387, in _shallow_copy_with_infer
    return self._shallow_copy(values, **kwargs)
  File "C:\Miniconda3\envs\balancedbeta\lib\site-packages\pandas\indexes\multi.py", line 396, in _shallow_copy
    return MultiIndex.from_tuples(values, **kwargs)
  File "C:\Miniconda3\envs\balancedbeta\lib\site-packages\pandas\indexes\multi.py", line 883, in from_tuples
    raise TypeError('Cannot infer number of levels from empty list')
TypeError: Cannot infer number of levels from empty list

Expected Output

MultiIndex(levels=[[], []], labels = [[], []])

output of pd.show_versions()

INSTALLED VERSIONS                                                          
------------------                                                          
commit: None                                                                
python: 2.7.11.final.0                                                      
python-bits: 64                                                             
OS: Windows                                                                 
OS-release: 7                                                               
machine: AMD64                                                              
processor: Intel64 Family 6 Model 61 Stepping 4, GenuineIntel               
byteorder: little                                                           
LC_ALL: None                                                                
LANG: DA                                                                    

pandas: 0.18.1                                                              
nose: None                                                                  
pip: 8.1.1                                                                  
setuptools: 20.7.0                                                          
Cython: 0.23                                                                
numpy: 1.10.4                                                               
scipy: 0.17.0                                                               
statsmodels: 0.6.1                                                          
xarray: None                                                                
IPython: 4.2.0                                                              
sphinx: None                                                                
patsy: 0.4.1                                                                
dateutil: 2.5.2                                                             
pytz: 2016.3                                                                
blosc: None                                                                 
bottleneck: None                                                            
tables: 3.2.2                                                               
numexpr: 2.5.2                                                              
matplotlib: 1.5.1                                                           
openpyxl: None                                                              
xlrd: None                                                                  
xlwt: None                                                                  
xlsxwriter: None                                                            
lxml: None                                                                  
bs4: None                                                                   
html5lib: None                                                              
httplib2: None                                                              
apiclient: None                                                             
sqlalchemy: 1.0.12                                                          
pymysql: None                                                               
psycopg2: None                                                              
jinja2: 2.8                                                                 
boto: None                                                                  
pandas_datareader: None                                                     
@jreback
Copy link
Contributor

jreback commented Jun 21, 2016

yeah I agree, on empties this should behave the same as .difference / .union

cc @TomAugspurger

@jreback jreback added Indexing Related to indexing on series/frames, not to indexes themselves Error Reporting Incorrect or improved errors from pandas labels Jun 21, 2016
@jreback jreback added this to the Next Major Release milestone Jun 21, 2016
@TomAugspurger
Copy link
Contributor

Agreed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Error Reporting Incorrect or improved errors from pandas Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
3 participants