Skip to content

Commit 1d5899d

Browse files
committed
BUG: make is_string_dtype stricter
Resolves pandas-dev#15585.
1 parent d30aeeb commit 1d5899d

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

pandas/core/dtypes/common.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
Interval,
1616
Period,
1717
algos,
18+
lib,
1819
)
1920
from pandas._libs.tslibs import conversion
2021
from pandas._typing import (
@@ -558,8 +559,12 @@ def is_string_dtype(arr_or_dtype) -> bool:
558559
>>> is_string_dtype(pd.Series([1, 2]))
559560
False
560561
"""
561-
# TODO: gh-15585: consider making the checks stricter.
562+
562563
def condition(dtype) -> bool:
564+
if isinstance(arr_or_dtype, np.ndarray):
565+
if not lib.infer_dtype(arr_or_dtype) in ("string", "unicode"):
566+
return False
567+
563568
return dtype.kind in ("O", "S", "U") and not is_excluded_dtype(dtype)
564569

565570
def is_excluded_dtype(dtype) -> bool:
@@ -1316,7 +1321,6 @@ def is_bool_dtype(arr_or_dtype) -> bool:
13161321
# now we use the special definition for Index
13171322

13181323
if isinstance(arr_or_dtype, ABCIndex):
1319-
13201324
# TODO(jreback)
13211325
# we don't have a boolean Index class
13221326
# so its object, we need to infer to
@@ -1666,7 +1670,6 @@ def infer_dtype_from_object(dtype) -> DtypeObj:
16661670
if is_extension_array_dtype(dtype):
16671671
return dtype.type
16681672
elif isinstance(dtype, str):
1669-
16701673
# TODO(jreback)
16711674
# should deprecate these
16721675
if dtype in ["datetimetz", "datetime64tz"]:

0 commit comments

Comments
 (0)