Skip to content

Commit 873b8a2

Browse files
authored
Fix types of declared ExtensionDtypes (#329)
1 parent 90c5a91 commit 873b8a2

File tree

7 files changed

+51
-8
lines changed

7 files changed

+51
-8
lines changed

pandas-stubs/__init__.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ from .core.api import (
2525
DateOffset as DateOffset,
2626
DatetimeIndex as DatetimeIndex,
2727
DatetimeTZDtype as DatetimeTZDtype,
28+
Float32Dtype as Float32Dtype,
29+
Float64Dtype as Float64Dtype,
2830
Float64Index as Float64Index,
2931
Grouper as Grouper,
3032
Index as Index,

pandas-stubs/core/api.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ from pandas.core.algorithms import (
55
)
66
from pandas.core.arrays import Categorical as Categorical
77
from pandas.core.arrays.boolean import BooleanDtype as BooleanDtype
8+
from pandas.core.arrays.floating import (
9+
Float32Dtype as Float32Dtype,
10+
Float64Dtype as Float64Dtype,
11+
)
812
from pandas.core.arrays.integer import (
913
Int8Dtype as Int8Dtype,
1014
Int16Dtype as Int16Dtype,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
from pandas.core.arrays.numeric import NumericDtype
2+
3+
class Float32Dtype(NumericDtype): ...
4+
class Float64Dtype(NumericDtype): ...

pandas-stubs/core/arrays/integer.pyi

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class IntegerArray(BaseMaskedArray):
2828
def __setitem__(self, key, value) -> None: ...
2929
def astype(self, dtype, copy: bool = ...): ...
3030

31-
class Int8Dtype: ...
32-
class Int16Dtype: ...
33-
class Int32Dtype: ...
34-
class Int64Dtype: ...
35-
class UInt8Dtype: ...
36-
class UInt16Dtype: ...
37-
class UInt32Dtype: ...
38-
class UInt64Dtype: ...
31+
class Int8Dtype(_IntegerDtype): ...
32+
class Int16Dtype(_IntegerDtype): ...
33+
class Int32Dtype(_IntegerDtype): ...
34+
class Int64Dtype(_IntegerDtype): ...
35+
class UInt8Dtype(_IntegerDtype): ...
36+
class UInt16Dtype(_IntegerDtype): ...
37+
class UInt32Dtype(_IntegerDtype): ...
38+
class UInt64Dtype(_IntegerDtype): ...
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from pandas.core.dtypes.dtypes import BaseMaskedDtype
2+
3+
class NumericDtype(BaseMaskedDtype): ...

pandas-stubs/core/dtypes/dtypes.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ _str = str
1717

1818
def register_extension_dtype(cls: type[ExtensionDtype]) -> type[ExtensionDtype]: ...
1919

20+
class BaseMaskedDtype(ExtensionDtype): ...
21+
2022
class PandasExtensionDtype(ExtensionDtype):
2123
subdtype = ...
2224
str: _str | None = ...

tests/test_api_types.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1+
from typing import Type
2+
13
import numpy as np
24
import pandas as pd
5+
from pandas.api.extensions import ExtensionDtype
36
import pandas.api.types as api
47
from typing_extensions import assert_type
58

@@ -176,3 +179,28 @@ def test_infer_dtype() -> None:
176179
def test_union_categoricals() -> None:
177180
to_union = [pd.Categorical([1, 2, 3]), pd.Categorical([3, 4, 5])]
178181
check(assert_type(api.union_categoricals(to_union), pd.Categorical), pd.Categorical)
182+
183+
184+
def check_extension_dtypes() -> None:
185+
# GH 315
186+
def check_ext_dtype(etype: Type[ExtensionDtype]):
187+
assert issubclass(etype, ExtensionDtype)
188+
189+
check_ext_dtype(pd.Int64Dtype)
190+
check_ext_dtype(pd.Int8Dtype)
191+
check_ext_dtype(pd.Int16Dtype)
192+
check_ext_dtype(pd.Int32Dtype)
193+
check_ext_dtype(pd.Int64Dtype)
194+
check_ext_dtype(pd.UInt8Dtype)
195+
check_ext_dtype(pd.UInt16Dtype)
196+
check_ext_dtype(pd.UInt32Dtype)
197+
check_ext_dtype(pd.UInt64Dtype)
198+
check_ext_dtype(pd.BooleanDtype)
199+
check_ext_dtype(pd.StringDtype)
200+
check_ext_dtype(pd.CategoricalDtype)
201+
check_ext_dtype(pd.DatetimeTZDtype)
202+
check_ext_dtype(pd.IntervalDtype)
203+
check_ext_dtype(pd.PeriodDtype)
204+
check_ext_dtype(pd.SparseDtype)
205+
check_ext_dtype(pd.Float32Dtype)
206+
check_ext_dtype(pd.Float64Dtype)

0 commit comments

Comments
 (0)