def coerce_dtype(self, series_or_index: pd.Index) -> pd.Index: """Coerce type of a pd.Index by type specified in pandas_dtype. :param pd.Index series: One-dimensional ndarray with axis labels (including time series). :returns: ``Index`` with coerced data type """ if self._pandas_dtype is PandasDtype.String: return series_or_index.where(series_or_index.isna(), series_or_index.astype(str)) # only coerce non-null elements to string return series_or_index.astype(self.dtype)