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

Series.at and DataFrame.at crash with CategoricalIndex #20629

Closed
Kodiologist opened this issue Apr 7, 2018 · 1 comment

Comments

@Kodiologist
Copy link
Contributor

commented Apr 7, 2018

Code Sample, a copy-pastable example if possible

Python 3.6.3 (default, Oct  3 2017, 21:45:48) 
[GCC 7.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import pandas as pd
>>> x = pd.Series([1, 2, 3], index=pd.CategoricalIndex(["A", "B", "C"]))
>>> x.loc["A"]
1
>>> x.at["A"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py", line 1869, in __getitem__
    return self.obj._get_value(*key, takeable=self._takeable)
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/series.py", line 929, in _get_value
    return self.index.get_value(self._values, label)
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/category.py", line 423, in get_value
    return series.iloc[indexer]
AttributeError: 'numpy.ndarray' object has no attribute 'iloc'
>>> x = pd.DataFrame([[1, 2], [3, 4], [5, 6]], index=pd.CategoricalIndex(["A", "B", "C"]))
>>> x.loc["B", 1]
4
>>> x.at["B", 1]
Traceback (most recent call last):
  File "pandas/_libs/index.pyx", line 139, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/hashtable_class_helper.pxi", line 811, in pandas._libs.hashtable.Int64HashTable.get_item
TypeError: an integer is required

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/indexing.py", line 1869, in __getitem__
    return self.obj._get_value(*key, takeable=self._takeable)
  File "/usr/local/lib/python3.6/dist-packages/pandas/core/frame.py", line 1985, in _get_value
    return engine.get_value(series._values, index)
  File "pandas/_libs/index.pyx", line 83, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 91, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 141, in pandas._libs.index.IndexEngine.get_loc
KeyError: 'B'

Problem description

With a CategoricalIndex, Series.at raises AttributeError and DataFrame.at raises TypeError and KeyError.

Expected Output

x.at["A"] should work the same as x.loc["A"], and x.at["B", 1] should work the same as x.loc["B", 1].

Output of pd.show_versions()

commit: None
python: 3.6.3.final.0
python-bits: 64
OS: Linux
OS-release: 4.13.0-37-generic
machine: x86_64
processor: x86_64
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.22.0
pytest: 3.4.0
pip: 9.0.3
setuptools: 39.0.1
Cython: None
numpy: 1.14.2
scipy: 1.0.0
pyarrow: None
xarray: None
IPython: None
sphinx: 1.6.7
patsy: 0.4.1
dateutil: 2.7.2
pytz: 2018.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.2.2
openpyxl: 2.4.9
xlrd: 1.1.0
xlwt: None
xlsxwriter: None
lxml: 4.0.0
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.0
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None

@jorisvandenbossche jorisvandenbossche added this to the Next Major Release milestone Apr 9, 2018

@jorisvandenbossche

This comment has been minimized.

Copy link
Member

commented Apr 9, 2018

Thanks for the report, that's clearly a bug.

Related issue (on indexing with categorical index): #14865

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.