diff --git a/pandas/core/strings/accessor.py b/pandas/core/strings/accessor.py index 71a50c69bfee1..f8dad3b252223 100644 --- a/pandas/core/strings/accessor.py +++ b/pandas/core/strings/accessor.py @@ -562,6 +562,8 @@ def cat( if sep is None: sep = "" + data: Series | np.ndarray + if isinstance(self._orig, ABCIndex): data = Series(self._orig, index=self._orig, dtype=self._orig.dtype) else: # Series @@ -569,9 +571,7 @@ def cat( # concatenate Series/Index with itself if no "others" if others is None: - # error: Incompatible types in assignment (expression has type - # "ndarray", variable has type "Series") - data = ensure_object(data) # type: ignore[assignment] + data = ensure_object(data) na_mask = isna(data) if na_rep is None and na_mask.any(): return sep.join(data[~na_mask])