From 7ab2a74c304c6791f8f28edc01b7f43b2cbd2fab Mon Sep 17 00:00:00 2001 From: Tom Augspurger Date: Thu, 29 Nov 2018 10:16:32 -0600 Subject: [PATCH] Remove _coerce_to_dtype --- pandas/core/dtypes/common.py | 32 ------------------------------ pandas/tests/dtypes/test_dtypes.py | 15 -------------- 2 files changed, 47 deletions(-) diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 5a6a49360e1df..e1141c6b6b3a8 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -1767,38 +1767,6 @@ def is_complex_dtype(arr_or_dtype): return issubclass(tipo, np.complexfloating) -def _coerce_to_dtype(dtype): - """ - Coerce a string or np.dtype to a pandas or numpy - dtype if possible. - - If we cannot convert to a pandas dtype initially, - we convert to a numpy dtype. - - Parameters - ---------- - dtype : The dtype that we want to coerce. - - Returns - ------- - pd_or_np_dtype : The coerced dtype. - """ - - if is_categorical_dtype(dtype): - categories = getattr(dtype, 'categories', None) - ordered = getattr(dtype, 'ordered', False) - dtype = CategoricalDtype(categories=categories, ordered=ordered) - elif is_datetime64tz_dtype(dtype): - dtype = DatetimeTZDtype.construct_from_string(dtype) - elif is_period_dtype(dtype): - dtype = PeriodDtype(dtype) - elif is_interval_dtype(dtype): - dtype = IntervalDtype(dtype) - else: - dtype = np.dtype(dtype) - return dtype - - def _get_dtype(arr_or_dtype): """ Get the dtype instance associated with an array diff --git a/pandas/tests/dtypes/test_dtypes.py b/pandas/tests/dtypes/test_dtypes.py index fb9fbe0f5ee1d..888f4bdb73291 100644 --- a/pandas/tests/dtypes/test_dtypes.py +++ b/pandas/tests/dtypes/test_dtypes.py @@ -17,7 +17,6 @@ is_dtype_equal, is_datetime64_ns_dtype, is_datetime64_dtype, is_interval_dtype, is_datetime64_any_dtype, is_string_dtype, - _coerce_to_dtype, is_bool_dtype, ) from pandas.core.sparse.api import SparseDtype @@ -173,12 +172,6 @@ def test_subclass(self): assert issubclass(type(a), type(a)) assert issubclass(type(a), type(b)) - def test_coerce_to_dtype(self): - assert (_coerce_to_dtype('datetime64[ns, US/Eastern]') == - DatetimeTZDtype('ns', 'US/Eastern')) - assert (_coerce_to_dtype('datetime64[ns, Asia/Tokyo]') == - DatetimeTZDtype('ns', 'Asia/Tokyo')) - def test_compat(self): assert is_datetime64tz_dtype(self.dtype) assert is_datetime64tz_dtype('datetime64[ns, US/Eastern]') @@ -319,10 +312,6 @@ def test_identity(self): assert PeriodDtype('period[1S1U]') == PeriodDtype('period[1000001U]') assert PeriodDtype('period[1S1U]') is PeriodDtype('period[1000001U]') - def test_coerce_to_dtype(self): - assert _coerce_to_dtype('period[D]') == PeriodDtype('period[D]') - assert _coerce_to_dtype('period[3M]') == PeriodDtype('period[3M]') - def test_compat(self): assert not is_datetime64_ns_dtype(self.dtype) assert not is_datetime64_ns_dtype('period[D]') @@ -517,10 +506,6 @@ def test_is_dtype(self): assert not IntervalDtype.is_dtype(np.int64) assert not IntervalDtype.is_dtype(np.float64) - def test_coerce_to_dtype(self): - assert (_coerce_to_dtype('interval[int64]') == - IntervalDtype('interval[int64]')) - def test_equality(self): assert is_dtype_equal(self.dtype, 'interval[int64]') assert is_dtype_equal(self.dtype, IntervalDtype('int64'))