Backport PR #25368 on branch 0.24.x (BUG: Fix potential segfault after pd.Categorical(pd.Series(...), categories=...))
State: closed

Backport PR #25368: BUG: Fix potential segfault after pd.Categorical(pd.Series(...), categories=...)

Labels:
name: Bug
name: Categorical
description: Categorical Data Type

Comments:
# [Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25520?src=pr&el=h1) Report
> Merging [#25520](https://codecov.io/gh/pandas-dev/pandas/pull/25520?src=pr&el=desc) into [0.24.x](https://codecov.io/gh/pandas-dev/pandas/commit/03fe61d0a60f06ce5cf4cf65fd5aa20aa52c046f?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/25520/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25520?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           0.24.x   #25520      +/-   ##
==========================================
- Coverage   92.39%   92.39%   -0.01%     
==========================================
  Files         166      166              
  Lines       52421    52419       -2     
==========================================
- Hits        48434    48432       -2     
  Misses       3987     3987
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.83% <100%> (-0.01%)` | :arrow_down: |
| #single | `42.91% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25520?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/25520/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.96% <100%> (-0.02%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25520?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/25520?src=pr&el=footer). Last update [03fe61d...e6fee8e](https://codecov.io/gh/pandas-dev/pandas/pull/25520?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/25520?src=pr&el=h1) Report
> Merging [#25520](https://codecov.io/gh/pandas-dev/pandas/pull/25520?src=pr&el=desc) into [0.24.x](https://codecov.io/gh/pandas-dev/pandas/commit/03fe61d0a60f06ce5cf4cf65fd5aa20aa52c046f?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/25520/graphs/tree.svg?width=650&token=eZ4WkYLtcO&height=150&src=pr)](https://codecov.io/gh/pandas-dev/pandas/pull/25520?src=pr&el=tree)

```diff
@@            Coverage Diff             @@
##           0.24.x   #25520      +/-   ##
==========================================
- Coverage   92.39%   92.39%   -0.01%     
==========================================
  Files         166      166              
  Lines       52421    52419       -2     
==========================================
- Hits        48434    48432       -2     
  Misses       3987     3987
```

| Flag | Coverage Δ | |
|---|---|---|
| #multiple | `90.83% <100%> (-0.01%)` | :arrow_down: |
| #single | `42.91% <0%> (-0.01%)` | :arrow_down: |

| [Impacted Files](https://codecov.io/gh/pandas-dev/pandas/pull/25520?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pandas/core/arrays/categorical.py](https://codecov.io/gh/pandas-dev/pandas/pull/25520/diff?src=pr&el=tree#diff-cGFuZGFzL2NvcmUvYXJyYXlzL2NhdGVnb3JpY2FsLnB5) | `95.96% <100%> (-0.02%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/pandas-dev/pandas/pull/25520?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/25520?src=pr&el=footer). Last update [03fe61d...e6fee8e](https://codecov.io/gh/pandas-dev/pandas/pull/25520?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).