Skip to content

Commit c1b03e7

Browse files
TYP: add type annotations for holidays and dtypes modules (#62327)
1 parent 7e48c73 commit c1b03e7

File tree

2 files changed

+25
-13
lines changed

2 files changed

+25
-13
lines changed

pandas/core/dtypes/dtypes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ class PandasExtensionDtype(ExtensionDtype):
123123
# problem dealing with multiple inheritance from PandasExtensionDtype
124124
# and ExtensionDtype's @properties in the subclasses below. The kind and
125125
# type variables in those subclasses are explicitly typed below.
126-
subdtype = None
126+
subdtype: DtypeObj | None = None
127127
str: str_type
128128
num = 100
129129
shape: tuple[int, ...] = ()
@@ -1604,7 +1604,7 @@ class BaseMaskedDtype(ExtensionDtype):
16041604
Base class for dtypes for BaseMaskedArray subclasses.
16051605
"""
16061606

1607-
base = None
1607+
base: DtypeObj | None = None
16081608
type: type
16091609
_internal_fill_value: Scalar
16101610

pandas/tseries/holiday.py

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@
44
datetime,
55
timedelta,
66
)
7-
from typing import TYPE_CHECKING
7+
from typing import (
8+
TYPE_CHECKING,
9+
Literal,
10+
overload,
11+
)
812
import warnings
913

1014
from dateutil.relativedelta import (
@@ -281,6 +285,17 @@ def __repr__(self) -> str:
281285
repr = f"Holiday: {self.name} ({info})"
282286
return repr
283287

288+
@overload
289+
def dates(self, start_date, end_date, return_name: Literal[True]) -> Series: ...
290+
291+
@overload
292+
def dates(
293+
self, start_date, end_date, return_name: Literal[False]
294+
) -> DatetimeIndex: ...
295+
296+
@overload
297+
def dates(self, start_date, end_date) -> DatetimeIndex: ...
298+
284299
def dates(
285300
self, start_date, end_date, return_name: bool = False
286301
) -> Series | DatetimeIndex:
@@ -411,7 +426,7 @@ def _apply_rule(self, dates: DatetimeIndex) -> DatetimeIndex:
411426
return dates
412427

413428

414-
holiday_calendars = {}
429+
holiday_calendars: dict[str, type[AbstractHolidayCalendar]] = {}
415430

416431

417432
def register(cls) -> None:
@@ -449,7 +464,7 @@ class AbstractHolidayCalendar(metaclass=HolidayCalendarMetaClass):
449464
rules: list[Holiday] = []
450465
start_date = Timestamp(datetime(1970, 1, 1))
451466
end_date = Timestamp(datetime(2200, 12, 31))
452-
_cache = None
467+
_cache: tuple[Timestamp, Timestamp, Series] | None = None
453468

454469
def __init__(self, name: str = "", rules=None) -> None:
455470
"""
@@ -478,7 +493,9 @@ def rule_from_name(self, name: str) -> Holiday | None:
478493

479494
return None
480495

481-
def holidays(self, start=None, end=None, return_name: bool = False):
496+
def holidays(
497+
self, start=None, end=None, return_name: bool = False
498+
) -> DatetimeIndex | Series:
482499
"""
483500
Returns a curve with holidays between start_date and end_date
484501
@@ -515,14 +532,9 @@ def holidays(self, start=None, end=None, return_name: bool = False):
515532
rule.dates(start, end, return_name=True) for rule in self.rules
516533
]
517534
if pre_holidays:
518-
# error: Argument 1 to "concat" has incompatible type
519-
# "List[Union[Series, DatetimeIndex]]"; expected
520-
# "Union[Iterable[DataFrame], Mapping[<nothing>, DataFrame]]"
521-
holidays = concat(pre_holidays) # type: ignore[arg-type]
535+
holidays = concat(pre_holidays)
522536
else:
523-
# error: Incompatible types in assignment (expression has type
524-
# "Series", variable has type "DataFrame")
525-
holidays = Series(index=DatetimeIndex([]), dtype=object) # type: ignore[assignment]
537+
holidays = Series(index=DatetimeIndex([]), dtype=object)
526538

527539
self._cache = (start, end, holidays.sort_index())
528540

0 commit comments

Comments
 (0)