Skip to content

Commit a82183c

Browse files
committed
update
1 parent 2f5c963 commit a82183c

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

doc/source/whatsnew/v1.2.0.rst

-1
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ Categorical
585585
- :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`)
586586
- Bug in :meth:`Categorical.__setitem__` that incorrectly raised when trying to set a tuple value (:issue:`20439`)
587587
- Bug in :meth:`CategoricalIndex.equals` incorrectly casting non-category entries to ``np.nan`` (:issue:`37667`)
588-
- Bug in :meth:`Categorical.unique`, where the dtype changed in the unique array if there were unused categories in the original array (:issue:`38140`).
589588
- Bug in :meth:`CategoricalIndex.where` incorrectly setting non-category entries to ``np.nan`` instead of raising ``TypeError`` (:issue:`37977`)
590589
- Bug in :meth:`Categorical.to_numpy` and ``np.array(categorical)`` with tz-aware ``datetime64`` categories incorrectly dropping the time zone information instead of casting to object dtype (:issue:`38136`)
591590

doc/source/whatsnew/v1.3.0.rst

+31
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,37 @@ Notable bug fixes
8080

8181
These are bug fixes that might have notable behavior changes.
8282

83+
``Categorical.unique`` now always maintains same dtype as original
84+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
85+
86+
Previously, when calling :meth:`Categorical.unique`, unused categories in the new array
87+
would be removed, meaning that the dtype of the new array would be different than the
88+
original, if some categories are not present in the unique array:
89+
90+
As an example of this, given:
91+
92+
.. ipython:: python
93+
94+
dtype = pd.CategoricalDtype(['bad', 'neutral', 'good'], ordered=True)
95+
original = pd.Categorical(['good','good', 'bad', 'bad'], dtype=dtype)
96+
unique = original.unique()
97+
98+
*pandas < 1.2.0*:
99+
100+
.. code-block:: ipython
101+
102+
In [1]: unique
103+
['good', 'bad']
104+
Categories (2, object): ['bad' < 'good']
105+
In [2]: original.dtype == unique.dtype
106+
False
107+
108+
*pandas >= 1.2.0*
109+
110+
.. ipython:: python
111+
112+
unique
113+
original.dtype == unique.dtype
83114
84115
Preserve dtypes in :meth:`~pandas.DataFrame.combine_first`
85116
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)