diff --git a/doc/source/whatsnew/v3.0.0.rst b/doc/source/whatsnew/v3.0.0.rst index 983768e0f67da..bb1e0b33c2ab8 100644 --- a/doc/source/whatsnew/v3.0.0.rst +++ b/doc/source/whatsnew/v3.0.0.rst @@ -212,6 +212,7 @@ Removal of prior version deprecations/changes - Disallow passing a pandas type to :meth:`Index.view` (:issue:`55709`) - Disallow units other than "s", "ms", "us", "ns" for datetime64 and timedelta64 dtypes in :func:`array` (:issue:`53817`) - Removed "freq" keyword from :class:`PeriodArray` constructor, use "dtype" instead (:issue:`52462`) +- Removed 'fastpath' keyword in :class:`Categorical` constructor (:issue:`20110`) - Removed alias :class:`arrays.PandasArray` for :class:`arrays.NumpyExtensionArray` (:issue:`53694`) - Removed deprecated "method" and "limit" keywords from :meth:`Series.replace` and :meth:`DataFrame.replace` (:issue:`53492`) - Removed extension test classes ``BaseNoReduceTests``, ``BaseNumericReduceTests``, ``BaseBooleanReduceTests`` (:issue:`54663`) diff --git a/pandas/core/arrays/categorical.py b/pandas/core/arrays/categorical.py index 416331a260e9f..3af4c528ceae8 100644 --- a/pandas/core/arrays/categorical.py +++ b/pandas/core/arrays/categorical.py @@ -276,9 +276,6 @@ class Categorical(NDArrayBackedExtensionArray, PandasObject, ObjectStringArrayMi provided). dtype : CategoricalDtype An instance of ``CategoricalDtype`` to use for this categorical. - fastpath : bool - The 'fastpath' keyword in Categorical is deprecated and will be - removed in a future version. Use Categorical.from_codes instead. copy : bool, default True Whether to copy if the codes are unchanged. @@ -391,20 +388,8 @@ def __init__( categories=None, ordered=None, dtype: Dtype | None = None, - fastpath: bool | lib.NoDefault = lib.no_default, copy: bool = True, ) -> None: - if fastpath is not lib.no_default: - # GH#20110 - warnings.warn( - "The 'fastpath' keyword in Categorical is deprecated and will " - "be removed in a future version. Use Categorical.from_codes instead", - DeprecationWarning, - stacklevel=find_stack_level(), - ) - else: - fastpath = False - dtype = CategoricalDtype._from_values_or_dtype( values, categories, ordered, dtype ) @@ -412,12 +397,6 @@ def __init__( # we may have dtype.categories be None, and we need to # infer categories in a factorization step further below - if fastpath: - codes = coerce_indexer_dtype(values, dtype.categories) - dtype = CategoricalDtype(ordered=False).update_dtype(dtype) - super().__init__(codes, dtype) - return - if not is_list_like(values): # GH#38433 raise TypeError("Categorical input must be list-like") diff --git a/pandas/tests/arrays/categorical/test_constructors.py b/pandas/tests/arrays/categorical/test_constructors.py index 857b14e2a2558..1069a9e5aaa90 100644 --- a/pandas/tests/arrays/categorical/test_constructors.py +++ b/pandas/tests/arrays/categorical/test_constructors.py @@ -35,13 +35,6 @@ class TestCategoricalConstructors: - def test_fastpath_deprecated(self): - codes = np.array([1, 2, 3]) - dtype = CategoricalDtype(categories=["a", "b", "c", "d"], ordered=False) - msg = "The 'fastpath' keyword in Categorical is deprecated" - with tm.assert_produces_warning(DeprecationWarning, match=msg): - Categorical(codes, dtype=dtype, fastpath=True) - def test_categorical_from_cat_and_dtype_str_preserve_ordered(self): # GH#49309 we should preserve orderedness in `res` cat = Categorical([3, 1], categories=[3, 2, 1], ordered=True)