We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent f68a38b commit a5e5096Copy full SHA for a5e5096
pandas/core/arrays/categorical.py
@@ -2152,18 +2152,8 @@ def unique(self):
2152
['b', 'a']
2153
Categories (3, object): ['a' < 'b' < 'c']
2154
"""
2155
- # unlike np.unique, unique1d does not sort
2156
unique_codes = unique1d(self.codes)
2157
- cat = self.copy()
2158
-
2159
- # keep nan in codes
2160
- cat._ndarray = unique_codes
2161
2162
- # exclude nan from indexer for categories
2163
- take_codes = unique_codes[unique_codes != -1]
2164
- if self.ordered:
2165
- take_codes = np.sort(take_codes)
2166
- return cat.set_categories(cat.categories.take(take_codes))
+ return self._from_backing_data(unique_codes)
2167
2168
def _values_for_factorize(self):
2169
return self._ndarray, -1
0 commit comments