Skip to content

Commit 31e8269

Browse files
committed
Add as_unit method to Timestamp
1 parent eb26f35 commit 31e8269

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pandas-stubs/_libs/tslibs/timestamps.pyi

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,6 @@ class Timestamp(datetime):
312312
def daysinmonth(self) -> int: ...
313313
@property
314314
def unit(self) -> str: ...
315+
def as_unit(
316+
self, unit: Literal["s", "ms", "us", "ns"], round_ok: bool = ...
317+
) -> Self: ...

tests/test_scalars.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1646,6 +1646,11 @@ def test_timestamp_misc_methods() -> None:
16461646
pd.Timestamp,
16471647
)
16481648

1649+
check(assert_type(ts2.as_unit("s"), pd.Timestamp), pd.Timestamp)
1650+
check(assert_type(ts2.as_unit("ms"), pd.Timestamp), pd.Timestamp)
1651+
check(assert_type(ts2.as_unit("us", round_ok=True), pd.Timestamp), pd.Timestamp)
1652+
check(assert_type(ts2.as_unit("ns", round_ok=False), pd.Timestamp), pd.Timestamp)
1653+
16491654

16501655
def test_timestamp_types_arithmetic() -> None:
16511656
ts: pd.Timestamp = pd.to_datetime("2021-03-01")

0 commit comments

Comments
 (0)