Skip to content

Commit

Permalink
consolidate special casing
Browse files Browse the repository at this point in the history
  • Loading branch information
jschendel committed May 21, 2019
1 parent 77f171d commit cf12a1f
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
5 changes: 1 addition & 4 deletions pandas/core/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ def is_copy(self, msg):
def _validate_dtype(self, dtype):
""" validate the passed dtype """

# GH 26336: don't convert 'category' to CategoricalDtype
if isinstance(dtype, str) and dtype == 'category':
pass
elif dtype is not None:
if dtype is not None:
dtype = pandas_dtype(dtype)

# a compound dtype
Expand Down
5 changes: 1 addition & 4 deletions pandas/core/internals/construction.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,7 @@ def sanitize_array(data, index, dtype=None, copy=False,
Sanitize input data to an ndarray, copy if specified, coerce to the
dtype if specified.
"""
# GH 26336: don't convert 'category' to CategoricalDtype
if isinstance(dtype, str) and dtype == 'category':
pass
elif dtype is not None:
if dtype is not None:
dtype = pandas_dtype(dtype)

if isinstance(data, ma.MaskedArray):
Expand Down
8 changes: 7 additions & 1 deletion pandas/core/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from pandas.util._validators import validate_bool_kwarg

from pandas.core.dtypes.common import (
_is_unorderable_exception, ensure_platform_int, is_bool,
_is_unorderable_exception, ensure_platform_int, is_bool, is_categorical,
is_categorical_dtype, is_datetime64_dtype, is_datetimelike, is_dict_like,
is_extension_array_dtype, is_extension_type, is_hashable, is_integer,
is_iterator, is_list_like, is_scalar, is_string_like, is_timedelta64_dtype)
Expand Down Expand Up @@ -168,6 +168,12 @@ def __init__(self, data=None, index=None, dtype=None, name=None,
if data is None:
data = {}
if dtype is not None:
# GH 26336: explicitly handle 'category' to avoid warning
# TODO: Remove after CategoricalDtype defaults to ordered=False
if (isinstance(dtype, str) and dtype == 'category' and
is_categorical(data)):
dtype = data.dtype

dtype = self._validate_dtype(dtype)

if isinstance(data, MultiIndex):
Expand Down
14 changes: 2 additions & 12 deletions pandas/io/packers.py
Original file line number Diff line number Diff line change
Expand Up @@ -623,19 +623,9 @@ def decode(obj):
return Interval(obj['left'], obj['right'], obj['closed'])
elif typ == 'series':
dtype = dtype_for(obj['dtype'])

# GH 26336: don't convert 'category' to CategoricalDtype
if isinstance(dtype, str) and dtype == 'category':
pd_dtype = dtype
else:
pd_dtype = pandas_dtype(dtype)

index = obj['index']
result = Series(unconvert(obj['data'], dtype, obj['compress']),
index=index,
dtype=pd_dtype,
name=obj['name'])
return result
data = unconvert(obj['data'], dtype, obj['compress'])
return Series(data, index=index, dtype=dtype, name=obj['name'])

elif typ == 'block_manager':
axes = obj['axes']
Expand Down

0 comments on commit cf12a1f

Please sign in to comment.