Skip to content

Commit f51547c

Browse files
authored
CLN,TYP Remove string return annotations (pandas-dev#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

+3-2
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

+3-2
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

+5-3
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

+5-3
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

+3-1
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

+4-2
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

+4-2
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

+3-1
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

+1-1
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

+6-4
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
# ------------------------------------------------------------------------

pandas/core/arrays/period.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from datetime import timedelta
24
import operator
35
from typing import Any, Callable, List, Optional, Sequence, Type, Union
@@ -191,7 +193,7 @@ def _simple_new(
191193
values: np.ndarray,
192194
freq: Optional[BaseOffset] = None,
193195
dtype: Optional[Dtype] = None,
194-
) -> "PeriodArray":
196+
) -> PeriodArray:
195197
# alias for PeriodArray.__init__
196198
assertion_msg = "Should be numpy array of type i8"
197199
assert isinstance(values, np.ndarray) and values.dtype == "i8", assertion_msg
@@ -204,7 +206,7 @@ def _from_sequence(
204206
*,
205207
dtype: Optional[Dtype] = None,
206208
copy: bool = False,
207-
) -> "PeriodArray":
209+
) -> PeriodArray:
208210
if dtype and isinstance(dtype, PeriodDtype):
209211
freq = dtype.freq
210212
else:
@@ -225,11 +227,11 @@ def _from_sequence(
225227
@classmethod
226228
def _from_sequence_of_strings(
227229
cls, strings, *, dtype: Optional[Dtype] = None, copy=False
228-
) -> "PeriodArray":
230+
) -> PeriodArray:
229231
return cls._from_sequence(strings, dtype=dtype, copy=copy)
230232

231233
@classmethod
232-
def _from_datetime64(cls, data, freq, tz=None) -> "PeriodArray":
234+
def _from_datetime64(cls, data, freq, tz=None) -> PeriodArray:
233235
"""
234236
Construct a PeriodArray from a datetime64 array
235237
@@ -504,7 +506,7 @@ def _box_func(self, x) -> Union[Period, NaTType]:
504506
return Period._from_ordinal(ordinal=x, freq=self.freq)
505507

506508
@doc(**_shared_doc_kwargs, other="PeriodIndex", other_name="PeriodIndex")
507-
def asfreq(self, freq=None, how: str = "E") -> "PeriodArray":
509+
def asfreq(self, freq=None, how: str = "E") -> PeriodArray:
508510
"""
509511
Convert the {klass} to the specified frequency `freq`.
510512
@@ -675,7 +677,7 @@ def _sub_period_array(self, other):
675677

676678
def _addsub_int_array(
677679
self, other: np.ndarray, op: Callable[[Any, Any], Any]
678-
) -> "PeriodArray":
680+
) -> PeriodArray:
679681
"""
680682
Add or subtract array of integers; equivalent to applying
681683
`_time_shift` pointwise.

pandas/core/arrays/sparse/array.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
"""
22
SparseArray data structure
33
"""
4+
from __future__ import annotations
5+
46
from collections import abc
57
import numbers
68
import operator
@@ -812,7 +814,7 @@ def _get_val_at(self, loc):
812814
val = maybe_box_datetimelike(val, self.sp_values.dtype)
813815
return val
814816

815-
def take(self, indices, *, allow_fill=False, fill_value=None) -> "SparseArray":
817+
def take(self, indices, *, allow_fill=False, fill_value=None) -> SparseArray:
816818
if is_scalar(indices):
817819
raise ValueError(f"'indices' must be an array, not a scalar '{indices}'.")
818820
indices = np.asarray(indices, dtype=np.int32)
@@ -1403,7 +1405,7 @@ def _arith_method(self, other, op):
14031405
other = SparseArray(other, fill_value=self.fill_value, dtype=dtype)
14041406
return _sparse_array_op(self, other, op, op_name)
14051407

1406-
def _cmp_method(self, other, op) -> "SparseArray":
1408+
def _cmp_method(self, other, op) -> SparseArray:
14071409
if not is_scalar(other) and not isinstance(other, type(self)):
14081410
# convert list-like to ndarray
14091411
other = np.asarray(other)
@@ -1431,19 +1433,19 @@ def _cmp_method(self, other, op) -> "SparseArray":
14311433

14321434
_logical_method = _cmp_method
14331435

1434-
def _unary_method(self, op) -> "SparseArray":
1436+
def _unary_method(self, op) -> SparseArray:
14351437
fill_value = op(np.array(self.fill_value)).item()
14361438
values = op(self.sp_values)
14371439
dtype = SparseDtype(values.dtype, fill_value)
14381440
return type(self)._simple_new(values, self.sp_index, dtype)
14391441

1440-
def __pos__(self) -> "SparseArray":
1442+
def __pos__(self) -> SparseArray:
14411443
return self._unary_method(operator.pos)
14421444

1443-
def __neg__(self) -> "SparseArray":
1445+
def __neg__(self) -> SparseArray:
14441446
return self._unary_method(operator.neg)
14451447

1446-
def __invert__(self) -> "SparseArray":
1448+
def __invert__(self) -> SparseArray:
14471449
return self._unary_method(operator.invert)
14481450

14491451
# ----------

pandas/core/arrays/sparse/dtype.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Sparse Dtype"""
2+
from __future__ import annotations
23

34
import re
45
from typing import TYPE_CHECKING, Any, List, Optional, Tuple, Type
@@ -185,7 +186,7 @@ def construct_array_type(cls) -> Type["SparseArray"]:
185186
return SparseArray
186187

187188
@classmethod
188-
def construct_from_string(cls, string: str) -> "SparseDtype":
189+
def construct_from_string(cls, string: str) -> SparseDtype:
189190
"""
190191
Construct a SparseDtype from a string form.
191192

pandas/core/arrays/string_.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import TYPE_CHECKING, Optional, Type, Union
24

35
import numpy as np
@@ -84,7 +86,7 @@ def __repr__(self) -> str:
8486

8587
def __from_arrow__(
8688
self, array: Union["pyarrow.Array", "pyarrow.ChunkedArray"]
87-
) -> "StringArray":
89+
) -> StringArray:
8890
"""
8991
Construct StringArray from pyarrow Array/ChunkedArray.
9092
"""

pandas/core/arrays/string_arrow.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __repr__(self) -> str:
105105

106106
def __from_arrow__(
107107
self, array: Union["pa.Array", "pa.ChunkedArray"]
108-
) -> "ArrowStringArray":
108+
) -> ArrowStringArray:
109109
"""
110110
Construct StringArray from pyarrow Array/ChunkedArray.
111111
"""
@@ -507,7 +507,7 @@ def __setitem__(self, key: Union[int, np.ndarray], value: Any) -> None:
507507

508508
def take(
509509
self, indices: Sequence[int], allow_fill: bool = False, fill_value: Any = None
510-
) -> "ExtensionArray":
510+
) -> ExtensionArray:
511511
"""
512512
Take elements from an array.
513513

0 commit comments

Comments
 (0)