Skip to content

Commit 7b072a5

Browse files
committed
moar clean
1 parent d9b3fc0 commit 7b072a5

File tree

3 files changed

+8
-12
lines changed

3 files changed

+8
-12
lines changed

pandas/core/dtypes/cast.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from pandas.compat import PY3, string_types, text_type, to_str
1010

1111
from .common import (
12-
_INT64_DTYPE, _NS_DTYPE, _POSSIBLY_CAST_DTYPES, _TD_DTYPE, _string_dtypes,
12+
_INT64_DTYPE, _NS_DTYPE, _POSSIBLY_CAST_DTYPES, _TD_DTYPE,
1313
ensure_int8, ensure_int16, ensure_int32, ensure_int64, ensure_object,
1414
is_bool, is_bool_dtype, is_categorical_dtype, is_complex, is_complex_dtype,
1515
is_datetime64_dtype, is_datetime64_ns_dtype, is_datetime64tz_dtype,
@@ -541,7 +541,7 @@ def invalidate_string_dtypes(dtype_set):
541541
"""Change string like dtypes to object for
542542
``DataFrame.select_dtypes()``.
543543
"""
544-
non_string_dtypes = dtype_set - _string_dtypes
544+
non_string_dtypes = dtype_set - {np.dtype('S').type, np.dtype('<U').type}
545545
if non_string_dtypes != dtype_set:
546546
raise TypeError("string dtypes are not allowed, use 'object' instead")
547547

pandas/core/dtypes/common.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
from pandas._libs import algos, lib
77
from pandas._libs.tslibs import conversion
8-
from pandas.compat import PY3, PY36, binary_type, string_types, text_type
8+
from pandas.compat import PY3, PY36, string_types
99

1010
from pandas.core.dtypes.dtypes import (
1111
CategoricalDtype, DatetimeTZDtype, ExtensionDtype, IntervalDtype,
@@ -1825,7 +1825,7 @@ def _is_dtype_type(arr_or_dtype, condition):
18251825
return condition(tipo)
18261826

18271827

1828-
def _get_dtype_from_object(dtype):
1828+
def infer_dtype_from_object(dtype):
18291829
"""
18301830
Get a numpy dtype.type-style object for a dtype object.
18311831
@@ -1869,7 +1869,7 @@ def _get_dtype_from_object(dtype):
18691869
dtype += '64'
18701870

18711871
try:
1872-
return _get_dtype_from_object(getattr(np, dtype))
1872+
return infer_dtype_from_object(getattr(np, dtype))
18731873
except (AttributeError, TypeError):
18741874
# Handles cases like _get_dtype(int) i.e.,
18751875
# Python objects that are valid dtypes
@@ -1879,7 +1879,7 @@ def _get_dtype_from_object(dtype):
18791879
# further handle internal types
18801880
pass
18811881

1882-
return _get_dtype_from_object(np.dtype(dtype))
1882+
return infer_dtype_from_object(np.dtype(dtype))
18831883

18841884

18851885
def _validate_date_like_dtype(dtype):
@@ -1907,10 +1907,6 @@ def _validate_date_like_dtype(dtype):
19071907
raise ValueError(msg.format(name=dtype.name, type=dtype.type.__name__))
19081908

19091909

1910-
_string_dtypes = frozenset(map(_get_dtype_from_object, (binary_type,
1911-
text_type)))
1912-
1913-
19141910
def pandas_dtype(dtype):
19151911
"""
19161912
Converts input into a pandas only dtype object or a numpy dtype object.

pandas/core/frame.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
is_scalar,
6161
is_dtype_equal,
6262
needs_i8_conversion,
63-
_get_dtype_from_object,
63+
infer_dtype_from_object,
6464
ensure_float64,
6565
ensure_int64,
6666
ensure_platform_int,
@@ -3288,7 +3288,7 @@ def _get_info_slice(obj, indexer):
32883288

32893289
# convert the myriad valid dtypes object to a single representation
32903290
include, exclude = map(
3291-
lambda x: frozenset(map(_get_dtype_from_object, x)), selection)
3291+
lambda x: frozenset(map(infer_dtype_from_object, x)), selection)
32923292
for dtypes in (include, exclude):
32933293
invalidate_string_dtypes(dtypes)
32943294

0 commit comments

Comments
 (0)