Skip to content

DEPR: Categorical fastpath #58157

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 5, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/source/whatsnew/v3.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 deprecated "method" and "limit" keywords from :meth:`Series.replace` and :meth:`DataFrame.replace` (:issue:`53492`)
- Removed extension test classes ``BaseNoReduceTests``, ``BaseNumericReduceTests``, ``BaseBooleanReduceTests`` (:issue:`54663`)
- Removed the "closed" and "normalize" keywords in :meth:`DatetimeIndex.__new__` (:issue:`52628`)
Expand Down
21 changes: 0 additions & 21 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -391,33 +388,15 @@ 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
)
# At this point, dtype is always a CategoricalDtype, but
# 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")
Expand Down
7 changes: 0 additions & 7 deletions pandas/tests/arrays/categorical/test_constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading