Skip to content

Commit 8049354

Browse files
committed
whatsnew doc updates for categorical api changes
1 parent 39e17f2 commit 8049354

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

doc/source/whatsnew/v0.16.0.txt

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,54 @@ Backwards incompatible API changes
307307
- ``Series.describe`` for categorical data will now give counts and frequencies of 0, not ``NaN``, for unused categories (:issue:`9443`)
308308

309309

310+
Categorical Changes
311+
~~~~~~~~~~~~~~~~~~~
312+
313+
.. _whatsnew_0160.api_breaking.categorical:
314+
315+
In prior versions, Categoricals that with had an unspecified ordering (meaning no ``ordered`` keyword was passed) were defaulted to have a lexographic ordering of the values and designated as ``ordered`` Categoricals. Going forward, the ``ordered`` keyword in the ``Categorical`` constructor will default to ``False``, so ordering must now be explicit.
316+
317+
Furthermore, previously you *could* change the ``ordered`` attribute of a Categorical by just setting the attribute, e.g. ``cat.ordered=True``; This is now deprecated and you should use ``cat.set_ordered(True)``. This will by default return a **new** object and not modify the existing object.
318+
319+
Previous Behavior
320+
321+
.. code-block:: python
322+
323+
In [1]: cat = pd.Categorical([0,1,2])
324+
325+
In [2]: cat
326+
Out[2]:
327+
[0, 1, 2]
328+
Categories (3, int64): [0 < 1 < 2]
329+
330+
In [3]: cat.ordered
331+
Out[3]: True
332+
333+
In [4]: cat.ordered=False
334+
335+
In [5]: cat
336+
Out[5]:
337+
[0, 1, 2]
338+
Categories (3, int64): [0, 1, 2]
339+
340+
341+
New Behavior
342+
343+
.. ipython:: python
344+
345+
cat = pd.Categorical([0,1,2])
346+
cat
347+
cat.ordered
348+
cat.ordered=True
349+
cat = cat.set_ordered(True)
350+
cat
351+
cat.ordered
352+
353+
# you can set in the construtor
354+
cat = pd.Categorical([0,1,2],ordered=True)
355+
cat
356+
cat.ordered
357+
310358
Indexing Changes
311359
~~~~~~~~~~~~~~~~
312360

0 commit comments

Comments
 (0)