BUG-20629 allow .at accessor with CategoricalIndex
State: closed

- [X] closes #20629
- [X] tests added / passed
- [X] passes `git diff upstream/master -u -- "*.py" | flake8 --diff`
- [X] whatsnew entry

This PR alters exception handling in various `get_value` functions to make calls to `.at` on non-integer `CategoricalIndex` fall back on positional indexing methods instead of raising exceptions, allowing queries like those mentioned in #20629.

Labels:
name: Bug
name: Indexing
description: Related to indexing on series/frames, not to indexes themselves
name: Categorical
description: Categorical Data Type

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=h1) Report
> Merging [#26298](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/94c8c94dccfa7934699c314420f0898d81425519?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/26298/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26298      +/-   ##
==========================================
- Coverage   91.98%   91.98%   -0.01%     
==========================================
  Files         175      175              
  Lines       52374    52381       +7     
==========================================
+ Hits        48178    48181       +3     
- Misses       4196     4200       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.53% <100%> (ø)` | :arrow_up: |
| #single | `40.71% <0%> (-0.16%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/category.py](https://codecov.io/gh/pandas-dev/pandas/pull/26298/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9jYXRlZ29yeS5weQ==) | `98.62% <100%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26298/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `96.91% <100%> (-0.11%)` | :arrow_down: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26298/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=footer). Last update [94c8c94...1843a04](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=h1) Report
> Merging [#26298](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=desc) into [master](https://codecov.io/gh/pandas-dev/pandas/commit/b99e84fb1d3bfa3506bf067bcdd0628ec7ace40c?src=pr&el=desc) will **decrease** coverage by `<.01%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/pandas-dev/pandas/pull/26298/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           master   #26298      +/-   ##
==========================================
- Coverage   91.74%   91.74%   -0.01%     
==========================================
  Files         174      174              
  Lines       50748    50755       +7     
==========================================
+ Hits        46560    46563       +3     
- Misses       4188     4192       +4
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.25% <100%> (ø)` | :arrow_up: |
| #single | `41.69% <38.46%> (-0.09%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/indexes/category.py](https://codecov.io/gh/pandas-dev/pandas/pull/26298/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvaW5kZXhlcy9jYXRlZ29yeS5weQ==) | `98.62% <100%> (ø)` | :arrow_up: |
| [pandas/core/frame.py](https://codecov.io/gh/pandas-dev/pandas/pull/26298/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvZnJhbWUucHk=) | `97.02% <100%> (-0.11%)` | :arrow_down: |
| [pandas/\_typing.py](https://codecov.io/gh/pandas-dev/pandas/pull/26298/diff?src=pr&el=tree#diff-cGFuZGFzL190eXBpbmcucHk=) | `100% <100%> (ø)` | :arrow_up: |
| [pandas/io/gbq.py](https://codecov.io/gh/pandas-dev/pandas/pull/26298/diff?src=pr&el=tree#diff-cGFuZGFzL2lvL2dicS5weQ==) | `78.94% <0%> (-10.53%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=footer). Last update [b99e84f...7b598c6](https://codecov.io/gh/pandas-dev/pandas/pull/26298?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

this might be solved as well: https://github.com/pandas-dev/pandas/issues/14865
This PR does not solve #14865 (although I'd be happy to look into it). There is still an issue with `Series.get` where if the key is not found in the index but can be interpreted to be a positional indexer, then it will be (for example, `s.get(0)` returns the first element when `s` has a `CategoricalIndex` that does not contain a 0) which is inconsistent which regular indexes.
@jreback I have made the requested changes
@jreback green
lgtm. can you merge master and ping on green.
thanks @JustinZhengBC keep em coming!