Skip to content

minor inconsistency in Categorical.remove_categories error message #28677

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 38 commits into from
Oct 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
b892c68
Fix #28669
punndcoder28 Sep 29, 2019
9236f99
Fix issue #28669
punndcoder28 Sep 30, 2019
e6d3d49
Fix
punndcoder28 Sep 30, 2019
d18d602
Fix issue #28669
punndcoder28 Sep 30, 2019
2f5347c
Fix issue #28669
punndcoder28 Sep 30, 2019
9e2a59b
Fix issue #28669
punndcoder28 Sep 30, 2019
41ee2be
Removed test for null
punndcoder28 Sep 30, 2019
894f60d
Removed test for null
punndcoder28 Sep 30, 2019
bc204d5
Removed test for null
punndcoder28 Sep 30, 2019
bb08e10
Removed test for null
punndcoder28 Sep 30, 2019
9c070b6
Removed test for null
punndcoder28 Sep 30, 2019
6d2cbbe
Fix issue #28669
punndcoder28 Oct 1, 2019
a2ea7a5
Added tests for removing null and duplicates
punndcoder28 Oct 5, 2019
f3a26d2
Removed assert statement
punndcoder28 Oct 5, 2019
12b8f1a
Parameterized pytest.raises
punndcoder28 Oct 5, 2019
d283f72
Parameterized pytest.raises
punndcoder28 Oct 5, 2019
6ab85bd
Parameterized pytest
punndcoder28 Oct 5, 2019
4e520b6
Parameterized pytest
punndcoder28 Oct 5, 2019
ca84a86
Parameterized pytest
punndcoder28 Oct 5, 2019
67e035e
Fix
punndcoder28 Oct 5, 2019
95f90da
Parameterized pytest
punndcoder28 Oct 6, 2019
68b0dd2
Parameterized pytest
punndcoder28 Oct 6, 2019
403be03
Parameterized pytest
punndcoder28 Oct 6, 2019
1877d6b
Parameterized pytest.raises
punndcoder28 Oct 6, 2019
e91806b
Parameterized pytest.raises
punndcoder28 Oct 6, 2019
870c2c3
Parameterized pytest.raises
punndcoder28 Oct 6, 2019
1201773
Added whatsnew entry
punndcoder28 Oct 7, 2019
2979c77
Update doc/source/whatsnew/v1.0.0.rst
punndcoder28 Oct 7, 2019
64b6d5e
Parameterized pytest.raises
punndcoder28 Oct 8, 2019
1fab641
Update doc/source/whatsnew/v1.0.0.rst
punndcoder28 Oct 8, 2019
6e0307e
Updated whatsnew
punndcoder28 Oct 8, 2019
110ae15
Updated whatsnew
punndcoder28 Oct 8, 2019
8cfa15f
Updated whatsnew
punndcoder28 Oct 8, 2019
1c0e9ea
Updated whatsnew
punndcoder28 Oct 8, 2019
475524f
Updated whatsnew
punndcoder28 Oct 8, 2019
3e62466
Added whatsnew entry
punndcoder28 Oct 8, 2019
b458d1b
Updated whatsnew
punndcoder28 Oct 8, 2019
0c02d52
Updated whatsnew
punndcoder28 Oct 9, 2019
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
2 changes: 1 addition & 1 deletion doc/source/whatsnew/v1.0.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ Categorical
- Bug where :func:`merge` was unable to join on categorical and extension dtype columns (:issue:`28668`)
- :meth:`Categorical.searchsorted` and :meth:`CategoricalIndex.searchsorted` now work on unordered categoricals also (:issue:`21667`)
- Added test to assert roundtripping to parquet with :func:`DataFrame.to_parquet` or :func:`read_parquet` will preserve Categorical dtypes for string types (:issue:`27955`)
-
- Changed the error message in :meth:`Categorical.remove_categories` to always show the invalid removals as a set (:issue:`28669`)


Datetimelike
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,7 +1120,7 @@ def remove_categories(self, removals, inplace=False):

# GH 10156
if any(isna(removals)):
not_included = [x for x in not_included if notna(x)]
not_included = {x for x in not_included if notna(x)}
new_categories = [x for x in new_categories if notna(x)]

if len(not_included) != 0:
Expand Down
12 changes: 9 additions & 3 deletions pandas/tests/arrays/categorical/test_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import re

import numpy as np
import pytest

Expand Down Expand Up @@ -339,9 +341,13 @@ def test_remove_categories(self):
tm.assert_categorical_equal(cat, new)
assert res is None

# removal is not in categories
with pytest.raises(ValueError):
cat.remove_categories(["c"])
@pytest.mark.parametrize("removals", [["c"], ["c", np.nan], "c", ["c", "c"]])
def test_remove_categories_raises(self, removals):
cat = Categorical(["a", "b", "a"])
message = re.escape("removals must all be in old categories: {'c'}")

with pytest.raises(ValueError, match=message):
cat.remove_categories(removals)

def test_remove_unused_categories(self):
c = Categorical(["a", "b", "c", "d", "a"], categories=["a", "b", "c", "d", "e"])
Expand Down