Skip to content

Alignment of CategoricalIndex #13365

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
toobaz opened this issue Jun 4, 2016 · 2 comments · Fixed by #51232
Closed

Alignment of CategoricalIndex #13365

toobaz opened this issue Jun 4, 2016 · 2 comments · Fixed by #51232
Labels
Bug Categorical Categorical Data Type Numeric Operations Arithmetic, Comparison, and Logical operations

Comments

@toobaz
Copy link
Member

toobaz commented Jun 4, 2016

Code Sample, a copy-pastable example if possible

In [2]: c = pd.CategoricalIndex(['3z53', '3z53', 'LoJG', 'LoJG', 'LoJG', 'N503'])

In [3]: s1 = pd.Series(2, index=c)

In [4]: s2 = pd.Series(2, index=c[:-1])

In [5]: s1*s2
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-5-7426096cfe41> in <module>()
----> 1 s1*s2

/home/pietro/nobackup/repo/pandas/pandas/core/ops.py in wrapper(left, right, name, na_op)
    647             else:
    648                 index, lidx, ridx = left.index.join(rindex, how='outer',
--> 649                                                     return_indexers=True)
    650 
    651                 if lidx is not None:

/home/pietro/nobackup/repo/pandas/pandas/indexes/base.py in join(self, other, how, level, return_indexers)
   2524         if not self.is_unique and not other.is_unique:
   2525             return self._join_non_unique(other, how=how,
-> 2526                                          return_indexers=return_indexers)
   2527         elif not self.is_unique or not other.is_unique:
   2528             if self.is_monotonic and other.is_monotonic:

/home/pietro/nobackup/repo/pandas/pandas/indexes/base.py in _join_non_unique(self, other, how, return_indexers)
   2616         join_index = self.values.take(left_idx)
   2617         mask = left_idx == -1
-> 2618         np.putmask(join_index, mask, other._values.take(right_idx))
   2619 
   2620         join_index = self._wrap_joined_index(join_index, other)

TypeError: putmask() argument 1 must be numpy.ndarray, not Categorical

Expected Output

No error

output of pd.show_versions()

In [6]: pd.show_versions()

INSTALLED VERSIONS
------------------
commit: None
python: 3.5.1.final.0
python-bits: 64
OS: Linux
OS-release: 4.5.0-2-amd64
machine: x86_64
processor: 
byteorder: little
LC_ALL: None
LANG: it_IT.utf8

pandas: 0.18.1+102.g0c6226c
nose: 1.3.7
pip: 1.5.6
setuptools: 18.4
Cython: 0.23.4
numpy: 1.10.4
scipy: 0.16.0
statsmodels: 0.8.0.dev0+0fac349
xarray: None
IPython: 5.0.0.dev
sphinx: 1.3.1
patsy: 0.3.0-dev
dateutil: 2.2
pytz: 2012c
blosc: None
bottleneck: 1.1.0dev
tables: 3.2.2
numexpr: 2.5
matplotlib: 1.5.1
openpyxl: None
xlrd: 0.9.4
xlwt: None
xlsxwriter: 0.7.3
lxml: None
bs4: 4.4.0
html5lib: 0.999
httplib2: 0.9.1
apiclient: 1.5.0
sqlalchemy: 1.0.11
pymysql: None
psycopg2: None
jinja2: 2.8
boto: 2.38.0
pandas_datareader: 0.2.1
@jreback
Copy link
Contributor

jreback commented Jun 5, 2016

These class of errors originate here. We don't properly support alignment on CI.

In [4]: s1.align(s2)
TypeError: putmask() argument 1 must be numpy.ndarray, not Categorical

@jreback jreback added Bug Indexing Related to indexing on series/frames, not to indexes themselves Dtype Conversions Unexpected or buggy dtype conversions Difficulty Advanced labels Jun 5, 2016
@jreback jreback added this to the Next Major Release milestone Jun 5, 2016
@jreback jreback changed the title TypeError when multiplying Series with CategoricalIndex of different lenght Alignment of CategoricalIndex Jun 5, 2016
toobaz added a commit to toobaz/pandas that referenced this issue Jun 25, 2016
@mroeschke
Copy link
Member

No longer raises an error on master but the result doesn't look correct.

In [81]: s1*s2
Out[81]:
0    4.0
0    4.0
0    4.0
0    4.0
1    4.0
1    4.0
1    4.0
1    4.0
1    4.0
1    4.0
1    4.0
1    4.0
1    4.0
2    NaN
dtype: float64

In [82]: pd.__version__
Out[82]: '0.26.0.dev0+652.g30362ed82'

@mroeschke mroeschke added Categorical Categorical Data Type Numeric Operations Arithmetic, Comparison, and Logical operations and removed Dtype Conversions Unexpected or buggy dtype conversions Indexing Related to indexing on series/frames, not to indexes themselves labels May 1, 2021
@mroeschke mroeschke removed this from the Contributions Welcome milestone Oct 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Categorical Categorical Data Type Numeric Operations Arithmetic, Comparison, and Logical operations
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants