Skip to content
New issue

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

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

Already on GitHub? # to your account

DEPR: Series[categorical].replace special-casing #56385

Merged
merged 1 commit into from
Dec 9, 2023

Conversation

jbrockmendel
Copy link
Member

@@ -473,6 +473,7 @@ Other Deprecations
- Deprecated the ``kind`` keyword in :meth:`Series.resample` and :meth:`DataFrame.resample`, explicitly cast the object's ``index`` instead (:issue:`55895`)
- Deprecated the ``ordinal`` keyword in :class:`PeriodIndex`, use :meth:`PeriodIndex.from_ordinals` instead (:issue:`55960`)
- Deprecated the ``unit`` keyword in :class:`TimedeltaIndex` construction, use :func:`to_timedelta` instead (:issue:`55499`)
- Deprecated the behavior of :meth:`DataFrame.replace` and :meth:`Series.replace` with :class:`CategoricalDtype`; in a future version replace will change the values while preserving the categories. To change the categories, use ``ser.cat.rename_categories`` instead (:issue:`55147`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious. If one does Categorical[int].replace(1, 1.2) in the future will that case raise?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It will behave like ser[ser == 1] = 1.2, which raises TypeError: Cannot setitem on a Categorical with a new category (1.2), set the categories first

@mroeschke mroeschke added Categorical Categorical Data Type Deprecate Functionality to remove in pandas replace replace method labels Dec 9, 2023
@mroeschke mroeschke added this to the 2.2 milestone Dec 9, 2023
@mroeschke mroeschke merged commit 536ce30 into pandas-dev:main Dec 9, 2023
@mroeschke
Copy link
Member

Thanks @jbrockmendel

@phofl
Copy link
Member

phofl commented Jan 30, 2024

Is there any use case for categorical replace now? I guess not? Except if you try to replace non-existing values?

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Categorical Categorical Data Type Deprecate Functionality to remove in pandas replace replace method
Projects
None yet
Development

Successfully merging this pull request may close these issues.

DEPR/API: Series[categorical].replace behavior
3 participants