Skip to content

Error when comparing equality of indexes #9785

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

Closed
dandavison opened this issue Apr 2, 2015 · 2 comments
Closed

Error when comparing equality of indexes #9785

dandavison opened this issue Apr 2, 2015 · 2 comments
Labels
Compat pandas objects compatability with Numpy or Python functions Error Reporting Incorrect or improved errors from pandas
Milestone

Comments

@dandavison
Copy link

In 0.16.0 comparing MultiIndices using == raises an exception.

from StringIO import StringIO
import pandas as pd

# create a series using a multiindex
df = pd.read_csv(StringIO('a,b,c\n1,2,3'), index_col=[0, 1])
series = df['c']

series.index == series.index
#   File "/Users/dan/venvs/pandas-0.16.0/lib/python2.7/site-packages/pandas/core/index.py", line 54, in wrapper
#     func = getattr(self._data.view(np.ndarray), opname)
# AttributeError: 'NoneType' object has no attribute 'view'

print pd.__version__
#0.16.0

Another one I've come across is that there is an AttributeError when comparing indexes for which the underlying numpy arrays cannot be broadcast together. The error message itself is very obscure. I gather that .equals() can be used for what I'm trying to do in these examples, but still the errors when using == are surprising.

>>> pd.Index(['a', 'b']) == pd.Index(['a', 'b', 'c'])
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-2-44325051df92> in <module>()
----> 1 pd.Index(['a', 'b']) == pd.Index(['a', 'b', 'c'])

/Users/dan/venvs/pandas-0.16.0/lib/python2.7/site-packages/pandas/core/index.pyc in wrapper(self, other)
     57         # technically we could support bool dtyped Index
     58         # for now just return the indexing array directly
---> 59         if is_bool_dtype(result):
     60             return result
     61         try:

/Users/dan/venvs/pandas-0.16.0/lib/python2.7/site-packages/pandas/core/common.py in is_bool_dtype(arr_or_dtype)
   2510
   2511 def is_bool_dtype(arr_or_dtype):
-> 2512     tipo = _get_dtype_type(arr_or_dtype)
   2513     return issubclass(tipo, np.bool_)
   2514

/Users/dan/venvs/pandas-0.16.0/lib/python2.7/site-packages/pandas/core/common.py in _get_dtype_type(arr_or_dtype)
   2439     elif isinstance(arr_or_dtype, CategoricalDtype):
   2440         return CategoricalDtypeType
-> 2441     return arr_or_dtype.dtype.type
   2442
   2443

AttributeError: 'NotImplementedType' object has no attribute 'dtype'
@jreback jreback added Error Reporting Incorrect or improved errors from pandas Compat pandas objects compatability with Numpy or Python functions labels Apr 2, 2015
@jreback jreback added this to the Next Major Release milestone Apr 2, 2015
@jreback
Copy link
Contributor

jreback commented Apr 2, 2015

.equals() is the comparator here as is compares a whether indexes of different types can be equal as well as the elements themselves (e.g. this is dtype and value). While == is an element-wise comparison and is pretty raw. It is pretty long established to use .equals().

All that said, If you can catch errors and produce a better error message, all for it.

@jreback jreback modified the milestones: 0.16.1, Next Major Release Apr 13, 2015
pykler added a commit to LeadSift/pandas that referenced this issue Apr 13, 2015
pykler added a commit to LeadSift/pandas that referenced this issue Apr 13, 2015
pykler added a commit to LeadSift/pandas that referenced this issue Apr 13, 2015
pykler added a commit to LeadSift/pandas that referenced this issue Apr 13, 2015
@jreback
Copy link
Contributor

jreback commented Apr 14, 2015

closed by #9872

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Compat pandas objects compatability with Numpy or Python functions Error Reporting Incorrect or improved errors from pandas
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants