Skip to content
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

GH648 Allowing dateoffset weekday from relativedelta #1010

Merged
merged 4 commits into from
Oct 2, 2024
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
3 changes: 2 additions & 1 deletion pandas-stubs/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ from typing import (
overload,
)

from dateutil.relativedelta import weekday as WeekdayClass
import numpy as np
from pandas.core.indexes.datetimes import DatetimeIndex
from typing_extensions import Self
Expand Down Expand Up @@ -257,7 +258,7 @@ class DateOffset(RelativeDeltaOffset):
year: int = ...,
month: int = ...,
day: int = ...,
weekday: int = ...,
weekday: int | WeekdayClass = ...,
hour: int = ...,
minute: int = ...,
second: int = ...,
Expand Down
45 changes: 45 additions & 0 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
cast,
)

from dateutil.relativedelta import (
FR,
MO,
SA,
SU,
TH,
TU,
WE,
)
import numpy as np
from numpy import typing as npt
import pandas as pd
Expand Down Expand Up @@ -1284,6 +1293,42 @@ def test_weekofmonth_init():
)


def test_dateoffset_weekday() -> None:
"""Check that you can create a `pd.DateOffset` from weekday of int or relativedelta.weekday."""
check(
assert_type(pd.offsets.DateOffset(weekday=1), pd.offsets.DateOffset),
pd.offsets.DateOffset,
)
check(
assert_type(pd.offsets.DateOffset(weekday=MO), pd.offsets.DateOffset),
pd.offsets.DateOffset,
)
check(
assert_type(pd.offsets.DateOffset(weekday=TU), pd.offsets.DateOffset),
pd.offsets.DateOffset,
)
check(
assert_type(pd.offsets.DateOffset(weekday=WE), pd.offsets.DateOffset),
pd.offsets.DateOffset,
)
check(
assert_type(pd.offsets.DateOffset(weekday=TH), pd.offsets.DateOffset),
pd.offsets.DateOffset,
)
check(
assert_type(pd.offsets.DateOffset(weekday=FR), pd.offsets.DateOffset),
pd.offsets.DateOffset,
)
check(
assert_type(pd.offsets.DateOffset(weekday=SA), pd.offsets.DateOffset),
pd.offsets.DateOffset,
)
check(
assert_type(pd.offsets.DateOffset(weekday=SU), pd.offsets.DateOffset),
pd.offsets.DateOffset,
)


def test_date_range_unit():
check(
assert_type(
Expand Down
Loading