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
@@ -10,6 +10,8 @@ users upgrade to this version.
10
10
Highlights include:
11
11
12
12
- Integration with `Apache Parquet <https://parquet.apache.org/>`__, including a new top-level :func:`read_parquet` and :func:`DataFrame.to_parquet` method, see :ref:`here <io.parquet>`.
13
+
- New user-facing :class:`pandas.api.types.CategoricalDtype` for specifying
14
+
categoricals independent of the data, see :ref:`here <whatsnew_0210.enhancements.categorical_dtype>`.
13
15
14
16
Check the :ref:`API Changes <whatsnew_0210.api_breaking>` and :ref:`deprecations <whatsnew_0210.deprecations>` before updating.
15
17
@@ -89,6 +91,30 @@ This does not raise any obvious exceptions, but also does not create a new colum
89
91
90
92
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>`.
91
93
94
+
.. _whatsnew_0210.enhancements.categorical_dtype:
95
+
96
+
``CategoricalDtype`` for specifying categoricals
97
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
98
+
99
+
:class:`pandas.api.types.CategoricalDtype` has been added to the public API and
100
+
expanded to include the ``categories`` and ``ordered`` attributes. A
101
+
``CategoricalDtype`` can be used to specify the set of categories and
102
+
orderedness of an array, independent of the data themselves. This can be useful,
103
+
e.g., when converting string data to a ``Categorical`` (:issue:`14711`, :issue:`15078`):
0 commit comments