Skip to content

Commit 625490b

Browse files
committed
annotate-imprecise-magics
1 parent 0794249 commit 625490b

23 files changed

+48
-25
lines changed

pandas/conftest.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@
2929
from decimal import Decimal
3030
import operator
3131
import os
32-
from typing import Callable
32+
from typing import (
33+
Callable,
34+
Iterator,
35+
)
3336

3437
from dateutil.tz import (
3538
tzlocal,
@@ -512,7 +515,7 @@ def __init__(self, underlying_dict) -> None:
512515
def __getitem__(self, key):
513516
return self._data.__getitem__(key)
514517

515-
def __iter__(self):
518+
def __iter__(self) -> Iterator:
516519
return self._data.__iter__()
517520

518521
def __len__(self) -> int:

pandas/core/arrays/categorical.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from typing import (
99
TYPE_CHECKING,
1010
Hashable,
11+
Iterator,
1112
Literal,
1213
Sequence,
1314
TypeVar,
@@ -2093,7 +2094,7 @@ def take_nd(
20932094
)
20942095
return self.take(indexer, allow_fill=allow_fill, fill_value=fill_value)
20952096

2096-
def __iter__(self):
2097+
def __iter__(self) -> Iterator:
20972098
"""
20982099
Returns an Iterator over the values of this Categorical.
20992100
"""

pandas/core/arrays/datetimelike.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
TYPE_CHECKING,
1111
Any,
1212
Callable,
13+
Iterator,
1314
Literal,
1415
Sequence,
1516
TypeVar,
@@ -287,7 +288,7 @@ def _box_values(self, values) -> np.ndarray:
287288
"""
288289
return lib.map_infer(values, self._box_func, convert=False)
289290

290-
def __iter__(self):
291+
def __iter__(self) -> Iterator:
291292
if self.ndim > 1:
292293
return (self[n] for n in range(len(self)))
293294
else:

pandas/core/arrays/datetimes.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import inspect
1010
from typing import (
1111
TYPE_CHECKING,
12+
Iterator,
1213
Literal,
1314
cast,
1415
)
@@ -567,7 +568,7 @@ def __array__(self, dtype=None) -> np.ndarray:
567568

568569
return super().__array__(dtype=dtype)
569570

570-
def __iter__(self):
571+
def __iter__(self) -> Iterator:
571572
"""
572573
Return an iterator over the boxed values
573574

pandas/core/arrays/interval.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import textwrap
99
from typing import (
1010
TYPE_CHECKING,
11+
Iterator,
1112
Literal,
1213
Sequence,
1314
TypeVar,
@@ -652,7 +653,7 @@ def size(self) -> int:
652653
# ---------------------------------------------------------------------
653654
# EA Interface
654655

655-
def __iter__(self):
656+
def __iter__(self) -> Iterator:
656657
return iter(np.asarray(self))
657658

658659
def __len__(self) -> int:

pandas/core/arrays/masked.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from typing import (
44
TYPE_CHECKING,
55
Any,
6+
Iterator,
67
Literal,
78
Sequence,
89
TypeVar,
@@ -239,7 +240,7 @@ def __setitem__(self, key, value) -> None:
239240
self._data[key] = value
240241
self._mask[key] = mask
241242

242-
def __iter__(self):
243+
def __iter__(self) -> Iterator:
243244
if self.ndim == 1:
244245
for i in range(len(self)):
245246
if self._mask[i]:

pandas/core/arrays/timedeltas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from datetime import timedelta
44
from typing import (
55
TYPE_CHECKING,
6+
Iterator,
67
cast,
78
)
89

@@ -304,7 +305,7 @@ def astype(self, dtype, copy: bool = True):
304305

305306
return dtl.DatetimeLikeArrayMixin.astype(self, dtype, copy=copy)
306307

307-
def __iter__(self):
308+
def __iter__(self) -> Iterator:
308309
if self.ndim > 1:
309310
for i in range(len(self)):
310311
yield self[i]

pandas/core/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
Any,
1212
Generic,
1313
Hashable,
14+
Iterator,
1415
Literal,
1516
TypeVar,
1617
cast,
@@ -739,7 +740,7 @@ def tolist(self):
739740

740741
to_list = tolist
741742

742-
def __iter__(self):
743+
def __iter__(self) -> Iterator:
743744
"""
744745
Return an iterator of the values.
745746

pandas/core/computation/ops.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from typing import (
1111
Callable,
1212
Iterable,
13+
Iterator,
1314
Literal,
1415
)
1516

@@ -214,7 +215,7 @@ def __init__(self, op: str, operands: Iterable[Term | Op], encoding=None) -> Non
214215
self.operands = operands
215216
self.encoding = encoding
216217

217-
def __iter__(self):
218+
def __iter__(self) -> Iterator:
218219
return iter(self.operands)
219220

220221
def __repr__(self) -> str:

pandas/core/generic.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
Callable,
1717
ClassVar,
1818
Hashable,
19+
Iterator,
1920
Literal,
2021
Mapping,
2122
NoReturn,
@@ -1951,7 +1952,7 @@ def _drop_labels_or_levels(self, keys, axis: int = 0):
19511952
# "object" defined the type as "Callable[[object], int]")
19521953
__hash__: ClassVar[None] # type: ignore[assignment]
19531954

1954-
def __iter__(self):
1955+
def __iter__(self) -> Iterator:
19551956
"""
19561957
Iterate over info axis.
19571958

pandas/core/groupby/grouper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
TYPE_CHECKING,
1010
Any,
1111
Hashable,
12+
Iterator,
1213
final,
1314
)
1415
import warnings
@@ -564,7 +565,7 @@ def __init__(
564565
def __repr__(self) -> str:
565566
return f"Grouping({self.name})"
566567

567-
def __iter__(self):
568+
def __iter__(self) -> Iterator:
568569
return iter(self.indices)
569570

570571
@cache_readonly

pandas/core/groupby/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1310,7 +1310,7 @@ def _sort_idx(self) -> npt.NDArray[np.intp]:
13101310
# Counting sort indexer
13111311
return get_group_index_sorter(self.labels, self.ngroups)
13121312

1313-
def __iter__(self):
1313+
def __iter__(self) -> Iterator:
13141314
sdata = self.sorted_data
13151315

13161316
if self.ngroups == 0:

pandas/core/strings/accessor.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
TYPE_CHECKING,
99
Callable,
1010
Hashable,
11+
Iterator,
1112
cast,
1213
)
1314
import warnings
@@ -239,7 +240,7 @@ def __getitem__(self, key):
239240
result = self._data.array._str_getitem(key)
240241
return self._wrap_result(result)
241242

242-
def __iter__(self):
243+
def __iter__(self) -> Iterator:
243244
warnings.warn(
244245
"Columnar iteration over characters will be deprecated in future releases.",
245246
FutureWarning,

pandas/core/window/rolling.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
Any,
1515
Callable,
1616
Hashable,
17+
Iterator,
1718
Sized,
1819
)
1920
import warnings
@@ -369,7 +370,7 @@ def __repr__(self) -> str:
369370
attrs = ",".join(attrs_list)
370371
return f"{type(self).__name__} [{attrs}]"
371372

372-
def __iter__(self):
373+
def __iter__(self) -> Iterator:
373374
obj = self._selected_obj.set_axis(self._on)
374375
obj = self._create_data(obj)
375376
indexer = self._get_window_indexer()

pandas/io/pytables.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1909,7 +1909,7 @@ def __init__(
19091909

19101910
self.auto_close = auto_close
19111911

1912-
def __iter__(self):
1912+
def __iter__(self) -> Iterator:
19131913
# iterate
19141914
current = self.start
19151915
if self.coordinates is None:
@@ -2131,7 +2131,7 @@ def cvalues(self):
21312131
"""return my cython values"""
21322132
return self.values
21332133

2134-
def __iter__(self):
2134+
def __iter__(self) -> Iterator:
21352135
return iter(self.values)
21362136

21372137
def maybe_set_size(self, min_itemsize=None) -> None:

pandas/tests/dtypes/test_inference.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from numbers import Number
1919
import re
2020
import sys
21+
from typing import Iterator
2122

2223
import numpy as np
2324
import pytest
@@ -95,7 +96,7 @@ class MockNumpyLikeArray:
9596
def __init__(self, values) -> None:
9697
self._values = values
9798

98-
def __iter__(self):
99+
def __iter__(self) -> Iterator:
99100
iter_values = iter(self._values)
100101

101102
def it_outer():

pandas/tests/frame/constructors/test_from_records.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import datetime
22
from decimal import Decimal
3+
from typing import Iterator
34

45
import numpy as np
56
import pytest
@@ -200,7 +201,7 @@ def __init__(self, *args) -> None:
200201
def __getitem__(self, i):
201202
return self.args[i]
202203

203-
def __iter__(self):
204+
def __iter__(self) -> Iterator:
204205
return iter(self.args)
205206

206207
recs = [Record(1, 2, 3), Record(4, 5, 6), Record(7, 8, 9)]

pandas/tests/frame/test_constructors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import functools
1111
import itertools
1212
import re
13+
from typing import Iterator
1314
import warnings
1415

1516
import numpy as np
@@ -1430,7 +1431,7 @@ def test_constructor_list_of_ranges(self):
14301431
def test_constructor_iterable(self):
14311432
# GH 21987
14321433
class Iter:
1433-
def __iter__(self):
1434+
def __iter__(self) -> Iterator:
14341435
for i in range(10):
14351436
yield [1, 2, 3]
14361437

pandas/tests/io/json/test_readlines.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from io import StringIO
22
from pathlib import Path
3+
from typing import Iterator
34

45
import pytest
56

@@ -289,7 +290,7 @@ def read(self, *args):
289290
self.read_count += 1
290291
return self.stringio.read(*args)
291292

292-
def __iter__(self):
293+
def __iter__(self) -> Iterator:
293294
self.read_count += 1
294295
return iter(self.stringio)
295296

pandas/tests/io/parser/test_python_parser_only.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
BytesIO,
1212
StringIO,
1313
)
14+
from typing import Iterator
1415

1516
import pytest
1617

@@ -322,7 +323,7 @@ class NoNextBuffer:
322323
def __init__(self, csv_data) -> None:
323324
self.data = csv_data
324325

325-
def __iter__(self):
326+
def __iter__(self) -> Iterator:
326327
return self.data.__iter__()
327328

328329
def read(self):

pandas/tests/io/test_html.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from pathlib import Path
99
import re
1010
import threading
11+
from typing import Iterator
1112
from urllib.error import URLError
1213

1314
import numpy as np
@@ -1277,7 +1278,7 @@ def seek(self, offset):
12771278
def seekable(self):
12781279
return True
12791280

1280-
def __iter__(self):
1281+
def __iter__(self) -> Iterator:
12811282
# to fool `is_file_like`, should never end up here
12821283
assert False
12831284

pandas/tests/reshape/concat/test_concat.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
deque,
44
)
55
from decimal import Decimal
6+
from typing import Iterator
67
from warnings import (
78
catch_warnings,
89
simplefilter,
@@ -463,7 +464,7 @@ def __getitem__(self, index):
463464
tm.assert_frame_equal(concat(CustomIterator1(), ignore_index=True), expected)
464465

465466
class CustomIterator2(abc.Iterable):
466-
def __iter__(self):
467+
def __iter__(self) -> Iterator:
467468
yield df1
468469
yield df2
469470

pandas/tests/series/test_constructors.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
datetime,
44
timedelta,
55
)
6+
from typing import Iterator
67

78
from dateutil.tz import tzoffset
89
import numpy as np
@@ -252,7 +253,7 @@ def test_constructor_series(self):
252253
def test_constructor_iterable(self):
253254
# GH 21987
254255
class Iter:
255-
def __iter__(self):
256+
def __iter__(self) -> Iterator:
256257
yield from range(10)
257258

258259
expected = Series(list(range(10)), dtype="int64")

0 commit comments

Comments
 (0)