Skip to content
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

Deprecate inplace in Categorical.remove_categories #37981

Merged
merged 11 commits into from
Apr 21, 2021

Conversation

OlehKSS
Copy link
Contributor

@OlehKSS OlehKSS commented Nov 20, 2020

@OlehKSS OlehKSS changed the title Deprecate inplace in Categorica.remove_categories Deprecate inplace in Categorical.remove_categories Nov 20, 2020
@@ -352,7 +352,9 @@ def test_validate_inplace_raises(self, value):
cat.add_categories(new_categories=["D", "E", "F"], inplace=value)

with pytest.raises(ValueError, match=msg):
cat.remove_categories(removals=["D", "E", "F"], inplace=value)
with tm.assert_produces_warning(FutureWarning):
# issue #37643 inplace kwarg deprecated
Copy link
Member

Choose a reason for hiding this comment

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

nit: I'd drop this comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was asked to add this comment in my previous pull request #37918, which is related to #37643, so I did the same here

Copy link
Member

Choose a reason for hiding this comment

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

yah i find these helpful

@@ -478,6 +478,7 @@ Deprecations
- Partial slicing on unordered :class:`DatetimeIndex` with keys, which are not in Index is deprecated and will be removed in a future version (:issue:`18531`)
- Deprecated :meth:`Index.asi8` for :class:`Index` subclasses other than :class:`DatetimeIndex`, :class:`TimedeltaIndex`, and :class:`PeriodIndex` (:issue:`37877`)
- The ``inplace`` parameter of :meth:`Categorical.remove_unused_categories` is deprecated and will be removed in a future version (:issue:`37643`)
- The ``inplace`` parameter of :meth:`Categorical.remove_categories` is deprecated and will be removed in a future version (:issue:`37643`)
Copy link
Member

Choose a reason for hiding this comment

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

could merge with the entry for Categorical.remove_unused_categories?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok

@@ -348,7 +348,10 @@ def test_remove_categories(self):
tm.assert_categorical_equal(res, new)

# inplace == True
res = cat.remove_categories("c", inplace=True)
with tm.assert_produces_warning(FutureWarning):
# issue #37643 inplace kwarg deprecated
Copy link
Member

Choose a reason for hiding this comment

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

and this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

same here

@jreback
Copy link
Contributor

jreback commented Nov 26, 2020

ok let's resolve the discussion on the issue first here.

@jreback jreback added API - Consistency Internal Consistency of API/Behavior Categorical Categorical Data Type Deprecate Functionality to remove in pandas labels Nov 26, 2020
@OlehKSS
Copy link
Contributor Author

OlehKSS commented Nov 30, 2020

@arw2019 I fixed the 'whatsnew' entry as you asked.

Updated to the latest master and resolved, hopefully all, unit test problems.

@github-actions
Copy link
Contributor

This pull request is stale because it has been open for thirty days with no activity. Please update or respond to this comment if you're still interested in working on this.

@github-actions github-actions bot added the Stale label Dec 31, 2020
cat.remove_categories(replace_value, inplace=True)
with catch_warnings():
simplefilter("ignore")
cat.remove_categories(replace_value, inplace=True)
Copy link
Member

Choose a reason for hiding this comment

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

i think eventually we'll need to push this up and deprecate inplace here in Categorical.replace, but that can be done in a separate step

@jbrockmendel
Copy link
Member

needs rebase, otherwise LGTM

@OlehKSS
Copy link
Contributor Author

OlehKSS commented Apr 5, 2021

@jbrockmendel
I have updated this pull request to the up-to-date main branch

warn(
"The `inplace` parameter in pandas.Categorical."
"remove_categories is deprecated and "
"will be removed in a future version.",
Copy link
Member

Choose a reason for hiding this comment

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

usually we would say "do X instead", but since the idea is to never change the dtype inplace, might be worth adding a short sentence like "Removing unused categories will always return a new Categorical object"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I updated the warning message.

@lithomas1 lithomas1 removed the Stale label Apr 6, 2021
@@ -1140,6 +1144,8 @@ def remove_categories(self, removals, inplace=False):
Whether or not to remove the categories inplace or return a copy of
this categorical with removed categories.

.. deprecated:: 1.2.0
Copy link
Member

Choose a reason for hiding this comment

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

1.3.0 now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch, thanks. I updated the version here and fixed conflicts with the master

@jbrockmendel
Copy link
Member

one comment, otherwise looks ready

@jreback jreback added this to the 1.3 milestone Apr 20, 2021
@jreback
Copy link
Contributor

jreback commented Apr 20, 2021

thanks @OlehKSS let's merge on green.

@jreback jreback merged commit 9be0b82 into pandas-dev:master Apr 21, 2021
@jreback
Copy link
Contributor

jreback commented Apr 21, 2021

thanks @OlehKSS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API - Consistency Internal Consistency of API/Behavior Categorical Categorical Data Type Deprecate Functionality to remove in pandas
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants