Skip to content

Commit f51547c

Browse files
authored
CLN,TYP Remove string return annotations (#39174)
* remove string return annotations * fixup conflict * fixup merge conflict
1 parent a3b5c49 commit f51547c

Some content is hidden

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

59 files changed

+314
-248
lines changed

.pre-commit-config.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ repos:
145145
language: pygrep
146146
types_or: [python, cython]
147147
- id: unwanted-typing
148-
name: Check for use of comment-based annotation syntax and missing error codes
148+
name: Check for outdated annotation syntax and missing error codes
149149
entry: |
150150
(?x)
151151
\#\ type:\ (?!ignore)|
152-
\#\ type:\s?ignore(?!\[)
152+
\#\ type:\s?ignore(?!\[)|
153+
\)\ ->\ \"
153154
language: pygrep
154155
types: [python]
155156
- id: np-bool

pandas/compat/pickle_compat.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""
22
Support pre-0.12 series pickle compatibility.
33
"""
4+
from __future__ import annotations
45

56
import contextlib
67
import copy
@@ -64,7 +65,7 @@ class _LoadSparseSeries:
6465
# https://github.com/python/mypy/issues/1020
6566
# error: Incompatible return type for "__new__" (returns "Series", but must return
6667
# a subtype of "_LoadSparseSeries")
67-
def __new__(cls) -> "Series": # type: ignore[misc]
68+
def __new__(cls) -> Series: # type: ignore[misc]
6869
from pandas import Series
6970

7071
warnings.warn(
@@ -82,7 +83,7 @@ class _LoadSparseFrame:
8283
# https://github.com/python/mypy/issues/1020
8384
# error: Incompatible return type for "__new__" (returns "DataFrame", but must
8485
# return a subtype of "_LoadSparseFrame")
85-
def __new__(cls) -> "DataFrame": # type: ignore[misc]
86+
def __new__(cls) -> DataFrame: # type: ignore[misc]
8687
from pandas import DataFrame
8788

8889
warnings.warn(

pandas/core/arrays/boolean.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import numbers
24
from typing import TYPE_CHECKING, List, Optional, Tuple, Type, Union
35
import warnings
@@ -93,7 +95,7 @@ def _is_numeric(self) -> bool:
9395

9496
def __from_arrow__(
9597
self, array: Union["pyarrow.Array", "pyarrow.ChunkedArray"]
96-
) -> "BooleanArray":
98+
) -> BooleanArray:
9799
"""
98100
Construct BooleanArray from pyarrow Array/ChunkedArray.
99101
"""
@@ -276,7 +278,7 @@ def dtype(self) -> BooleanDtype:
276278
@classmethod
277279
def _from_sequence(
278280
cls, scalars, *, dtype: Optional[Dtype] = None, copy: bool = False
279-
) -> "BooleanArray":
281+
) -> BooleanArray:
280282
if dtype:
281283
assert dtype == "boolean"
282284
values, mask = coerce_to_array(scalars, copy=copy)
@@ -291,7 +293,7 @@ def _from_sequence_of_strings(
291293
copy: bool = False,
292294
true_values: Optional[List[str]] = None,
293295
false_values: Optional[List[str]] = None,
294-
) -> "BooleanArray":
296+
) -> BooleanArray:
295297
true_values_union = cls._TRUE_VALUES.union(true_values or [])
296298
false_values_union = cls._FALSE_VALUES.union(false_values or [])
297299

pandas/core/arrays/categorical.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from csv import QUOTE_NONNUMERIC
24
from functools import partial
35
import operator
@@ -740,7 +742,7 @@ def _set_categories(self, categories, fastpath=False):
740742

741743
self._dtype = new_dtype
742744

743-
def _set_dtype(self, dtype: CategoricalDtype) -> "Categorical":
745+
def _set_dtype(self, dtype: CategoricalDtype) -> Categorical:
744746
"""
745747
Internal method for directly updating the CategoricalDtype
746748
@@ -1740,7 +1742,7 @@ def fillna(self, value=None, method=None, limit=None):
17401742
def _ndarray(self) -> np.ndarray:
17411743
return self._codes
17421744

1743-
def _from_backing_data(self, arr: np.ndarray) -> "Categorical":
1745+
def _from_backing_data(self, arr: np.ndarray) -> Categorical:
17441746
return self._constructor(arr, dtype=self.dtype, fastpath=True)
17451747

17461748
def _box_func(self, i: int):
@@ -2160,7 +2162,7 @@ def _concat_same_type(
21602162

21612163
# ------------------------------------------------------------------
21622164

2163-
def _encode_with_my_categories(self, other: "Categorical") -> "Categorical":
2165+
def _encode_with_my_categories(self, other: "Categorical") -> Categorical:
21642166
"""
21652167
Re-encode another categorical using this Categorical's categories.
21662168

pandas/core/arrays/datetimes.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
from datetime import datetime, time, timedelta, tzinfo
24
from typing import Optional, Union, cast
35
import warnings
@@ -291,7 +293,7 @@ def __init__(self, values, dtype=DT64NS_DTYPE, freq=None, copy=False):
291293
@classmethod
292294
def _simple_new(
293295
cls, values, freq: Optional[BaseOffset] = None, dtype=DT64NS_DTYPE
294-
) -> "DatetimeArray":
296+
) -> DatetimeArray:
295297
assert isinstance(values, np.ndarray)
296298
if values.dtype != DT64NS_DTYPE:
297299
assert values.dtype == "i8"

pandas/core/arrays/floating.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import List, Optional, Tuple, Type
24
import warnings
35

@@ -242,14 +244,14 @@ def __init__(self, values: np.ndarray, mask: np.ndarray, copy: bool = False):
242244
@classmethod
243245
def _from_sequence(
244246
cls, scalars, *, dtype=None, copy: bool = False
245-
) -> "FloatingArray":
247+
) -> FloatingArray:
246248
values, mask = coerce_to_array(scalars, dtype=dtype, copy=copy)
247249
return FloatingArray(values, mask)
248250

249251
@classmethod
250252
def _from_sequence_of_strings(
251253
cls, strings, *, dtype=None, copy: bool = False
252-
) -> "FloatingArray":
254+
) -> FloatingArray:
253255
scalars = to_numeric(strings, errors="raise")
254256
return cls._from_sequence(scalars, dtype=dtype, copy=copy)
255257

pandas/core/arrays/integer.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Dict, List, Optional, Tuple, Type
24
import warnings
35

@@ -303,14 +305,14 @@ def __abs__(self):
303305
@classmethod
304306
def _from_sequence(
305307
cls, scalars, *, dtype: Optional[Dtype] = None, copy: bool = False
306-
) -> "IntegerArray":
308+
) -> IntegerArray:
307309
values, mask = coerce_to_array(scalars, dtype=dtype, copy=copy)
308310
return IntegerArray(values, mask)
309311

310312
@classmethod
311313
def _from_sequence_of_strings(
312314
cls, strings, *, dtype: Optional[Dtype] = None, copy: bool = False
313-
) -> "IntegerArray":
315+
) -> IntegerArray:
314316
scalars = to_numeric(strings, errors="raise")
315317
return cls._from_sequence(scalars, dtype=dtype, copy=copy)
316318

pandas/core/arrays/interval.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 operator
24
from operator import le, lt
35
import textwrap
@@ -861,7 +863,7 @@ def copy(self: IntervalArrayT) -> IntervalArrayT:
861863
def isna(self) -> np.ndarray:
862864
return isna(self._left)
863865

864-
def shift(self, periods: int = 1, fill_value: object = None) -> "IntervalArray":
866+
def shift(self, periods: int = 1, fill_value: object = None) -> IntervalArray:
865867
if not len(self) or periods == 0:
866868
return self.copy()
867869

pandas/core/arrays/masked.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ def factorize(self, na_sentinel: int = -1) -> Tuple[np.ndarray, ExtensionArray]:
346346
uniques = type(self)(uniques, np.zeros(len(uniques), dtype=bool))
347347
return codes, uniques
348348

349-
def value_counts(self, dropna: bool = True) -> "Series":
349+
def value_counts(self, dropna: bool = True) -> Series:
350350
"""
351351
Returns a Series containing counts of each unique value.
352352

pandas/core/arrays/numpy_.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import numbers
24
from typing import Optional, Tuple, Type, Union
35

@@ -75,7 +77,7 @@ def _is_boolean(self) -> bool:
7577
return self.kind == "b"
7678

7779
@classmethod
78-
def construct_from_string(cls, string: str) -> "PandasDtype":
80+
def construct_from_string(cls, string: str) -> PandasDtype:
7981
try:
8082
dtype = np.dtype(string)
8183
except TypeError as err:
@@ -174,7 +176,7 @@ def __init__(self, values: Union[np.ndarray, "PandasArray"], copy: bool = False)
174176
@classmethod
175177
def _from_sequence(
176178
cls, scalars, *, dtype: Optional[Dtype] = None, copy: bool = False
177-
) -> "PandasArray":
179+
) -> PandasArray:
178180
if isinstance(dtype, PandasDtype):
179181
dtype = dtype._dtype
180182

@@ -184,10 +186,10 @@ def _from_sequence(
184186
return cls(result)
185187

186188
@classmethod
187-
def _from_factorized(cls, values, original) -> "PandasArray":
189+
def _from_factorized(cls, values, original) -> PandasArray:
188190
return cls(values)
189191

190-
def _from_backing_data(self, arr: np.ndarray) -> "PandasArray":
192+
def _from_backing_data(self, arr: np.ndarray) -> PandasArray:
191193
return type(self)(arr)
192194

193195
# ------------------------------------------------------------------------

0 commit comments

Comments
 (0)