You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We extended the CategoricalDtype to accept optional categories and ordered
argument.
```python
pd.CategoricalDtype(categories=['a', 'b'], ordered=True
```
CategoricalDtype is now part of the public API. This allows users to
specify the desired categories and orderedness of an operation ahead of time.
The current behavior, which is still possible with categories=None, the
default, is to infer the categories from whatever is present.
This change will make it easy to implement support for specifying categories
that are know ahead of time in other places e.g. .astype, .read_csv, and the
Series constructor.
Closespandas-dev#14711Closespandas-dev#15078Closespandas-dev#14676
Copy file name to clipboardExpand all lines: doc/source/whatsnew/v0.21.0.txt
+26
Original file line number
Diff line number
Diff line change
@@ -22,6 +22,8 @@ Check the :ref:`API Changes <whatsnew_0210.api_breaking>` and :ref:`deprecations
22
22
New features
23
23
~~~~~~~~~~~~
24
24
25
+
- New user-facing :class:`pandas.api.types.CategoricalDtype` for specifying
26
+
categoricals independent of the data (:issue:`14711`, :issue:`15078`)
25
27
- Support for `PEP 519 -- Adding a file system path protocol
26
28
<https://www.python.org/dev/peps/pep-0519/>`_ on most readers and writers (:issue:`13823`)
27
29
- Added ``__fspath__`` method to :class:`~pandas.HDFStore`, :class:`~pandas.ExcelFile`,
@@ -88,6 +90,30 @@ This does not raise any obvious exceptions, but also does not create a new colum
88
90
89
91
Setting a list-like data structure into a new attribute now raise a ``UserWarning`` about the potential for unexpected behavior. See :ref:`Attribute Access <indexing.attribute_access>`.
90
92
93
+
.. _whatsnew_0210.enhancements.categorical_dtype:
94
+
95
+
``CategoricalDtype`` for specifying categoricals
96
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97
+
98
+
:class:`pandas.api.types.CategoricalDtype` has been added to the public API and
99
+
expanded to include the ``categories`` and ``ordered`` attributes. A
100
+
``CategoricalDtype`` can be used to specify the set of categories and
101
+
orderedness of an array, independent of the data themselves. This can be useful,
102
+
e.g., when converting string data to a ``Categorical``:
0 commit comments