Skip to content

.at does not work using a categorical index. #25881

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
TyberiusPrime opened this issue Mar 26, 2019 · 1 comment
Closed

.at does not work using a categorical index. #25881

TyberiusPrime opened this issue Mar 26, 2019 · 1 comment
Labels
Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves

Comments

@TyberiusPrime
Copy link

Code Sample, a copy-pastable example if possible

df = pd.DataFrame({
    "x": pd.Categorical(["a", "b", "c"]), 
      "y": [10, 20, 30]}
).set_index("x")
print(df.index)
print(df.loc["a"]["y"])
print(df.at["a", "y"])

Problem description

Loc works using a categorical index, at does not.
Both should work.

Expected Output

CategoricalIndex(['a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=False, name='x', dtype='category')
10
10

Actual output

CategoricalIndex(['a', 'b', 'c'], categories=['a', 'b', 'c'], ordered=False, name='x', dtype='category')
10
Traceback (most recent call last):
  File "test.py", line 9, in <module>
    print(df.at["a", "y"])
  File "/rose/temp/shu/pandas/pandas/core/indexing.py", line 2277, in __getitem__
    return self.obj._get_value(*key, takeable=self._takeable)
  File "/rose/temp/shu/pandas/pandas/core/frame.py", line 2720, in _get_value
    return engine.get_value(series._values, index)
  File "pandas/_libs/index.pyx", line 81, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 89, in pandas._libs.index.IndexEngine.get_value
  File "pandas/_libs/index.pyx", line 129, in pandas._libs.index.IndexEngine.get_loc
  File "pandas/_libs/index_class_helper.pxi", line 214, in pandas._libs.index.Int8Engine._check_type

Output of pd.show_versions()

INSTALLED VERSIONS

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

pandas: 0.25.0.dev0+321.gb878f5b
pytest: None
pip: 19.0.1
setuptools: 40.8.0
Cython: 0.29.6
numpy: 1.16.2
scipy: None
pyarrow: None
xarray: None
IPython: None
sphinx: 1.8.5
patsy: None
dateutil: 2.8.0
pytz: 2018.9
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: None
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: None
bs4: None
html5lib: None
sqlalchemy: None
pymysql: None
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: None
pandas_gbq: None
pandas_datareader: None
gcsfs: None
Traceback (most recent

@jbrockmendel jbrockmendel added Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves labels Jul 23, 2019
@topper-123
Copy link
Contributor

This is a duplicate of #20629 and has been fixed in #26298. Closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Categorical Categorical Data Type Indexing Related to indexing on series/frames, not to indexes themselves
Projects
None yet
Development

No branches or pull requests

3 participants