Skip to content

Commit 0d5a644

Browse files
authored
remove string type hints (#39299)
1 parent 9e5573e commit 0d5a644

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+295
-248
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,6 @@ repos:
150150
(?x)
151151
\#\ type:\ (?!ignore)
152152
|\#\ type:\s?ignore(?!\[)
153-
|\)\ ->\ \"
154153
language: pygrep
155154
types: [python]
156155
- id: np-bool
@@ -185,3 +184,7 @@ repos:
185184
- id: codespell
186185
types_or: [python, rst, markdown]
187186
files: ^pandas/core/
187+
- repo: https://github.com/MarcoGorelli/no-string-hints
188+
rev: v0.1.5
189+
hooks:
190+
- id: no-string-hints

pandas/core/aggregation.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
kwarg aggregations in groupby and DataFrame/Series aggregation
44
"""
55

6+
from __future__ import annotations
7+
68
from collections import defaultdict
79
from functools import partial
810
from typing import (
@@ -296,7 +298,7 @@ def relabel_result(
296298
func: Dict[str, List[Union[Callable, str]]],
297299
columns: Iterable[Hashable],
298300
order: Iterable[int],
299-
) -> Dict[Hashable, "Series"]:
301+
) -> Dict[Hashable, Series]:
300302
"""
301303
Internal function to reorder result if relabelling is True for
302304
dataframe.agg, and return the reordered result in dict.
@@ -323,7 +325,7 @@ def relabel_result(
323325
reordered_indexes = [
324326
pair[0] for pair in sorted(zip(columns, order), key=lambda t: t[1])
325327
]
326-
reordered_result_in_dict: Dict[Hashable, "Series"] = {}
328+
reordered_result_in_dict: Dict[Hashable, Series] = {}
327329
idx = 0
328330

329331
reorder_mask = not isinstance(result, ABCSeries) and len(result.columns) > 1

pandas/core/algorithms.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ def factorize(
559559
sort: bool = False,
560560
na_sentinel: Optional[int] = -1,
561561
size_hint: Optional[int] = None,
562-
) -> Tuple[np.ndarray, Union[np.ndarray, "Index"]]:
562+
) -> Tuple[np.ndarray, Union[np.ndarray, Index]]:
563563
"""
564564
Encode the object as an enumerated type or categorical variable.
565565

pandas/core/arrays/boolean.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def numpy_dtype(self) -> np.dtype:
7272
return np.dtype("bool")
7373

7474
@classmethod
75-
def construct_array_type(cls) -> Type["BooleanArray"]:
75+
def construct_array_type(cls) -> Type[BooleanArray]:
7676
"""
7777
Return the array type associated with this dtype.
7878
@@ -94,7 +94,7 @@ def _is_numeric(self) -> bool:
9494
return True
9595

9696
def __from_arrow__(
97-
self, array: Union["pyarrow.Array", "pyarrow.ChunkedArray"]
97+
self, array: Union[pyarrow.Array, pyarrow.ChunkedArray]
9898
) -> BooleanArray:
9999
"""
100100
Construct BooleanArray from pyarrow Array/ChunkedArray.

pandas/core/arrays/categorical.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ def dtype(self) -> CategoricalDtype:
422422
return self._dtype
423423

424424
@property
425-
def _constructor(self) -> Type["Categorical"]:
425+
def _constructor(self) -> Type[Categorical]:
426426
return Categorical
427427

428428
@classmethod
@@ -2162,7 +2162,7 @@ def _concat_same_type(
21622162

21632163
# ------------------------------------------------------------------
21642164

2165-
def _encode_with_my_categories(self, other: "Categorical") -> Categorical:
2165+
def _encode_with_my_categories(self, other: Categorical) -> Categorical:
21662166
"""
21672167
Re-encode another categorical using this Categorical's categories.
21682168
@@ -2179,7 +2179,7 @@ def _encode_with_my_categories(self, other: "Categorical") -> Categorical:
21792179
)
21802180
return self._from_backing_data(codes)
21812181

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

25292529

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

pandas/core/arrays/floating.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def _is_numeric(self) -> bool:
4747
return True
4848

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

pandas/core/arrays/integer.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def _is_numeric(self) -> bool:
5757
return True
5858

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

pandas/core/arrays/numeric.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import datetime
24
import numbers
35
from typing import TYPE_CHECKING, Any, List, Union
@@ -25,7 +27,7 @@
2527

2628
class NumericDtype(BaseMaskedDtype):
2729
def __from_arrow__(
28-
self, array: Union["pyarrow.Array", "pyarrow.ChunkedArray"]
30+
self, array: Union[pyarrow.Array, pyarrow.ChunkedArray]
2931
) -> BaseMaskedArray:
3032
"""
3133
Construct IntegerArray/FloatingArray from pyarrow Array/ChunkedArray.

pandas/core/arrays/numpy_.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def construct_from_string(cls, string: str) -> PandasDtype:
8989
return cls(dtype)
9090

9191
@classmethod
92-
def construct_array_type(cls) -> Type["PandasArray"]:
92+
def construct_array_type(cls) -> Type[PandasArray]:
9393
"""
9494
Return the array type associated with this dtype.
9595
@@ -155,7 +155,7 @@ class PandasArray(
155155
# ------------------------------------------------------------------------
156156
# Constructors
157157

158-
def __init__(self, values: Union[np.ndarray, "PandasArray"], copy: bool = False):
158+
def __init__(self, values: Union[np.ndarray, PandasArray], copy: bool = False):
159159
if isinstance(values, type(self)):
160160
values = values._ndarray
161161
if not isinstance(values, np.ndarray):

pandas/core/arrays/period.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def _simple_new(
201201

202202
@classmethod
203203
def _from_sequence(
204-
cls: Type["PeriodArray"],
204+
cls: Type[PeriodArray],
205205
scalars: Union[Sequence[Optional[Period]], AnyArrayLike],
206206
*,
207207
dtype: Optional[Dtype] = None,

0 commit comments

Comments
 (0)