diff --git a/pandas/core/base.py b/pandas/core/base.py index 5adf01a62352c..5a0fb02494236 100644 --- a/pandas/core/base.py +++ b/pandas/core/base.py @@ -786,8 +786,7 @@ def base(self): return self.values.base @property - def array(self): - # type: () -> ExtensionArray + def array(self) -> ExtensionArray: """ The ExtensionArray of the data backing this Series or Index. @@ -962,8 +961,7 @@ def to_numpy(self, dtype=None, copy=False): return result @property - def _ndarray_values(self): - # type: () -> np.ndarray + def _ndarray_values(self) -> np.ndarray: """ The data as an ndarray, possibly losing information. diff --git a/pandas/core/common.py b/pandas/core/common.py index 77b7b94e7a1f7..43c9aea0e0a0e 100644 --- a/pandas/core/common.py +++ b/pandas/core/common.py @@ -93,8 +93,7 @@ def maybe_box_datetimelike(value): values_from_object = lib.values_from_object -def is_bool_indexer(key): - # type: (Any) -> bool +def is_bool_indexer(key: Any) -> bool: """ Check whether `key` is a valid boolean indexer. diff --git a/pandas/core/dtypes/base.py b/pandas/core/dtypes/base.py index 8269f8c88ffd3..3ec49a4cdf331 100644 --- a/pandas/core/dtypes/base.py +++ b/pandas/core/dtypes/base.py @@ -65,8 +65,7 @@ def __ne__(self, other): return not self.__eq__(other) @property - def names(self): - # type: () -> Optional[List[str]] + def names(self) -> Optional[List[str]]: """Ordered list of field names, or None if there are no fields. This is for compatibility with NumPy arrays, and may be removed in the @@ -116,8 +115,7 @@ def is_dtype(cls, dtype): return False @property - def _is_numeric(self): - # type: () -> bool + def _is_numeric(self) -> bool: """ Whether columns with this dtype should be considered numeric. @@ -128,8 +126,7 @@ def _is_numeric(self): return False @property - def _is_boolean(self): - # type: () -> bool + def _is_boolean(self) -> bool: """ Whether this dtype should be considered boolean. @@ -212,8 +209,7 @@ def __str__(self): return self.name @property - def type(self): - # type: () -> Type + def type(self) -> Type: """ The scalar type for the array, e.g. ``int`` @@ -242,8 +238,7 @@ def kind(self): return 'O' @property - def name(self): - # type: () -> str + def name(self) -> str: """ A string identifying the data type. diff --git a/pandas/core/frame.py b/pandas/core/frame.py index 92db102543c43..ec6af0ae2d907 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -19,7 +19,7 @@ import sys import warnings from textwrap import dedent -from typing import List, Union +from typing import List, Optional, Union import numpy as np import numpy.ma as ma @@ -74,7 +74,8 @@ is_iterator, is_sequence, is_named_tuple) -from pandas.core.dtypes.generic import ABCSeries, ABCIndexClass, ABCMultiIndex +from pandas.core.dtypes.generic import ( + ABCSeries, ABCDataFrame, ABCIndexClass, ABCMultiIndex) from pandas.core.dtypes.missing import isna, notna from pandas.core import algorithms @@ -285,6 +286,7 @@ Index(['value'], dtype='object') """ + # ----------------------------------------------------------------------- # DataFrame class @@ -6244,11 +6246,10 @@ def diff(self, periods=1, axis=0): # Function application def _gotitem(self, - key, # type: Union[str, List[str]] - ndim, # type: int - subset=None # type: Union[Series, DataFrame, None] - ): - # type: (...) -> Union[Series, DataFrame] + key: Union[str, List[str]], + ndim: int, + subset: Optional[Union[Series, ABCDataFrame]] = None, + ) -> Union[Series, ABCDataFrame]: """ Sub-classes to define. Return a sliced object. diff --git a/pandas/core/groupby/groupby.py b/pandas/core/groupby/groupby.py index 3d9431596ea60..2494cf55d2e0d 100644 --- a/pandas/core/groupby/groupby.py +++ b/pandas/core/groupby/groupby.py @@ -12,7 +12,7 @@ class providing the base-class of operations. import datetime from functools import partial, wraps import types -from typing import Optional, Type +from typing import Optional, Tuple, Type import warnings import numpy as np @@ -1041,8 +1041,7 @@ def _bool_agg(self, val_test, skipna): Shared func to call any / all Cython GroupBy implementations. """ - def objs_to_bool(vals): - # type: (np.ndarray) -> (np.ndarray, Type) + def objs_to_bool(vals: np.ndarray) -> Tuple[np.ndarray, Type]: if is_object_dtype(vals): vals = np.array([bool(x) for x in vals]) else: @@ -1050,8 +1049,7 @@ def objs_to_bool(vals): return vals.view(np.uint8), np.bool - def result_to_bool(result, inference): - # type: (np.ndarray, Type) -> np.ndarray + def result_to_bool(result: np.ndarray, inference: Type) -> np.ndarray: return result.astype(inference, copy=False) return self._get_cythonized_result('group_any_all', self.grouper, @@ -1739,8 +1737,9 @@ def quantile(self, q=0.5, interpolation='linear'): b 3.0 """ - def pre_processor(vals): - # type: (np.ndarray) -> (np.ndarray, Optional[Type]) + def pre_processor( + vals: np.ndarray + ) -> Tuple[np.ndarray, Optional[Type]]: if is_object_dtype(vals): raise TypeError("'quantile' cannot be performed against " "'object' dtypes!") @@ -1754,8 +1753,10 @@ def pre_processor(vals): return vals, inference - def post_processor(vals, inference): - # type: (np.ndarray, Optional[Type]) -> np.ndarray + def post_processor( + vals: np.ndarray, + inference: Optional[Type] + ) -> np.ndarray: if inference: # Check for edge case if not (is_integer_dtype(inference) and diff --git a/pandas/core/indexes/base.py b/pandas/core/indexes/base.py index 68bbe0f26784d..fdb2ebd39a99e 100644 --- a/pandas/core/indexes/base.py +++ b/pandas/core/indexes/base.py @@ -3632,8 +3632,7 @@ def values(self): return self._data.view(np.ndarray) @property - def _values(self): - # type: () -> Union[ExtensionArray, Index, np.ndarray] + def _values(self) -> Union[ExtensionArray, ABCIndexClass, np.ndarray]: # TODO(EA): remove index types as they become extension arrays """ The best array representation. diff --git a/pandas/core/indexes/datetimelike.py b/pandas/core/indexes/datetimelike.py index da4e7040097a2..197fbc2c22927 100644 --- a/pandas/core/indexes/datetimelike.py +++ b/pandas/core/indexes/datetimelike.py @@ -130,8 +130,7 @@ def _ndarray_values(self): # Abstract data attributes @property - def values(self): - # type: () -> np.ndarray + def values(self) -> np.ndarray: # Note: PeriodArray overrides this to return an ndarray of objects. return self._data._data diff --git a/pandas/core/internals/managers.py b/pandas/core/internals/managers.py index be2b56881db71..49fcb572e963b 100644 --- a/pandas/core/internals/managers.py +++ b/pandas/core/internals/managers.py @@ -1862,8 +1862,9 @@ def _shape_compat(x): return stacked, placement -def _interleaved_dtype(blocks): - # type: (List[Block]) -> Optional[Union[np.dtype, ExtensionDtype]] +def _interleaved_dtype( + blocks: List[Block] +) -> Optional[Union[np.dtype, ExtensionDtype]]: """Find the common dtype for `blocks`. Parameters