@@ -96,12 +96,17 @@ By passing a :class:`pandas.Categorical` object to a `Series` or assigning it to
96
96
df[" B" ] = raw_cat
97
97
df
98
98
99
- You can also specify differently ordered categories or make the resulting data
100
- ordered by passing a :class: `CategoricalDtype `:
99
+ Anywhere above we passed a keyword ``dtype='category' ``, we used the default behavior of
100
+
101
+ 1. categories are inferred from the data
102
+ 2. categories are unordered.
103
+
104
+ To control those behaviors, instead of passing ``'category' ``, use an instance
105
+ of :class: `CategoricalDtype `.
101
106
102
107
.. ipython :: python
103
108
104
- s = pd.Series([" a" ," b" ," c" ," a" ])
109
+ s = pd.Series([" a" , " b" , " c" , " a" ])
105
110
cat_type = pd.CategoricalDtype(categories = [" b" , " c" , " d" ], ordered = False )
106
111
s_cat = s.astype(cat_type)
107
112
s_cat
@@ -145,7 +150,7 @@ constructor to save the factorize step during normal constructor mode:
145
150
CategoricalDtype
146
151
----------------
147
152
148
- .. versionadded :: 0.21.0
153
+ .. versionchanged :: 0.21.0
149
154
150
155
A categorical's type is fully described by 1.) its categories (an iterable with
151
156
unique values and no missing values), and 2.) its orderedness (a boolean).
@@ -184,12 +189,19 @@ order of the ``categories`` is not considered
184
189
# Unequal, since the second CategoricalDtype is ordered
185
190
c1 == pd.CategoricalDtype([' a' , ' b' , ' c' ], ordered = True )
186
191
187
- Finally, all instances of ``CategoricalDtype `` compare equal to the string ``'category' ``
192
+ All instances of ``CategoricalDtype `` compare equal to the string ``'category' ``
188
193
189
194
.. ipython :: python
190
195
191
196
c1 == ' category'
192
197
198
+
199
+ .. warning ::
200
+
201
+ Since ``dtype='category' `` is essentially ``CategoricalDtype(None, False) ``,
202
+ and since all instances ``CategoricalDtype `` compare equal to ``'`category' ``,
203
+ all instances of ``CategoricalDtype `` compare equal to a ``CategoricalDtype(None) ``
204
+
193
205
Description
194
206
-----------
195
207
0 commit comments