Skip to content

Commit 845808b

Browse files
committed
Fix type annotations in pandas.core.dtypes
1 parent 0610a60 commit 845808b

File tree

4 files changed

+29
-27
lines changed

4 files changed

+29
-27
lines changed

mypy.ini

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,6 @@ ignore_errors=True
6262
[mypy-pandas.core.config_init]
6363
ignore_errors=True
6464

65-
[mypy-pandas.core.dtypes.dtypes]
66-
ignore_errors=True
67-
68-
[mypy-pandas.core.dtypes.missing]
69-
ignore_errors=True
70-
7165
[mypy-pandas.core.frame]
7266
ignore_errors=True
7367

pandas/core/dtypes/base.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
"""Extend pandas with custom array types"""
2-
from typing import List, Optional, Type
2+
from typing import List, Optional, Tuple, Type
33

44
import numpy as np
55

@@ -24,7 +24,7 @@ class _DtypeOpsMixin(object):
2424
# of the NA value, not the physical NA vaalue for storage.
2525
# e.g. for JSONArray, this is an empty dictionary.
2626
na_value = np.nan
27-
_metadata = ()
27+
_metadata = () # type: Tuple[str, ...]
2828

2929
def __eq__(self, other):
3030
"""Check whether 'other' is equal to self.
@@ -219,8 +219,7 @@ def type(self) -> Type:
219219
raise AbstractMethodError(self)
220220

221221
@property
222-
def kind(self):
223-
# type () -> str
222+
def kind(self) -> str:
224223
"""
225224
A character code (one of 'biufcmMOSUV'), default 'O'
226225

pandas/core/dtypes/dtypes.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
""" define extension dtypes """
2+
import builtins
23
import re
4+
from typing import Any, Dict, Optional, Tuple, Type
35
import warnings
46

57
import numpy as np
@@ -104,17 +106,23 @@ class PandasExtensionDtype(_DtypeOpsMixin):
104106
105107
THIS IS NOT A REAL NUMPY DTYPE
106108
"""
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+
"""
108117
subdtype = None
109-
kind = None
110-
str = None
118+
str = None # type: Optional[builtins.str]
111119
num = 100
112-
shape = tuple()
120+
shape = tuple() # type: Tuple[int, ...]
113121
itemsize = 8
114122
base = None
115123
isbuiltin = 0
116124
isnative = 0
117-
_cache = {}
125+
_cache = {} # type: Dict[builtins.str, object]
118126

119127
def __unicode__(self):
120128
return self.name
@@ -217,12 +225,12 @@ class CategoricalDtype(PandasExtensionDtype, ExtensionDtype):
217225
"""
218226
# TODO: Document public vs. private API
219227
name = 'category'
220-
type = CategoricalDtypeType
221-
kind = 'O'
228+
type = CategoricalDtypeType # type: Type[CategoricalDtypeType]
229+
kind = 'O' # type: builtins.str
222230
str = '|O08'
223231
base = np.dtype('O')
224232
_metadata = ('categories', 'ordered')
225-
_cache = {}
233+
_cache = {} # type: Dict[builtins.str, object]
226234

227235
def __init__(self, categories=None, ordered=None):
228236
self._finalize(categories, ordered, fastpath=False)
@@ -584,15 +592,15 @@ class DatetimeTZDtype(PandasExtensionDtype, ExtensionDtype):
584592
THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of
585593
np.datetime64[ns]
586594
"""
587-
type = Timestamp
588-
kind = 'M'
595+
type = Timestamp # type: Type[Timestamp]
596+
kind = 'M' # type: builtins.str
589597
str = '|M8[ns]'
590598
num = 101
591599
base = np.dtype('M8[ns]')
592600
na_value = NaT
593601
_metadata = ('unit', 'tz')
594602
_match = re.compile(r"(datetime64|M8)\[(?P<unit>.+), (?P<tz>.+)\]")
595-
_cache = {}
603+
_cache = {} # type: Dict[builtins.str, object]
596604

597605
def __init__(self, unit="ns", tz=None):
598606
"""
@@ -736,14 +744,14 @@ class PeriodDtype(ExtensionDtype, PandasExtensionDtype):
736744
737745
THIS IS NOT A REAL NUMPY DTYPE, but essentially a sub-class of np.int64.
738746
"""
739-
type = Period
740-
kind = 'O'
747+
type = Period # type: Type[Period]
748+
kind = 'O' # type: builtins.str
741749
str = '|O08'
742750
base = np.dtype('O')
743751
num = 102
744752
_metadata = ('freq',)
745753
_match = re.compile(r"(P|p)eriod\[(?P<freq>.+)\]")
746-
_cache = {}
754+
_cache = {} # type: Dict[builtins.str, object]
747755

748756
def __new__(cls, freq=None):
749757
"""
@@ -860,13 +868,13 @@ class IntervalDtype(PandasExtensionDtype, ExtensionDtype):
860868
THIS IS NOT A REAL NUMPY DTYPE
861869
"""
862870
name = 'interval'
863-
kind = None
871+
kind = None # type: Optional[builtins.str]
864872
str = '|O08'
865873
base = np.dtype('O')
866874
num = 103
867875
_metadata = ('subtype',)
868876
_match = re.compile(r"(I|i)nterval\[(?P<subtype>.+)\]")
869-
_cache = {}
877+
_cache = {} # type: Dict[builtins.str, object]
870878

871879
def __new__(cls, subtype=None):
872880
"""

pandas/core/dtypes/missing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
"""
44
import numpy as np
55

6-
from pandas._libs import lib, missing as libmissing
6+
from pandas._libs import lib
7+
import pandas._libs.missing as libmissing
78
from pandas._libs.tslibs import NaT, iNaT
89

910
from .common import (

0 commit comments

Comments
 (0)