diff --git a/pandas/core/dtypes/common.py b/pandas/core/dtypes/common.py index 3f4ebc88c1c8a..2a46d335ff512 100644 --- a/pandas/core/dtypes/common.py +++ b/pandas/core/dtypes/common.py @@ -45,7 +45,6 @@ is_re_compilable, is_scalar, is_sequence, - is_string_like, ) from pandas._typing import ArrayLike @@ -1383,8 +1382,8 @@ def is_numeric_v_string_like(a, b): is_a_string_array = is_a_array and is_string_like_dtype(a) is_b_string_array = is_b_array and is_string_like_dtype(b) - is_a_scalar_string_like = not is_a_array and is_string_like(a) - is_b_scalar_string_like = not is_b_array and is_string_like(b) + is_a_scalar_string_like = not is_a_array and isinstance(a, str) + is_b_scalar_string_like = not is_b_array and isinstance(b, str) return ( (is_a_numeric_array and is_b_scalar_string_like) diff --git a/pandas/core/dtypes/inference.py b/pandas/core/dtypes/inference.py index e69e703f3a96c..61fa7940c1bce 100644 --- a/pandas/core/dtypes/inference.py +++ b/pandas/core/dtypes/inference.py @@ -67,30 +67,6 @@ def is_number(obj): return isinstance(obj, (Number, np.number)) -def is_string_like(obj): - """ - Check if the object is a string. - - Parameters - ---------- - obj : The object to check - - Examples - -------- - >>> is_string_like("foo") - True - >>> is_string_like(1) - False - - Returns - ------- - is_str_like : bool - Whether `obj` is a string or not. - """ - - return isinstance(obj, str) - - def _iterable_not_string(obj): """ Check if the object is an iterable but not a string. diff --git a/pandas/core/indexes/datetimes.py b/pandas/core/indexes/datetimes.py index e5cecd090e061..2d0ecf1b936da 100644 --- a/pandas/core/indexes/datetimes.py +++ b/pandas/core/indexes/datetimes.py @@ -16,7 +16,6 @@ is_integer, is_list_like, is_scalar, - is_string_like, ) from pandas.core.dtypes.concat import concat_compat from pandas.core.dtypes.dtypes import DatetimeTZDtype @@ -1659,7 +1658,7 @@ def bdate_range( msg = "freq must be specified for bdate_range; use date_range instead" raise TypeError(msg) - if is_string_like(freq) and freq.startswith("C"): + if isinstance(freq, str) and freq.startswith("C"): try: weekmask = weekmask or "Mon Tue Wed Thu Fri" freq = prefix_mapping[freq](holidays=holidays, weekmask=weekmask) diff --git a/pandas/core/series.py b/pandas/core/series.py index 7b65816dc06b9..73a05b4cdfa66 100644 --- a/pandas/core/series.py +++ b/pandas/core/series.py @@ -34,7 +34,6 @@ is_list_like, is_object_dtype, is_scalar, - is_string_like, is_timedelta64_dtype, ) from pandas.core.dtypes.generic import ( @@ -4539,7 +4538,7 @@ def to_csv(self, *args, **kwargs): # passed as second argument (while the first is the same) maybe_sep = args[1] - if not (is_string_like(maybe_sep) and len(maybe_sep) == 1): + if not (isinstance(maybe_sep, str) and len(maybe_sep) == 1): # old signature warnings.warn( "The signature of `Series.to_csv` was aligned " diff --git a/pandas/core/strings.py b/pandas/core/strings.py index f1a67d0892cad..7194d1cf08e4a 100644 --- a/pandas/core/strings.py +++ b/pandas/core/strings.py @@ -19,7 +19,6 @@ is_list_like, is_re, is_scalar, - is_string_like, ) from pandas.core.dtypes.generic import ( ABCDataFrame, @@ -601,7 +600,7 @@ def str_replace(arr, pat, repl, n=-1, case=None, flags=0, regex=True): """ # Check whether repl is valid (GH 13438, GH 15055) - if not (is_string_like(repl) or callable(repl)): + if not (isinstance(repl, str) or callable(repl)): raise TypeError("repl must be a string or callable") is_compiled_re = is_re(pat) diff --git a/pandas/io/formats/style.py b/pandas/io/formats/style.py index 9865087a26ae3..dce0afd8670b2 100644 --- a/pandas/io/formats/style.py +++ b/pandas/io/formats/style.py @@ -18,7 +18,7 @@ from pandas.compat._optional import import_optional_dependency from pandas.util._decorators import Appender -from pandas.core.dtypes.common import is_float, is_string_like +from pandas.core.dtypes.common import is_float import pandas as pd from pandas.api.types import is_dict_like, is_list_like @@ -1488,7 +1488,7 @@ def _get_level_lengths(index, hidden_elements=None): def _maybe_wrap_formatter(formatter): - if is_string_like(formatter): + if isinstance(formatter, str): return lambda x: formatter.format(x) elif callable(formatter): return formatter