Skip to content

Commit 3b335f7

Browse files
committed
CLN: Explanatory comments
1 parent c87be76 commit 3b335f7

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

pandas/core/categorical.py

+4
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
260260
# c.) infer from values
261261

262262
if dtype is not None:
263+
# The dtype argument takes precedence over values.dtype (if any)
263264
if isinstance(dtype, compat.string_types):
264265
if dtype == 'category':
265266
dtype = CategoricalDtype(categories, ordered)
@@ -274,9 +275,12 @@ def __init__(self, values, categories=None, ordered=None, dtype=None,
274275
ordered = dtype.ordered
275276

276277
elif is_categorical(values):
278+
# If no "dtype" was passed, use the one from "values", but honor
279+
# the "ordered" and "categories" arguments
277280
dtype = values.dtype._from_categorical_dtype(values.dtype,
278281
categories, ordered)
279282
else:
283+
# If dtype=None and values is not categorical, create a new dtype
280284
dtype = CategoricalDtype(categories, ordered)
281285

282286
# At this point, dtype is always a CategoricalDtype

0 commit comments

Comments
 (0)