Skip to content

Commit f7fb76e

Browse files
committed
fix doc strings
1 parent 6a368a7 commit f7fb76e

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

doc/source/whatsnew/v1.2.0.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ Categorical
523523
- :meth:`Categorical.fillna` will always return a copy, validate a passed fill value regardless of whether there are any NAs to fill, and disallow an ``NaT`` as a fill value for numeric categories (:issue:`36530`)
524524
- Bug in :meth:`Categorical.__setitem__` that incorrectly raised when trying to set a tuple value (:issue:`20439`)
525525
- Bug in :meth:`CategoricalIndex.equals` incorrectly casting non-category entries to ``np.nan`` (:issue:`37667`)
526-
- Bug in :meth:`Categorical.unique` where the dtype changes in the unique array if there are unused categories in the original array (:issue:`38140`).
526+
- Bug in :meth:`Categorical.unique`, where the dtype changed in the unique array if there were unused categories in the original array (:issue:`38140`).
527527
- Bug in :meth:`CategoricalIndex.where` incorrectly setting non-category entries to ``np.nan`` instead of raising ``TypeError`` (:issue:`37977`)
528528
-
529529

pandas/core/arrays/categorical.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2042,7 +2042,7 @@ def unique(self):
20422042
20432043
.. versionchanged:: 1.2.0
20442044
2045-
Previously unused categories were dropped.
2045+
Previously, unused categories were dropped from the new categories.
20462046
20472047
Returns
20482048
-------

pandas/core/groupby/categorical.py

+2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ def recode_for_groupby(
7272

7373
# sort=False should order groups in as-encountered order (GH-8868)
7474
cat = c.unique()
75+
76+
# See GH-38140 for block below
7577
# exclude nan from indexer for categories
7678
take_codes = cat.codes[cat.codes != -1]
7779
if cat.ordered:

pandas/core/series.py

+3-6
Original file line numberDiff line numberDiff line change
@@ -1820,15 +1820,12 @@ def unique(self):
18201820
['2016-01-01 00:00:00-05:00']
18211821
Length: 1, dtype: datetime64[ns, US/Eastern]
18221822
1823-
An unordered Categorical will return categories in the order of
1824-
appearance.
1823+
An Categorical will return categories in the order of
1824+
appearance and with the same dtype.
18251825
18261826
>>> pd.Series(pd.Categorical(list('baabc'))).unique()
18271827
['b', 'a', 'c']
1828-
Categories (3, object): ['b', 'a', 'c']
1829-
1830-
An ordered Categorical preserves the category ordering.
1831-
1828+
Categories (3, object): ['a', 'b', 'c']
18321829
>>> pd.Series(pd.Categorical(list('baabc'), categories=list('abc'),
18331830
... ordered=True)).unique()
18341831
['b', 'a', 'c']

0 commit comments

Comments
 (0)