Skip to content

Commit 2792705

Browse files
gwromejreback
authored andcommitted
Update type hints to python3 style (non-array files) (#25802)
1 parent d95b306 commit 2792705

File tree

8 files changed

+31
-38
lines changed

8 files changed

+31
-38
lines changed

pandas/core/base.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -786,8 +786,7 @@ def base(self):
786786
return self.values.base
787787

788788
@property
789-
def array(self):
790-
# type: () -> ExtensionArray
789+
def array(self) -> ExtensionArray:
791790
"""
792791
The ExtensionArray of the data backing this Series or Index.
793792
@@ -962,8 +961,7 @@ def to_numpy(self, dtype=None, copy=False):
962961
return result
963962

964963
@property
965-
def _ndarray_values(self):
966-
# type: () -> np.ndarray
964+
def _ndarray_values(self) -> np.ndarray:
967965
"""
968966
The data as an ndarray, possibly losing information.
969967

pandas/core/common.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,7 @@ def maybe_box_datetimelike(value):
9393
values_from_object = lib.values_from_object
9494

9595

96-
def is_bool_indexer(key):
97-
# type: (Any) -> bool
96+
def is_bool_indexer(key: Any) -> bool:
9897
"""
9998
Check whether `key` is a valid boolean indexer.
10099

pandas/core/dtypes/base.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,7 @@ def __ne__(self, other):
6363
return not self.__eq__(other)
6464

6565
@property
66-
def names(self):
67-
# type: () -> Optional[List[str]]
66+
def names(self) -> Optional[List[str]]:
6867
"""Ordered list of field names, or None if there are no fields.
6968
7069
This is for compatibility with NumPy arrays, and may be removed in the
@@ -114,8 +113,7 @@ def is_dtype(cls, dtype):
114113
return False
115114

116115
@property
117-
def _is_numeric(self):
118-
# type: () -> bool
116+
def _is_numeric(self) -> bool:
119117
"""
120118
Whether columns with this dtype should be considered numeric.
121119
@@ -126,8 +124,7 @@ def _is_numeric(self):
126124
return False
127125

128126
@property
129-
def _is_boolean(self):
130-
# type: () -> bool
127+
def _is_boolean(self) -> bool:
131128
"""
132129
Whether this dtype should be considered boolean.
133130
@@ -210,8 +207,7 @@ def __str__(self):
210207
return self.name
211208

212209
@property
213-
def type(self):
214-
# type: () -> Type
210+
def type(self) -> Type:
215211
"""
216212
The scalar type for the array, e.g. ``int``
217213
@@ -240,8 +236,7 @@ def kind(self):
240236
return 'O'
241237

242238
@property
243-
def name(self):
244-
# type: () -> str
239+
def name(self) -> str:
245240
"""
246241
A string identifying the data type.
247242

pandas/core/frame.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import sys
1818
import warnings
1919
from textwrap import dedent
20-
from typing import List, Union
20+
from typing import List, Optional, Union
2121

2222
import numpy as np
2323
import numpy.ma as ma
@@ -71,7 +71,8 @@
7171
is_iterator,
7272
is_sequence,
7373
is_named_tuple)
74-
from pandas.core.dtypes.generic import ABCSeries, ABCIndexClass, ABCMultiIndex
74+
from pandas.core.dtypes.generic import (
75+
ABCSeries, ABCDataFrame, ABCIndexClass, ABCMultiIndex)
7576
from pandas.core.dtypes.missing import isna, notna
7677

7778
from pandas.core import algorithms
@@ -282,6 +283,7 @@
282283
Index(['value'], dtype='object')
283284
"""
284285

286+
285287
# -----------------------------------------------------------------------
286288
# DataFrame class
287289

@@ -6239,11 +6241,10 @@ def diff(self, periods=1, axis=0):
62396241
# Function application
62406242

62416243
def _gotitem(self,
6242-
key, # type: Union[str, List[str]]
6243-
ndim, # type: int
6244-
subset=None # type: Union[Series, DataFrame, None]
6245-
):
6246-
# type: (...) -> Union[Series, DataFrame]
6244+
key: Union[str, List[str]],
6245+
ndim: int,
6246+
subset: Optional[Union[Series, ABCDataFrame]] = None,
6247+
) -> Union[Series, ABCDataFrame]:
62476248
"""
62486249
Sub-classes to define. Return a sliced object.
62496250

