Skip to content

Commit 935c8c1

Browse files
committed
adjust doc string
1 parent 11d9ac1 commit 935c8c1

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

pandas/core/dtypes/dtypes.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -245,11 +245,23 @@ def _from_categorical_dtype(cls, dtype, categories=None, ordered=None):
245245
def _from_values_or_dtype(cls, values=None, categories=None, ordered=None,
246246
dtype=None):
247247
"""
248-
Construct from the inputs used in :class:`Categorical` construction.
249-
250-
This is an internal helper method, and specifically does not do the
251-
factorization step, if that is needed. Additional steps may
252-
therefore have to be taken to create the final dtype.
248+
Construct dtype from the input parameters used in :class:`Categorical`.
249+
250+
This constructor method specifically does not do the factorization
251+
step, if that is needed to find the categories. This constructor may
252+
therefore return ``CategoricalDtype(categories=None, ordered=None)``,
253+
which may not be useful. Additional steps may therefore have to be
254+
taken to create the final dtype.
255+
256+
The return dtype is specified from the inputs in this prioritized
257+
order:
258+
1. if dtype is a CategoricalDtype, return dtype
259+
2. if dtype is the string 'category', create a CategoricalDtype from
260+
the supplied categories and ordered parameters, and return that.
261+
3. if values is a categorical, use value.dtype, but override it with
262+
categories and ordered if either/both of those are not None.
263+
4. if dtype is None and values is not a categorical, construct the
264+
dtype from categories and ordered, even if either of those is None.
253265
254266
Parameters
255267
----------
@@ -307,7 +319,8 @@ def _from_values_or_dtype(cls, values=None, categories=None, ordered=None,
307319
categories, ordered)
308320
else:
309321
# If dtype=None and values is not categorical, create a new dtype.
310-
# Note: This could potentially have categories=None and ordered=None.
322+
# Note: This could potentially have categories=None and
323+
# ordered=None.
311324
dtype = CategoricalDtype(categories, ordered)
312325

313326
return dtype

0 commit comments

Comments
 (0)