Skip to content

TYP: remove ignore from all_timeseries_index_generator #39054

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
from __future__ import annotations

import collections
from datetime import datetime
from functools import wraps
import operator
import os
import re
import string
from typing import Callable, ContextManager, Counter, List, Type
from typing import (
TYPE_CHECKING,
Callable,
ContextManager,
Counter,
Iterable,
List,
Type,
)
import warnings

import numpy as np
Expand Down Expand Up @@ -90,6 +100,9 @@
)
from pandas.core.arrays import DatetimeArray, PeriodArray, TimedeltaArray, period_array

if TYPE_CHECKING:
from pandas import PeriodIndex, TimedeltaIndex

_N = 30
_K = 4

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


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


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


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

Expand Down Expand Up @@ -394,7 +407,7 @@ def index_subclass_makers_generator():
yield from make_index_funcs


def all_timeseries_index_generator(k=10):
def all_timeseries_index_generator(k: int = 10) -> Iterable[Index]:
"""
Generator which can be iterated over to get instances of all the classes
which represent time-series.
Expand All @@ -403,10 +416,13 @@ def all_timeseries_index_generator(k=10):
----------
k: length of each of the index instances
"""
make_index_funcs = [makeDateIndex, makePeriodIndex, makeTimedeltaIndex]
make_index_funcs: List[Callable[..., Index]] = [
makeDateIndex,
makePeriodIndex,
makeTimedeltaIndex,
]
for make_index_func in make_index_funcs:
# pandas\_testing.py:1986: error: Cannot call function of unknown type
yield make_index_func(k=k) # type: ignore[operator]
yield make_index_func(k=k)


# make series
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/datetimes.py
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ def date_range(
def bdate_range(
start=None,
end=None,
periods=None,
periods: Optional[int] = None,
freq="B",
tz=None,
normalize=True,
Expand Down
2 changes: 1 addition & 1 deletion pandas/core/indexes/period.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ def memory_usage(self, deep: bool = False) -> int:


def period_range(
start=None, end=None, periods=None, freq=None, name=None
start=None, end=None, periods: Optional[int] = None, freq=None, name=None
) -> PeriodIndex:
"""
Return a fixed frequency PeriodIndex.
Expand Down
11 changes: 8 additions & 3 deletions pandas/core/indexes/timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pandas._libs import index as libindex, lib
from pandas._libs.tslibs import Timedelta, to_offset
from pandas._typing import DtypeObj
from pandas._typing import DtypeObj, Optional
from pandas.errors import InvalidIndexError

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


def timedelta_range(
start=None, end=None, periods=None, freq=None, name=None, closed=None
start=None,
end=None,
periods: Optional[int] = None,
freq=None,
name=None,
closed=None,
) -> TimedeltaIndex:
"""
Return a fixed frequency TimedeltaIndex, with day as the default
Expand All @@ -236,7 +241,7 @@ def timedelta_range(

Returns
-------
rng : TimedeltaIndex
TimedeltaIndex

Notes
-----
Expand Down