pandas/core/groupby/groupby.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class providing the base-class of operations.
1212
import datetime
1313
from functools import partial, wraps
1414
import types
15-
from typing import Optional, Type
15+
from typing import Optional, Tuple, Type
1616
import warnings
1717

1818
import numpy as np
@@ -1041,17 +1041,15 @@ def _bool_agg(self, val_test, skipna):
10411041
Shared func to call any / all Cython GroupBy implementations.
10421042
"""
10431043

1044-
def objs_to_bool(vals):
1045-
# type: (np.ndarray) -> (np.ndarray, Type)
1044+
def objs_to_bool(vals: np.ndarray) -> Tuple[np.ndarray, Type]:
10461045
if is_object_dtype(vals):
10471046
vals = np.array([bool(x) for x in vals])
10481047
else:
10491048
vals = vals.astype(np.bool)
10501049

10511050
return vals.view(np.uint8), np.bool
10521051

1053-
def result_to_bool(result, inference):
1054-
# type: (np.ndarray, Type) -> np.ndarray
1052+
def result_to_bool(result: np.ndarray, inference: Type) -> np.ndarray:
10551053
return result.astype(inference, copy=False)
10561054

10571055
return self._get_cythonized_result('group_any_all', self.grouper,
@@ -1739,8 +1737,9 @@ def quantile(self, q=0.5, interpolation='linear'):
17391737
b 3.0
17401738
"""
17411739

1742-
def pre_processor(vals):
1743-
# type: (np.ndarray) -> (np.ndarray, Optional[Type])
1740+
def pre_processor(
1741+
vals: np.ndarray
1742+
) -> Tuple[np.ndarray, Optional[Type]]:
17441743
if is_object_dtype(vals):
17451744
raise TypeError("'quantile' cannot be performed against "
17461745
"'object' dtypes!")
@@ -1754,8 +1753,10 @@ def pre_processor(vals):
17541753

17551754
return vals, inference
17561755

1757-
def post_processor(vals, inference):
1758-
# type: (np.ndarray, Optional[Type]) -> np.ndarray
1756+
def post_processor(
1757+
vals: np.ndarray,
1758+
inference: Optional[Type]
1759+
) -> np.ndarray:
17591760
if inference:
17601761
# Check for edge case
17611762
if not (is_integer_dtype(inference) and

pandas/core/indexes/base.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3630,8 +3630,7 @@ def values(self):
36303630
return self._data.view(np.ndarray)
36313631

36323632
@property
3633-
def _values(self):
3634-
# type: () -> Union[ExtensionArray, Index, np.ndarray]
3633+
def _values(self) -> Union[ExtensionArray, ABCIndexClass, np.ndarray]:
36353634
# TODO(EA): remove index types as they become extension arrays
36363635
"""
36373636
The best array representation.

pandas/core/indexes/datetimelike.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,7 @@ def _ndarray_values(self):
130130
# Abstract data attributes
131131

132132
@property
133-
def values(self):
134-
# type: () -> np.ndarray
133+
def values(self) -> np.ndarray:
135134
# Note: PeriodArray overrides this to return an ndarray of objects.
136135
return self._data._data
137136

pandas/core/internals/managers.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1862,8 +1862,9 @@ def _shape_compat(x):
18621862
return stacked, placement
18631863

18641864

1865-
def _interleaved_dtype(blocks):
1866-
# type: (List[Block]) -> Optional[Union[np.dtype, ExtensionDtype]]
1865+
def _interleaved_dtype(
1866+
blocks: List[Block]
1867+
) -> Optional[Union[np.dtype, ExtensionDtype]]:
18671868
"""Find the common dtype for `blocks`.
18681869
18691870
Parameters

0 commit comments

Comments
 (0)