Skip to content

type to_offset #1113

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 1 commit into from
Feb 10, 2025
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
5 changes: 0 additions & 5 deletions pandas-stubs/_libs/tslibs/offsets.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,6 @@ class BaseOffset:
class SingleConstructorOffset(BaseOffset):
def __reduce__(self): ...

@overload
def to_offset(freq: None) -> None: ...
@overload
def to_offset(freq: timedelta | BaseOffset | str) -> BaseOffset: ...

class Tick(SingleConstructorOffset):
def __init__(self, n: int = ..., normalize: bool = ...) -> None: ...
@property
Expand Down
11 changes: 9 additions & 2 deletions pandas-stubs/tseries/frequencies.pyi
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
from typing import overload

from pandas import (
DatetimeIndex,
Series,
TimedeltaIndex,
)

from pandas.tseries.offsets import DateOffset as DateOffset
from pandas._typing import Frequency

from pandas.tseries.offsets import DateOffset

def get_period_alias(offset_str: str) -> str | None: ...
def to_offset(freq) -> DateOffset | None: ...
@overload
def to_offset(freq: None) -> None: ...
@overload
def to_offset(freq: Frequency) -> DateOffset: ...
def get_offset(name: str) -> DateOffset: ...
def infer_freq(index: Series | DatetimeIndex | TimedeltaIndex) -> str | None: ...
9 changes: 8 additions & 1 deletion tests/test_timefuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

from pandas._libs import NaTType
from pandas._libs.tslibs import BaseOffset
from pandas._libs.tslibs.offsets import DateOffset

from pandas.tseries.frequencies import to_offset
from pandas.tseries.offsets import DateOffset

if TYPE_CHECKING:
from pandas._typing import FulldatetimeDict
Expand Down Expand Up @@ -1425,3 +1427,8 @@ def test_DatetimeIndex_sub_timedelta() -> None:
),
pd.DatetimeIndex,
)


def test_to_offset() -> None:
check(assert_type(to_offset(None), None), type(None))
check(assert_type(to_offset("1D"), DateOffset), DateOffset)