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