Skip to content

TYP: ExtensionDtype.name/type as ClassVar #54458

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion pandas/core/arrays/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import numbers
from typing import (
TYPE_CHECKING,
ClassVar,
cast,
)

Expand Down Expand Up @@ -60,7 +61,7 @@ class BooleanDtype(BaseMaskedDtype):
BooleanDtype
"""

name = "boolean"
name: ClassVar[str] = "boolean"

# https://github.com/python/mypy/issues/4125
# error: Signature of "type" incompatible with supertype "BaseMaskedDtype"
Expand Down
6 changes: 4 additions & 2 deletions pandas/core/arrays/floating.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import ClassVar

import numpy as np

from pandas.core.dtypes.base import register_extension_dtype
Expand Down Expand Up @@ -156,14 +158,14 @@ class FloatingArray(NumericArray):
@register_extension_dtype
class Float32Dtype(FloatingDtype):
type = np.float32
name = "Float32"
name: ClassVar[str] = "Float32"
__doc__ = _dtype_docstring.format(dtype="float32")


@register_extension_dtype
class Float64Dtype(FloatingDtype):
type = np.float64
name = "Float64"
name: ClassVar[str] = "Float64"
__doc__ = _dtype_docstring.format(dtype="float64")


Expand Down
18 changes: 10 additions & 8 deletions pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

from typing import ClassVar

import numpy as np

from pandas.core.dtypes.base import register_extension_dtype
Expand Down Expand Up @@ -205,56 +207,56 @@ class IntegerArray(NumericArray):
@register_extension_dtype
class Int8Dtype(IntegerDtype):
type = np.int8
name = "Int8"
name: ClassVar[str] = "Int8"
__doc__ = _dtype_docstring.format(dtype="int8")


@register_extension_dtype
class Int16Dtype(IntegerDtype):
type = np.int16
name = "Int16"
name: ClassVar[str] = "Int16"
__doc__ = _dtype_docstring.format(dtype="int16")


@register_extension_dtype
class Int32Dtype(IntegerDtype):
type = np.int32
name = "Int32"
name: ClassVar[str] = "Int32"
__doc__ = _dtype_docstring.format(dtype="int32")


@register_extension_dtype
class Int64Dtype(IntegerDtype):
type = np.int64
name = "Int64"
name: ClassVar[str] = "Int64"
__doc__ = _dtype_docstring.format(dtype="int64")


@register_extension_dtype
class UInt8Dtype(IntegerDtype):
type = np.uint8
name = "UInt8"
name: ClassVar[str] = "UInt8"
__doc__ = _dtype_docstring.format(dtype="uint8")


@register_extension_dtype
class UInt16Dtype(IntegerDtype):
type = np.uint16
name = "UInt16"
name: ClassVar[str] = "UInt16"
__doc__ = _dtype_docstring.format(dtype="uint16")


@register_extension_dtype
class UInt32Dtype(IntegerDtype):
type = np.uint32
name = "UInt32"
name: ClassVar[str] = "UInt32"
__doc__ = _dtype_docstring.format(dtype="uint32")


@register_extension_dtype
class UInt64Dtype(IntegerDtype):
type = np.uint64
name = "UInt64"
name: ClassVar[str] = "UInt64"
__doc__ = _dtype_docstring.format(dtype="uint64")


Expand Down
5 changes: 4 additions & 1 deletion pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from typing import (
TYPE_CHECKING,
ClassVar,
Literal,
)

Expand Down Expand Up @@ -96,7 +97,9 @@ class StringDtype(StorageExtensionDtype):
string[pyarrow]
"""

name = "string"
# error: Cannot override instance variable (previously declared on
# base class "StorageExtensionDtype") with class variable
name: ClassVar[str] = "string" # type: ignore[misc]

#: StringDtype().na_value uses pandas.NA
@property
Expand Down
1 change: 0 additions & 1 deletion pandas/core/dtypes/dtypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1488,7 +1488,6 @@ class BaseMaskedDtype(ExtensionDtype):
Base class for dtypes for BaseMaskedArray subclasses.
"""

name: str
base = None
type: type

Expand Down