Skip to content

Commit 7ab2a74

Browse files
committed
Remove _coerce_to_dtype
1 parent 6cc9ce5 commit 7ab2a74

File tree

2 files changed

+0
-47
lines changed

2 files changed

+0
-47
lines changed

pandas/core/dtypes/common.py

-32
Original file line numberDiff line numberDiff line change
@@ -1767,38 +1767,6 @@ def is_complex_dtype(arr_or_dtype):
17671767
return issubclass(tipo, np.complexfloating)
17681768

17691769

1770-
def _coerce_to_dtype(dtype):
1771-
"""
1772-
Coerce a string or np.dtype to a pandas or numpy
1773-
dtype if possible.
1774-
1775-
If we cannot convert to a pandas dtype initially,
1776-
we convert to a numpy dtype.
1777-
1778-
Parameters
1779-
----------
1780-
dtype : The dtype that we want to coerce.
1781-
1782-
Returns
1783-
-------
1784-
pd_or_np_dtype : The coerced dtype.
1785-
"""
1786-
1787-
if is_categorical_dtype(dtype):
1788-
categories = getattr(dtype, 'categories', None)
1789-
ordered = getattr(dtype, 'ordered', False)
1790-
dtype = CategoricalDtype(categories=categories, ordered=ordered)
1791-
elif is_datetime64tz_dtype(dtype):
1792-
dtype = DatetimeTZDtype.construct_from_string(dtype)
1793-
elif is_period_dtype(dtype):
1794-
dtype = PeriodDtype(dtype)
1795-
elif is_interval_dtype(dtype):
1796-
dtype = IntervalDtype(dtype)
1797-
else:
1798-
dtype = np.dtype(dtype)
1799-
return dtype
1800-
1801-
18021770
def _get_dtype(arr_or_dtype):
18031771
"""
18041772
Get the dtype instance associated with an array

pandas/tests/dtypes/test_dtypes.py

-15
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
is_dtype_equal, is_datetime64_ns_dtype,
1818
is_datetime64_dtype, is_interval_dtype,
1919
is_datetime64_any_dtype, is_string_dtype,
20-
_coerce_to_dtype,
2120
is_bool_dtype,
2221
)
2322
from pandas.core.sparse.api import SparseDtype
@@ -173,12 +172,6 @@ def test_subclass(self):
173172
assert issubclass(type(a), type(a))
174173
assert issubclass(type(a), type(b))
175174

176-
def test_coerce_to_dtype(self):
177-
assert (_coerce_to_dtype('datetime64[ns, US/Eastern]') ==
178-
DatetimeTZDtype('ns', 'US/Eastern'))
179-
assert (_coerce_to_dtype('datetime64[ns, Asia/Tokyo]') ==
180-
DatetimeTZDtype('ns', 'Asia/Tokyo'))
181-
182175
def test_compat(self):
183176
assert is_datetime64tz_dtype(self.dtype)
184177
assert is_datetime64tz_dtype('datetime64[ns, US/Eastern]')
@@ -319,10 +312,6 @@ def test_identity(self):
319312
assert PeriodDtype('period[1S1U]') == PeriodDtype('period[1000001U]')
320313
assert PeriodDtype('period[1S1U]') is PeriodDtype('period[1000001U]')
321314

322-
def test_coerce_to_dtype(self):
323-
assert _coerce_to_dtype('period[D]') == PeriodDtype('period[D]')
324-
assert _coerce_to_dtype('period[3M]') == PeriodDtype('period[3M]')
325-
326315
def test_compat(self):
327316
assert not is_datetime64_ns_dtype(self.dtype)
328317
assert not is_datetime64_ns_dtype('period[D]')
@@ -517,10 +506,6 @@ def test_is_dtype(self):
517506
assert not IntervalDtype.is_dtype(np.int64)
518507
assert not IntervalDtype.is_dtype(np.float64)
519508

520-
def test_coerce_to_dtype(self):
521-
assert (_coerce_to_dtype('interval[int64]') ==
522-
IntervalDtype('interval[int64]'))
523-
524509
def test_equality(self):
525510
assert is_dtype_equal(self.dtype, 'interval[int64]')
526511
assert is_dtype_equal(self.dtype, IntervalDtype('int64'))

0 commit comments

Comments
 (0)