Skip to content

Commit e8048cd

Browse files
authored
DEPR: Categorical fastpath (#58157)
1 parent 3ac6eb9 commit e8048cd

File tree

3 files changed

+1
-28
lines changed

3 files changed

+1
-28
lines changed

doc/source/whatsnew/v3.0.0.rst

+1
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ Removal of prior version deprecations/changes
212212
- Disallow passing a pandas type to :meth:`Index.view` (:issue:`55709`)
213213
- Disallow units other than "s", "ms", "us", "ns" for datetime64 and timedelta64 dtypes in :func:`array` (:issue:`53817`)
214214
- Removed "freq" keyword from :class:`PeriodArray` constructor, use "dtype" instead (:issue:`52462`)
215+
- Removed 'fastpath' keyword in :class:`Categorical` constructor (:issue:`20110`)
215216
- Removed alias :class:`arrays.PandasArray` for :class:`arrays.NumpyExtensionArray` (:issue:`53694`)
216217
- Removed deprecated "method" and "limit" keywords from :meth:`Series.replace` and :meth:`DataFrame.replace` (:issue:`53492`)
217218
- Removed extension test classes ``BaseNoReduceTests``, ``BaseNumericReduceTests``, ``BaseBooleanReduceTests`` (:issue:`54663`)

pandas/core/arrays/categorical.py

-21
Original file line numberDiff line numberDiff line change
@@ -276,9 +276,6 @@ class Categorical(NDArrayBackedExtensionArray, PandasObject, ObjectStringArrayMi
276276
provided).
277277
dtype : CategoricalDtype
278278
An instance of ``CategoricalDtype`` to use for this categorical.
279-
fastpath : bool
280-
The 'fastpath' keyword in Categorical is deprecated and will be
281-
removed in a future version. Use Categorical.from_codes instead.
282279
copy : bool, default True
283280
Whether to copy if the codes are unchanged.
284281
@@ -391,33 +388,15 @@ def __init__(
391388
categories=None,
392389
ordered=None,
393390
dtype: Dtype | None = None,
394-
fastpath: bool | lib.NoDefault = lib.no_default,
395391
copy: bool = True,
396392
) -> None:
397-
if fastpath is not lib.no_default:
398-
# GH#20110
399-
warnings.warn(
400-
"The 'fastpath' keyword in Categorical is deprecated and will "
401-
"be removed in a future version. Use Categorical.from_codes instead",
402-
DeprecationWarning,
403-
stacklevel=find_stack_level(),
404-
)
405-
else:
406-
fastpath = False
407-
408393
dtype = CategoricalDtype._from_values_or_dtype(
409394
values, categories, ordered, dtype
410395
)
411396
# At this point, dtype is always a CategoricalDtype, but
412397
# we may have dtype.categories be None, and we need to
413398
# infer categories in a factorization step further below
414399

415-
if fastpath:
416-
codes = coerce_indexer_dtype(values, dtype.categories)
417-
dtype = CategoricalDtype(ordered=False).update_dtype(dtype)
418-
super().__init__(codes, dtype)
419-
return
420-
421400
if not is_list_like(values):
422401
# GH#38433
423402
raise TypeError("Categorical input must be list-like")

pandas/tests/arrays/categorical/test_constructors.py

-7
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,6 @@
3535

3636

3737
class TestCategoricalConstructors:
38-
def test_fastpath_deprecated(self):
39-
codes = np.array([1, 2, 3])
40-
dtype = CategoricalDtype(categories=["a", "b", "c", "d"], ordered=False)
41-
msg = "The 'fastpath' keyword in Categorical is deprecated"
42-
with tm.assert_produces_warning(DeprecationWarning, match=msg):
43-
Categorical(codes, dtype=dtype, fastpath=True)
44-
4538
def test_categorical_from_cat_and_dtype_str_preserve_ordered(self):
4639
# GH#49309 we should preserve orderedness in `res`
4740
cat = Categorical([3, 1], categories=[3, 2, 1], ordered=True)

0 commit comments

Comments
 (0)