Skip to content

Commit 5188c78

Browse files
GH648 Allowing dateoffset weekday from relativedelta
1 parent 1bc27e6 commit 5188c78

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

pandas-stubs/_libs/tslibs/offsets.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ from typing import (
1212
overload,
1313
)
1414

15+
from dateutil.relativedelta import weekday as WeekdayClass
1516
import numpy as np
1617
from pandas.core.indexes.datetimes import DatetimeIndex
1718
from typing_extensions import Self
@@ -257,7 +258,7 @@ class DateOffset(RelativeDeltaOffset):
257258
year: int = ...,
258259
month: int = ...,
259260
day: int = ...,
260-
weekday: int = ...,
261+
weekday: int | WeekdayClass = ...,
261262
hour: int = ...,
262263
minute: int = ...,
263264
second: int = ...,

tests/test_timefuncs.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88
cast,
99
)
1010

11+
from dateutil.relativedelta import (
12+
FR,
13+
MO,
14+
SA,
15+
SU,
16+
TH,
17+
TU,
18+
WE,
19+
)
1120
import numpy as np
1221
from numpy import typing as npt
1322
import pandas as pd
@@ -19,7 +28,12 @@
1928

2029
from pandas._libs import NaTType
2130
from pandas._libs.tslibs import BaseOffset
22-
from pandas._libs.tslibs.offsets import DateOffset
31+
from pandas._libs.tslibs.offsets import (
32+
DateOffset,
33+
FY5253Mixin,
34+
WeekOfMonth,
35+
WeekOfMonthMixin,
36+
)
2337

2438
if TYPE_CHECKING:
2539
from pandas._typing import FulldatetimeDict
@@ -1284,6 +1298,21 @@ def test_weekofmonth_init():
12841298
)
12851299

12861300

1301+
def test_dateoffset_weekday():
1302+
"""Check that you can create a `pd.DateOffset` from weekday of int or dateutil.relativedelta."""
1303+
# check for int
1304+
check(
1305+
assert_type(pd.offsets.DateOffset(weekday=1), pd.offsets.DateOffset),
1306+
pd.offsets.DateOffset,
1307+
)
1308+
# check for relativedelta
1309+
for weekday in [MO, TU, WE, TH, TH, FR, SA, SU]:
1310+
check(
1311+
assert_type(pd.offsets.DateOffset(weekday=weekday), pd.offsets.DateOffset),
1312+
pd.offsets.DateOffset,
1313+
)
1314+
1315+
12871316
def test_date_range_unit():
12881317
check(
12891318
assert_type(

0 commit comments

Comments
 (0)