Skip to content

Commit 1bf3728

Browse files
committed
update
1 parent 6055211 commit 1bf3728

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
@@ -205,6 +205,37 @@ Notable bug fixes
205205

206206
These are bug fixes that might have notable behavior changes.
207207

208+
``Categorical.unique`` now always maintains same dtype as original
209+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
210+
211+
Previously, when calling :meth:`Categorical.unique`, unused categories in the new array
212+
would be removed, meaning that the dtype of the new array would be different than the
213+
original, if some categories are not present in the unique array:
214+
215+
As an example of this, given:
216+
217+
.. ipython:: python
218+
219+
dtype = pd.CategoricalDtype(['bad', 'neutral', 'good'], ordered=True)
220+
original = pd.Categorical(['good','good', 'bad', 'bad'], dtype=dtype)
221+
unique = original.unique()
222+
223+
*pandas < 1.2.0*:
224+
225+
.. code-block:: ipython
226+
227+
In [1]: unique
228+
['good', 'bad']
229+
Categories (2, object): ['bad' < 'good']
230+
In [2]: original.dtype == unique.dtype
231+
False
232+
233+
*pandas >= 1.2.0*
234+
235+
.. ipython:: python
236+
237+
unique
238+
original.dtype == unique.dtype
208239
209240
Preserve dtypes in :meth:`~pandas.DataFrame.combine_first`
210241
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)