Skip to content

GH648 Allowing dateoffset weekday from relativedelta #1010

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
merged 4 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
20 changes: 20 additions & 0 deletions tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,20 @@
cast,
)

from dateutil.relativedelta import (
FR,
MO,
SA,
SU,
TH,
TU,
WE,
weekday as WeekdayClass,
)
import numpy as np
from numpy import typing as npt
import pandas as pd
import pytest
import pytz
from typing_extensions import (
assert_never,
Expand Down Expand Up @@ -1284,6 +1295,15 @@ def test_weekofmonth_init():
)


@pytest.mark.parametrize("weekday", [1, MO, TU, WE, TH, TH, FR, SA, SU])
def test_dateoffset_weekday(weekday: int | WeekdayClass):
"""Check that you can create a `pd.DateOffset` from weekday of int or relativedelta.weekday."""
check(
assert_type(pd.offsets.DateOffset(weekday=weekday), pd.offsets.DateOffset),
pd.offsets.DateOffset,
)


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