def astype(self, index_ops: IndexOpsLike, dtype: Union[str, type, Dtype]) -> IndexOpsLike: dtype, _ = pandas_on_spark_type(dtype) if isinstance(dtype, CategoricalDtype) and cast(CategoricalDtype, dtype).categories is None: return index_ops.copy() return _to_cat(index_ops).astype(dtype)
def astype(self, index_ops: IndexOpsLike, dtype: Union[str, type, Dtype]) -> IndexOpsLike: dtype, _ = pandas_on_spark_type(dtype) if isinstance(dtype, CategoricalDtype) and cast(CategoricalDtype, dtype).categories is None: return index_ops.copy() categories = cast(CategoricalDtype, index_ops.dtype).categories if len(categories) == 0: scol = SF.lit(None) else: kvs = chain( *[(SF.lit(code), SF.lit(category)) for code, category in enumerate(categories)] ) map_scol = F.create_map(*kvs) scol = map_scol.getItem(index_ops.spark.column) return index_ops._with_new_scol(scol).astype(dtype)
def nan_to_null(self, index_ops: IndexOpsLike) -> IndexOpsLike: return index_ops.copy()