Skip to content

Commit df3224f

Browse files
committed
FIX: categorical fixups
1 parent 6cf0a4e commit df3224f

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

doc/source/categorical.rst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ operations (additions, divisions, ...) are not possible.
4141

4242
All values of categorical data are either in `categories` or `np.nan`. Order is defined by
4343
the order of `categories`, not lexical order of the values. Internally, the data structure
44-
consists of a `categories` array and an integer array of `codes` which point to the real value in
44+
consists of a `categories` array and an integer array of `codes` which point to the real value in
4545
the `categories` array.
4646

4747
The categorical data type is useful in the following cases:
@@ -769,9 +769,3 @@ Use ``copy=True`` to prevent such a behaviour or simply don't reuse `Categorical
769769
using an int array (e.g. ``np.array([1,2,3,4])``) will exhibit the same behaviour, while using
770770
a string array (e.g. ``np.array(["a","b","c","a"])``) will not.
771771

772-
773-
Future compatibility
774-
~~~~~~~~~~~~~~~~~~~~
775-
776-
As `Categorical` is not a native `numpy` dtype, the implementation details of
777-
`Series.cat` can change if such a `numpy` dtype is implemented.

pandas/core/categorical.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -643,10 +643,11 @@ def remove_categories(self, removals, inplace=False):
643643
"""
644644
if not com.is_list_like(removals):
645645
removals = [removals]
646-
not_included = set(removals) - set(self._categories)
646+
removals = set(list(removals))
647+
not_included = removals - set(self._categories)
647648
if len(not_included) != 0:
648649
raise ValueError("removals must all be in old categories: %s" % str(not_included))
649-
new_categories = set(self._categories) - set(removals)
650+
new_categories = [ c for c in self._categories if c not in removals ]
650651
return self.set_categories(new_categories, ordered=self.ordered, rename=False,
651652
inplace=inplace)
652653

0 commit comments

Comments
 (0)