We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ab97abe commit 16c13efCopy full SHA for 16c13ef
pandas/core/arrays/categorical.py
@@ -2130,18 +2130,8 @@ def unique(self):
2130
['b', 'a']
2131
Categories (3, object): ['a' < 'b' < 'c']
2132
"""
2133
- # unlike np.unique, unique1d does not sort
2134
unique_codes = unique1d(self.codes)
2135
- cat = self.copy()
2136
-
2137
- # keep nan in codes
2138
- cat._ndarray = unique_codes
2139
2140
- # exclude nan from indexer for categories
2141
- take_codes = unique_codes[unique_codes != -1]
2142
- if self.ordered:
2143
- take_codes = np.sort(take_codes)
2144
- return cat.set_categories(cat.categories.take(take_codes))
+ return self._from_backing_data(unique_codes)
2145
2146
def _values_for_factorize(self):
2147
return self._ndarray, -1
0 commit comments