Skip to content

Commit

Permalink
TYP: annotate tseries.holiday (pandas-dev#35913)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbrockmendel authored Aug 27, 2020
1 parent e3bcf8d commit a1f6056
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
28 changes: 15 additions & 13 deletions pandas/tseries/holiday.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from pandas.tseries.offsets import Day, Easter


def next_monday(dt):
def next_monday(dt: datetime) -> datetime:
"""
If holiday falls on Saturday, use following Monday instead;
if holiday falls on Sunday, use Monday instead
Expand All @@ -24,7 +24,7 @@ def next_monday(dt):
return dt


def next_monday_or_tuesday(dt):
def next_monday_or_tuesday(dt: datetime) -> datetime:
"""
For second holiday of two adjacent ones!
If holiday falls on Saturday, use following Monday instead;
Expand All @@ -39,7 +39,7 @@ def next_monday_or_tuesday(dt):
return dt


def previous_friday(dt):
def previous_friday(dt: datetime) -> datetime:
"""
If holiday falls on Saturday or Sunday, use previous Friday instead.
"""
Expand All @@ -50,7 +50,7 @@ def previous_friday(dt):
return dt


def sunday_to_monday(dt):
def sunday_to_monday(dt: datetime) -> datetime:
"""
If holiday falls on Sunday, use day thereafter (Monday) instead.
"""
Expand All @@ -59,7 +59,7 @@ def sunday_to_monday(dt):
return dt


def weekend_to_monday(dt):
def weekend_to_monday(dt: datetime) -> datetime:
"""
If holiday falls on Sunday or Saturday,
use day thereafter (Monday) instead.
Expand All @@ -72,7 +72,7 @@ def weekend_to_monday(dt):
return dt


def nearest_workday(dt):
def nearest_workday(dt: datetime) -> datetime:
"""
If holiday falls on Saturday, use day before (Friday) instead;
if holiday falls on Sunday, use day thereafter (Monday) instead.
Expand All @@ -84,7 +84,7 @@ def nearest_workday(dt):
return dt


def next_workday(dt):
def next_workday(dt: datetime) -> datetime:
"""
returns next weekday used for observances
"""
Expand All @@ -95,7 +95,7 @@ def next_workday(dt):
return dt


def previous_workday(dt):
def previous_workday(dt: datetime) -> datetime:
"""
returns previous weekday used for observances
"""
Expand All @@ -106,14 +106,14 @@ def previous_workday(dt):
return dt


def before_nearest_workday(dt):
def before_nearest_workday(dt: datetime) -> datetime:
"""
returns previous workday after nearest workday
"""
return previous_workday(nearest_workday(dt))


def after_nearest_workday(dt):
def after_nearest_workday(dt: datetime) -> datetime:
"""
returns next workday after nearest workday
needed for Boxing day or multiple holidays in a series
Expand Down Expand Up @@ -428,9 +428,11 @@ def holidays(self, start=None, end=None, return_name=False):
# If we don't have a cache or the dates are outside the prior cache, we
# get them again
if self._cache is None or start < self._cache[0] or end > self._cache[1]:
holidays = [rule.dates(start, end, return_name=True) for rule in self.rules]
if holidays:
holidays = concat(holidays)
pre_holidays = [
rule.dates(start, end, return_name=True) for rule in self.rules
]
if pre_holidays:
holidays = concat(pre_holidays)
else:
holidays = Series(index=DatetimeIndex([]), dtype=object)

Expand Down
3 changes: 0 additions & 3 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,3 @@ check_untyped_defs=False

[mypy-pandas.plotting._matplotlib.misc]
check_untyped_defs=False

[mypy-pandas.tseries.holiday]
check_untyped_defs=False

0 comments on commit a1f6056

Please sign in to comment.