Skip to content

Commit 53810fd

Browse files
TYP: remove ignore from all_timeseries_index_generator (#39054)
1 parent 51b04e0 commit 53810fd

File tree

4 files changed

+34
-13
lines changed

4 files changed

+34
-13
lines changed

pandas/_testing/__init__.py

+24-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
from __future__ import annotations
2+
13
import collections
24
from datetime import datetime
35
from functools import wraps
46
import operator
57
import os
68
import re
79
import string
8-
from typing import Callable, ContextManager, Counter, List, Type
10+
from typing import (
11+
TYPE_CHECKING,
12+
Callable,
13+
ContextManager,
14+
Counter,
15+
Iterable,
16+
List,
17+
Type,
18+
)
919
import warnings
1020

1121
import numpy as np
@@ -90,6 +100,9 @@
90100
)
91101
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray, period_array
92102

103+
if TYPE_CHECKING:
104+
from pandas import PeriodIndex, TimedeltaIndex
105+
93106
_N = 30
94107
_K = 4
95108

@@ -281,17 +294,17 @@ def makeFloatIndex(k=10, name=None):
281294
return Index(values * (10 ** np.random.randint(0, 9)), name=name)
282295

283296

284-
def makeDateIndex(k=10, freq="B", name=None, **kwargs):
297+
def makeDateIndex(k: int = 10, freq="B", name=None, **kwargs) -> DatetimeIndex:
285298
dt = datetime(2000, 1, 1)
286299
dr = bdate_range(dt, periods=k, freq=freq, name=name)
287300
return DatetimeIndex(dr, name=name, **kwargs)
288301

289302

290-
def makeTimedeltaIndex(k=10, freq="D", name=None, **kwargs):
303+
def makeTimedeltaIndex(k: int = 10, freq="D", name=None, **kwargs) -> TimedeltaIndex:
291304
return pd.timedelta_range(start="1 day", periods=k, freq=freq, name=name, **kwargs)
292305

293306

294-
def makePeriodIndex(k=10, name=None, **kwargs):
307+
def makePeriodIndex(k: int = 10, name=None, **kwargs) -> PeriodIndex:
295308
dt = datetime(2000, 1, 1)
296309
return pd.period_range(start=dt, periods=k, freq="B", name=name, **kwargs)
297310

@@ -394,7 +407,7 @@ def index_subclass_makers_generator():
394407
yield from make_index_funcs
395408

396409

397-
def all_timeseries_index_generator(k=10):
410+
def all_timeseries_index_generator(k: int = 10) -> Iterable[Index]:
398411
"""
399412
Generator which can be iterated over to get instances of all the classes
400413
which represent time-series.
@@ -403,10 +416,13 @@ def all_timeseries_index_generator(k=10):
403416
----------
404417
k: length of each of the index instances
405418
"""
406-
make_index_funcs = [makeDateIndex, makePeriodIndex, makeTimedeltaIndex]
419+
make_index_funcs: List[Callable[..., Index]] = [
420+
makeDateIndex,
421+
makePeriodIndex,
422+
makeTimedeltaIndex,
423+
]
407424
for make_index_func in make_index_funcs:
408-
# pandas\_testing.py:1986: error: Cannot call function of unknown type
409-
yield make_index_func(k=k) # type: ignore[operator]
425+
yield make_index_func(k=k)
410426

411427

412428
# make series

pandas/core/indexes/datetimes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ def date_range(
10891089
def bdate_range(
10901090
start=None,
10911091
end=None,
1092-
periods=None,
1092+
periods: Optional[int] = None,
10931093
freq="B",
10941094
tz=None,
10951095
normalize=True,

pandas/core/indexes/period.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ def memory_usage(self, deep: bool = False) -> int:
649649

650650

651651
def period_range(
652-
start=None, end=None, periods=None, freq=None, name=None
652+
start=None, end=None, periods: Optional[int] = None, freq=None, name=None
653653
) -> PeriodIndex:
654654
"""
655655
Return a fixed frequency PeriodIndex.

pandas/core/indexes/timedeltas.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from pandas._libs import index as libindex, lib
44
from pandas._libs.tslibs import Timedelta, to_offset
5-
from pandas._typing import DtypeObj
5+
from pandas._typing import DtypeObj, Optional
66
from pandas.errors import InvalidIndexError
77

88
from pandas.core.dtypes.common import TD64NS_DTYPE, is_scalar, is_timedelta64_dtype
@@ -212,7 +212,12 @@ def inferred_type(self) -> str:
212212

213213

214214
def timedelta_range(
215-
start=None, end=None, periods=None, freq=None, name=None, closed=None
215+
start=None,
216+
end=None,
217+
periods: Optional[int] = None,
218+
freq=None,
219+
name=None,
220+
closed=None,
216221
) -> TimedeltaIndex:
217222
"""
218223
Return a fixed frequency TimedeltaIndex, with day as the default
@@ -236,7 +241,7 @@ def timedelta_range(
236241
237242
Returns
238243
-------
239-
rng : TimedeltaIndex
244+
TimedeltaIndex
240245
241246
Notes
242247
-----

0 commit comments

Comments
 (0)