Skip to content

CLN, TYP Remove string type hints #39299

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,7 @@ repos:
entry: |
(?x)
\#\ type:\ (?!ignore)|
\#\ type:\s?ignore(?!\[)|
\)\ ->\ \"
\#\ type:\s?ignore(?!\[)
language: pygrep
types: [python]
- id: np-bool
Expand Down Expand Up @@ -185,3 +184,7 @@ repos:
- id: codespell
types_or: [python, rst, markdown]
files: ^pandas/core/
- repo: https://github.com/MarcoGorelli/no-string-hints
rev: v0.1.5
hooks:
- id: no-string-hints
6 changes: 4 additions & 2 deletions pandas/core/aggregation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
kwarg aggregations in groupby and DataFrame/Series aggregation
"""

from __future__ import annotations

from collections import defaultdict
from functools import partial
from typing import (
Expand Down Expand Up @@ -296,7 +298,7 @@ def relabel_result(
func: Dict[str, List[Union[Callable, str]]],
columns: Iterable[Hashable],
order: Iterable[int],
) -> Dict[Hashable, "Series"]:
) -> Dict[Hashable, Series]:
"""
Internal function to reorder result if relabelling is True for
dataframe.agg, and return the reordered result in dict.
Expand All @@ -323,7 +325,7 @@ def relabel_result(
reordered_indexes = [
pair[0] for pair in sorted(zip(columns, order), key=lambda t: t[1])
]
reordered_result_in_dict: Dict[Hashable, "Series"] = {}
reordered_result_in_dict: Dict[Hashable, Series] = {}
idx = 0

reorder_mask = not isinstance(result, ABCSeries) and len(result.columns) > 1
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def factorize(
sort: bool = False,
na_sentinel: Optional[int] = -1,
size_hint: Optional[int] = None,
) -> Tuple[np.ndarray, Union[np.ndarray, "Index"]]:
) -> Tuple[np.ndarray, Union[np.ndarray, Index]]:
"""
Encode the object as an enumerated type or categorical variable.

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/boolean.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def numpy_dtype(self) -> np.dtype:
return np.dtype("bool")

@classmethod
def construct_array_type(cls) -> Type["BooleanArray"]:
def construct_array_type(cls) -> Type[BooleanArray]:
"""
Return the array type associated with this dtype.

Expand All @@ -94,7 +94,7 @@ def _is_numeric(self) -> bool:
return True

def __from_arrow__(
self, array: Union["pyarrow.Array", "pyarrow.ChunkedArray"]
self, array: Union[pyarrow.Array, pyarrow.ChunkedArray]
) -> BooleanArray:
"""
Construct BooleanArray from pyarrow Array/ChunkedArray.
Expand Down
8 changes: 4 additions & 4 deletions pandas/core/arrays/categorical.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ def dtype(self) -> CategoricalDtype:
return self._dtype

@property
def _constructor(self) -> Type["Categorical"]:
def _constructor(self) -> Type[Categorical]:
return Categorical

@classmethod
Expand Down Expand Up @@ -2162,7 +2162,7 @@ def _concat_same_type(

# ------------------------------------------------------------------

def _encode_with_my_categories(self, other: "Categorical") -> Categorical:
def _encode_with_my_categories(self, other: Categorical) -> Categorical:
"""
Re-encode another categorical using this Categorical's categories.

Expand All @@ -2179,7 +2179,7 @@ def _encode_with_my_categories(self, other: "Categorical") -> Categorical:
)
return self._from_backing_data(codes)

def _categories_match_up_to_permutation(self, other: "Categorical") -> bool:
def _categories_match_up_to_permutation(self, other: Categorical) -> bool:
"""
Returns True if categoricals are the same dtype
same categories, and same ordered
Expand Down Expand Up @@ -2527,7 +2527,7 @@ def _delegate_method(self, name, *args, **kwargs):
# utility routines


def _get_codes_for_values(values, categories: "Index") -> np.ndarray:
def _get_codes_for_values(values, categories: Index) -> np.ndarray:
"""
utility routine to turn values into codes given the specified categories

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/floating.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def _is_numeric(self) -> bool:
return True

@classmethod
def construct_array_type(cls) -> Type["FloatingArray"]:
def construct_array_type(cls) -> Type[FloatingArray]:
"""
Return the array type associated with this dtype.

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/integer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def _is_numeric(self) -> bool:
return True

@classmethod
def construct_array_type(cls) -> Type["IntegerArray"]:
def construct_array_type(cls) -> Type[IntegerArray]:
"""
Return the array type associated with this dtype.

Expand Down
4 changes: 3 additions & 1 deletion pandas/core/arrays/numeric.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import annotations

import datetime
import numbers
from typing import TYPE_CHECKING, Any, List, Union
Expand Down Expand Up @@ -25,7 +27,7 @@

