From d90ce6c53df5d68f8c809f380e4fb8c27c25151c Mon Sep 17 00:00:00 2001 From: Antareep Sarkar Date: Fri, 7 Nov 2025 21:36:58 +0530 Subject: [PATCH] check for `np.str_` when checking strings --- pandas/core/dtypes/inference.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pandas/core/dtypes/inference.py b/pandas/core/dtypes/inference.py index 5e6f6d2124734..f3d61cbded718 100644 --- a/pandas/core/dtypes/inference.py +++ b/pandas/core/dtypes/inference.py @@ -100,7 +100,7 @@ def iterable_not_string(obj: object) -> bool: >>> iterable_not_string(1) False """ - return isinstance(obj, abc.Iterable) and not isinstance(obj, str) + return isinstance(obj, abc.Iterable) and not isinstance(obj, (str, np.str_)) @set_module("pandas.api.types") @@ -467,7 +467,7 @@ def is_sequence(obj: object) -> bool: iter(obj) # type: ignore[call-overload] # Has a length associated with it. len(obj) # type: ignore[arg-type] - return not isinstance(obj, (str, bytes)) + return not isinstance(obj, (str, bytes, np.str_)) except (TypeError, AttributeError): return False