Skip to content

Commit d7f45ca

Browse files
author
MarcoGorelli
committed
use periods_per_second and abbrev_to_npy_unit
1 parent e6a6064 commit d7f45ca

File tree

1 file changed

+5
-8
lines changed

1 file changed

+5
-8
lines changed

pandas/core/resample.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,10 @@
2323
Period,
2424
Timedelta,
2525
Timestamp,
26+
periods_per_second,
2627
to_offset,
2728
)
29+
from pandas._libs.tslibs.dtypes import abbrev_to_npy_unit
2830
from pandas._typing import (
2931
AnyArrayLike,
3032
Axis,
@@ -2130,14 +2132,9 @@ def _adjust_dates_anchored(
21302132
if offset is not None:
21312133
offset = offset.as_unit(unit)
21322134

2133-
# TODO is there anything which can be reused here?
2134-
freq_value = freq.nanos
2135-
if unit == "us":
2136-
freq_value = freq_value // 1_000
2137-
elif unit == "ms":
2138-
freq_value = freq_value // 1_000_000
2139-
elif unit == "s":
2140-
freq_value = freq_value // 1_000_000_000
2135+
freq_value = freq.nanos // (
2136+
1_000_000_000 // periods_per_second(abbrev_to_npy_unit(unit))
2137+
)
21412138

21422139
origin_timestamp = 0 # origin == "epoch"
21432140
if origin == "start_day":

0 commit comments

Comments
 (0)