class NumericDtype(BaseMaskedDtype):
def __from_arrow__(
self, array: Union["pyarrow.Array", "pyarrow.ChunkedArray"]
self, array: Union[pyarrow.Array, pyarrow.ChunkedArray]
) -> BaseMaskedArray:
"""
Construct IntegerArray/FloatingArray from pyarrow Array/ChunkedArray.
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/numpy_.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def construct_from_string(cls, string: str) -> PandasDtype:
return cls(dtype)

@classmethod
def construct_array_type(cls) -> Type["PandasArray"]:
def construct_array_type(cls) -> Type[PandasArray]:
"""
Return the array type associated with this dtype.

Expand Down Expand Up @@ -155,7 +155,7 @@ class PandasArray(
# ------------------------------------------------------------------------
# Constructors

def __init__(self, values: Union[np.ndarray, "PandasArray"], copy: bool = False):
def __init__(self, values: Union[np.ndarray, PandasArray], copy: bool = False):
if isinstance(values, type(self)):
values = values._ndarray
if not isinstance(values, np.ndarray):
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def _simple_new(

@classmethod
def _from_sequence(
cls: Type["PeriodArray"],
cls: Type[PeriodArray],
scalars: Union[Sequence[Optional[Period]], AnyArrayLike],
*,
dtype: Optional[Dtype] = None,
Expand Down
6 changes: 3 additions & 3 deletions pandas/core/arrays/sparse/array.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
_sparray_doc_kwargs = {"klass": "SparseArray"}


def _get_fill(arr: "SparseArray") -> np.ndarray:
def _get_fill(arr: SparseArray) -> np.ndarray:
"""
Create a 0-dim ndarray containing the fill value

Expand All @@ -87,7 +87,7 @@ def _get_fill(arr: "SparseArray") -> np.ndarray:


def _sparse_array_op(
left: "SparseArray", right: "SparseArray", op: Callable, name: str
left: SparseArray, right: SparseArray, op: Callable, name: str
) -> Any:
"""
Perform a binary operation between two arrays.
Expand Down Expand Up @@ -896,7 +896,7 @@ def _take_with_fill(self, indices, fill_value=None) -> np.ndarray:

return taken

def _take_without_fill(self, indices) -> Union[np.ndarray, "SparseArray"]:
def _take_without_fill(self, indices) -> Union[np.ndarray, SparseArray]:
to_shift = indices < 0
indices = indices.copy()

Expand Down
2 changes: 1 addition & 1 deletion pandas/core/arrays/sparse/dtype.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def __repr__(self) -> str:
return self.name

@classmethod
def construct_array_type(cls) -> Type["SparseArray"]:
def construct_array_type(cls) -> Type[SparseArray]:
"""
Return the array type associated with this dtype.

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/string_.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def type(self) -> Type[str]:
return str

@classmethod
def construct_array_type(cls) -> Type["StringArray"]:
def construct_array_type(cls) -> Type[StringArray]:
"""
Return the array type associated with this dtype.

Expand All @@ -85,7 +85,7 @@ def __repr__(self) -> str:
return "StringDtype"

def __from_arrow__(
self, array: Union["pyarrow.Array", "pyarrow.ChunkedArray"]
self, array: Union[pyarrow.Array, pyarrow.ChunkedArray]
) -> StringArray:
"""
Construct StringArray from pyarrow Array/ChunkedArray.
Expand Down
4 changes: 2 additions & 2 deletions pandas/core/arrays/string_arrow.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def type(self) -> Type[str]:
return str

@classmethod
def construct_array_type(cls) -> Type["ArrowStringArray"]:
def construct_array_type(cls) -> Type[ArrowStringArray]:
"""
Return the array type associated with this dtype.

Expand All @@ -104,7 +104,7 @@ def __repr__(self) -> str:
return "ArrowStringDtype"

def __from_arrow__(
self, array: Union["pa.Array", "pa.ChunkedArray"]
self, array: Union[pa.Array, pa.ChunkedArray]
) -> ArrowStringArray:
"""
Construct StringArray from pyarrow Array/ChunkedArray.
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/computation/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Operator classes for eval.
"""

from __future__ import annotations

from datetime import datetime
from distutils.version import LooseVersion
from functools import partial
Expand Down Expand Up @@ -203,7 +205,7 @@ class Op:

op: str

def __init__(self, op: str, operands: Iterable[Union[Term, "Op"]], encoding=None):
def __init__(self, op: str, operands: Iterable[Union[Term, Op]], encoding=None):
self.op = _bool_op_map.get(op, op)
self.operands = operands
self.encoding = encoding
Expand Down
20 changes: 10 additions & 10 deletions pandas/core/describe.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class NDFrameDescriberAbstract(ABC):
Whether to treat datetime dtypes as numeric.
"""

def __init__(self, obj: "FrameOrSeriesUnion", datetime_is_numeric: bool):
def __init__(self, obj: FrameOrSeriesUnion, datetime_is_numeric: bool):
self.obj = obj
self.datetime_is_numeric = datetime_is_numeric

Expand All @@ -110,7 +110,7 @@ def describe(self, percentiles: Sequence[float]) -> FrameOrSeriesUnion:
class SeriesDescriber(NDFrameDescriberAbstract):
"""Class responsible for creating series description."""

obj: "Series"
obj: Series

def describe(self, percentiles: Sequence[float]) -> Series:
describe_func = select_describe_func(
Expand All @@ -137,7 +137,7 @@ class DataFrameDescriber(NDFrameDescriberAbstract):

def __init__(
self,
obj: "DataFrame",
obj: DataFrame,
*,
include: Optional[Union[str, Sequence[str]]],
exclude: Optional[Union[str, Sequence[str]]],
Expand All @@ -154,7 +154,7 @@ def __init__(
def describe(self, percentiles: Sequence[float]) -> DataFrame:
data = self._select_data()

ldesc: List["Series"] = []
ldesc: List[Series] = []
for _, series in data.items():
describe_func = select_describe_func(series, self.datetime_is_numeric)
ldesc.append(describe_func(series, percentiles))
Expand Down Expand Up @@ -191,7 +191,7 @@ def _select_data(self):
return data


def reorder_columns(ldesc: Sequence["Series"]) -> List[Hashable]:
def reorder_columns(ldesc: Sequence[Series]) -> List[Hashable]:
"""Set a convenient order for rows for display."""
names: List[Hashable] = []
ldesc_indexes = sorted((x.index for x in ldesc), key=len)
Expand All @@ -202,7 +202,7 @@ def reorder_columns(ldesc: Sequence["Series"]) -> List[Hashable]:
return names


def describe_numeric_1d(series: "Series", percentiles: Sequence[float]) -> Series:
def describe_numeric_1d(series: Series, percentiles: Sequence[float]) -> Series:
"""Describe series containing numerical data.

Parameters
Expand All @@ -226,7 +226,7 @@ def describe_numeric_1d(series: "Series", percentiles: Sequence[float]) -> Serie


def describe_categorical_1d(
data: "Series",
data: Series,
percentiles_ignored: Sequence[float],
) -> Series:
"""Describe series containing categorical data.
Expand Down Expand Up @@ -258,7 +258,7 @@ def describe_categorical_1d(


def describe_timestamp_as_categorical_1d(
data: "Series",
data: Series,
percentiles_ignored: Sequence[float],
) -> Series:
"""Describe series containing timestamp data treated as categorical.
Expand Down Expand Up @@ -305,7 +305,7 @@ def describe_timestamp_as_categorical_1d(
return Series(result, index=names, name=data.name, dtype=dtype)


def describe_timestamp_1d(data: "Series", percentiles: Sequence[float]) -> Series:
def describe_timestamp_1d(data: Series, percentiles: Sequence[float]) -> Series:
"""Describe series containing datetime64 dtype.

Parameters
Expand All @@ -330,7 +330,7 @@ def describe_timestamp_1d(data: "Series", percentiles: Sequence[float]) -> Serie


def select_describe_func(
data: "Series",
data: Series,
datetime_is_numeric: bool,
) -> Callable:
"""Select proper function for describing series based on data type.
Expand Down
4 changes: 3 additions & 1 deletion pandas/core/dtypes/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Extend pandas with custom array types.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Type, Union

import numpy as np
Expand Down Expand Up @@ -186,7 +188,7 @@ def names(self) -> Optional[List[str]]:
return None

@classmethod
def construct_array_type(cls) -> Type["ExtensionArray"]:
def construct_array_type(cls) -> Type[ExtensionArray]:
"""
Return the array type associated with this dtype.

Expand Down
4 changes: 2 additions & 2 deletions pandas/core/dtypes/cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ def trans(x):


def maybe_cast_result(
result: ArrayLike, obj: "Series", numeric_only: bool = False, how: str = ""
result: ArrayLike, obj: Series, numeric_only: bool = False, how: str = ""
) -> ArrayLike:
"""
Try casting result to a different type if appropriate
Expand Down Expand Up @@ -397,7 +397,7 @@ def maybe_cast_result_dtype(dtype: DtypeObj, how: str) -> DtypeObj:


def maybe_cast_to_extension_array(
cls: Type["ExtensionArray"], obj: ArrayLike, dtype: Optional[ExtensionDtype] = None
cls: Type[ExtensionArray], obj: ArrayLike, dtype: Optional[ExtensionDtype] = None
) -> ArrayLike:
"""
Call to `_from_sequence` that returns the object unchanged on Exception.
Expand Down
Loading