|
1 | 1 | """ define extension dtypes """
|
| 2 | +import builtins |
2 | 3 | import re
|
| 4 | +from typing import Any, Dict, Optional, Tuple, Type |
3 | 5 | import warnings
|
4 | 6 |
|
5 | 7 | import numpy as np
|
@@ -104,17 +106,23 @@ class PandasExtensionDtype(_DtypeOpsMixin):
|
104 | 106 |
|
105 | 107 | THIS IS NOT A REAL NUMPY DTYPE
|
106 | 108 | """
|
107 |
| - type = None |
| 109 | + type = None # type: Any |
| 110 | + kind = None # type: Any |
| 111 | + """ |
| 112 | + The Any type annotations above are here only because mypy seems to have a |
| 113 | + problem dealing with with multiple inheritance from PandasExtensionDtype |
| 114 | + and ExtensionDtype's @properties in the subclasses below. Those subclasses |
| 115 | + are explicitly typed, as appropriate. |
| 116 | + """ |
108 | 117 | subdtype = None
|
109 |
| - kind = None |
110 |
| - str = None |
| 118 | + str = None # type: Optional[builtins.str] |
111 | 119 | num = 100
|
112 |
| - shape = tuple() |
| 120 | + shape = tuple() # type: Tuple[int, ...] |
113 | 121 | itemsize = 8
|
114 | 122 | base = None
|
115 | 123 | isbuiltin = 0
|
116 | 124 | isnative = 0
|
117 |
| - _cache = {} |
| 125 | + _cache = {} # type: Dict[builtins.str, object] |
118 | 126 |
|
119 | 127 | def __unicode__(self):
|
120 | 128 | return self.name
|
@@ -217,12 +225,12 @@ class CategoricalDtype(PandasExtensionDtype, ExtensionDtype):
|
217 | 225 | """
|
218 | 226 | # TODO: Document public vs. private API
|
219 | 227 | name = 'category'
|
220 |
| - type = CategoricalDtypeType |
221 |
| - kind = 'O' |
| 228 | + type = CategoricalDtypeType # type: Type[CategoricalDtypeType] |
| 229 | + kind = 'O' # type: builtins.str |
222 | 230 | str = '|O08'
|
223 | 231 | base = np.dtype('O')
|
224 | 232 | _metadata = ('categories', 'ordered')
|
225 |
| - _cache = {} |
| 233 | + _cache = {} # type: Dict[builtins.str, object] |
226 | 234 |
|
227 | 235 | def __init__(self, categories=None, ordered=None):
|
228 | 236 | self._finalize(categories, ordered, fastpath=False)
|
@@ -584,15 +592,15 @@ class DatetimeTZDtype(PandasExtensionDtype, ExtensionDtype):
|
584 | 592 | THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of
|
585 | 593 | np.datetime64[ns]
|
586 | 594 | """
|
587 |
| - type = Timestamp |
588 |
| - kind = 'M' |
| 595 | + type = Timestamp # type: Type[Timestamp] |
| 596 | + kind = 'M' # type: builtins.str |
589 | 597 | str = '|M8[ns]'
|
590 | 598 | num = 101
|
591 | 599 | base = np.dtype('M8[ns]')
|
592 | 600 | na_value = NaT
|
593 | 601 | _metadata = ('unit', 'tz')
|
594 | 602 | _match = re.compile(r"(datetime64|M8)\[(?P<unit>.+), (?P<tz>.+)\]")
|
595 |
| - _cache = {} |
| 603 | + _cache = {} # type: Dict[builtins.str, object] |
596 | 604 |
|
597 | 605 | def __init__(self, unit="ns", tz=None):
|
598 | 606 | """
|
@@ -736,14 +744,14 @@ class PeriodDtype(ExtensionDtype, PandasExtensionDtype):
|
736 | 744 |
|
737 | 745 | THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of np.int64.
|
738 | 746 | """
|
739 |
| - type = Period |
740 |
| - kind = 'O' |
| 747 | + type = Period # type: Type[Period] |
| 748 | + kind = 'O' # type: builtins.str |
741 | 749 | str = '|O08'
|
742 | 750 | base = np.dtype('O')
|
743 | 751 | num = 102
|
744 | 752 | _metadata = ('freq',)
|
745 | 753 | _match = re.compile(r"(P|p)eriod\[(?P<freq>.+)\]")
|
746 |
| - _cache = {} |
| 754 | + _cache = {} # type: Dict[builtins.str, object] |
747 | 755 |
|
748 | 756 | def __new__(cls, freq=None):
|
749 | 757 | """
|
@@ -860,13 +868,13 @@ class IntervalDtype(PandasExtensionDtype, ExtensionDtype):
|
860 | 868 | THIS IS NOT A REAL NUMPY DTYPE
|
861 | 869 | """
|
862 | 870 | name = 'interval'
|
863 |
| - kind = None |
| 871 | + kind = None # type: Optional[builtins.str] |
864 | 872 | str = '|O08'
|
865 | 873 | base = np.dtype('O')
|
866 | 874 | num = 103
|
867 | 875 | _metadata = ('subtype',)
|
868 | 876 | _match = re.compile(r"(I|i)nterval\[(?P<subtype>.+)\]")
|
869 |
| - _cache = {} |
| 877 | + _cache = {} # type: Dict[builtins.str, object] |
870 | 878 |
|
871 | 879 | def __new__(cls, subtype=None):
|
872 | 880 | """
|
|
0 commit comments