Skip to content

Commit 3981b04

Browse files
committed
TST: BUG49897 convert millis to micros so relativedelta can use them
1 parent c2cf081 commit 3981b04

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

pandas/_libs/tslibs/offsets.pyx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,11 @@ cdef _determine_offset(kwds):
336336
# This also handles "milliseconds" (plur): see GH 49897
337337
return timedelta(**kwds_no_nanos), False
338338

339+
# convert milliseconds to microseconds, so relativedelta can parse it
340+
if "milliseconds" in kwds_no_nanos:
341+
micro = kwds_no_nanos.pop("milliseconds") * 1000
342+
kwds_no_nanos["microseconds"] = kwds_no_nanos.get("microseconds", 0) + micro
343+
339344
if all(k in kwds_use_relativedelta for k in kwds_no_nanos):
340345
return relativedelta(**kwds_no_nanos), True
341346

pandas/tests/tseries/offsets/test_offsets.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -742,10 +742,13 @@ def test_eq(self):
742742
@pytest.mark.parametrize(
743743
"offset_kwargs, expected_arg",
744744
[
745+
({"seconds": 1, "milliseconds": 1}, "2022-01-01 00:00:01.001"),
745746
({"minutes": 1, "milliseconds": 1}, "2022-01-01 00:01:00.001"),
746747
({"hours": 1, "milliseconds": 1}, "2022-01-01 01:00:00.001"),
747748
({"days": 1, "milliseconds": 1}, "2022-01-02 00:00:00.001"),
748749
({"weeks": 1, "milliseconds": 1}, "2022-01-08 00:00:00.001"),
750+
({"months": 1, "milliseconds": 1}, "2022-02-01 00:00:00.001"),
751+
({"years": 1, "milliseconds": 1}, "2023-01-01 00:00:00.001"),
749752
],
750753
)
751754
def test_milliseconds_combination(self, offset_kwargs, expected_arg):

0 commit comments

Comments
 (0)