Skip to content
Open
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
7 changes: 5 additions & 2 deletions pandas-stubs/_libs/tslibs/timedeltas.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ from pandas.core.indexes.timedeltas import TimedeltaIndex
from pandas.core.series import Series
from typing_extensions import Self

from pandas._libs.tslibs import NaTType
from pandas._libs.tslibs import (
NaTType,
Tick,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should import Tick from pandas.tseries.offsets

)
from pandas._libs.tslibs.period import Period
from pandas._libs.tslibs.timestamps import Timestamp
from pandas._typing import (
Expand Down Expand Up @@ -95,7 +98,7 @@ class Timedelta(timedelta):
value: int
def __new__(
cls,
value: str | float | Timedelta | timedelta | np.timedelta64 = ...,
value: str | float | Timedelta | Tick | timedelta | np.timedelta64 = ...,
unit: TimeDeltaUnitChoices = ...,
*,
days: float | np.integer | np.floating = ...,
Expand Down
8 changes: 8 additions & 0 deletions tests/arrays/test_timedeltas.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from typing_extensions import assert_type

from pandas._libs import NaTType
from pandas._libs.tslibs.offsets import Minute
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should import Minute from pandas.tseries.offsets

from pandas._libs.tslibs.timedeltas import Timedelta
from pandas._typing import TimeUnit

Expand Down Expand Up @@ -107,6 +108,13 @@ def test_timedelta_array_mod() -> None:
check(assert_type(result, TimedeltaArray), TimedeltaArray)


def test_timedelta_takes_tick_object() -> None:
"""Test that Timedelta objects can be built using tick objects such as Minute."""
tick = Minute(15)
seconds = pd.Timedelta(tick).total_seconds()
assert seconds == 900.0
Comment on lines +113 to +115
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test should be of the form:

check(assert_type(pd.Timedelta(Minute(15)), pd.Timedelta), pd.Timedelta)



def test_timedelta_array_divmod() -> None:
"""Test __divmod__ for TimedeltaArray."""
idx = pd.TimedeltaIndex(["1 days", "2 days", "3 days"])
Expand Down