Skip to content

Commit

Permalink
Remove _coerce_to_dtype
Browse files Browse the repository at this point in the history
  • Loading branch information
TomAugspurger committed Nov 29, 2018
1 parent 6cc9ce5 commit 7ab2a74
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 47 deletions.
32 changes: 0 additions & 32 deletions pandas/core/dtypes/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 0 additions & 15 deletions pandas/tests/dtypes/test_dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]')
Expand Down Expand Up @@ -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]')
Expand Down Expand Up @@ -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'))
Expand Down

0 comments on commit 7ab2a74

Please sign in to comment.