Skip to content

DataFrame.astype('category') currently not supported #558

Closed
@zmoon

Description

@zmoon
          Weird, using v1.5.3.230227, which has that, I got this message

error: Argument 1 to "astype" of "DataFrame" has incompatible type "Literal['category']"; expected "Union[Union[Union[Type[bool], Type[bool_], BooleanDtype, Literal['bool']], Union[Type[int], Int8Dtype, Int16Dtype, Int32Dtype, Int64Dtype, Type[signedinteger[_8Bit]], Type[signedinteger[_16Bit]], Type[signedinteger[_32Bit]], Type[signedinteger[_64Bit]], Type[unsignedinteger[_8Bit]], Type[unsignedinteger[_16Bit]], Type[unsignedinteger[_32Bit]], Type[unsignedinteger[_64Bit]], Type[signedinteger[Any]], Type[unsignedinteger[Any]], Type[signedinteger[Any]], Type[unsignedinteger[Any]], Literal['int', 'int32']], Union[Type[str], StringDtype, Literal['str']], Type[bytes], Union[Float32Dtype, Float64Dtype, Type[floating[_16Bit]], Type[floating[_32Bit]], Type[floating[_64Bit]], Type[float], Literal['float']], Union[Type[complexfloating[_32Bit, _32Bit]], Type[complexfloating[_64Bit, _64Bit]], Type[complex], Literal['complex']], CategoricalDtype, ExtensionDtype, Literal['timedelta64[ns]', 'datetime64[ns]']], Mapping[Any, Union[ExtensionDtype, Union[str, dtype[generic], Type[str], Type[complex], Type[bool], Type[object]]]], Series[Any]]" [arg-type]

I guess because CategoryDtypeArg is missing from AstypeArg.

AstypeArg: TypeAlias = (
BooleanDtypeArg
| IntDtypeArg
| StrDtypeArg
| BytesDtypeArg
| FloatDtypeArg
| ComplexDtypeArg
| TimedeltaDtypeArg
| TimestampDtypeArg
| CategoricalDtype
| ExtensionDtype
)

Originally posted by @zmoon in #556 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions