Skip to content

Commit 8f28567

Browse files
author
hhaensel
committed
fix micro/millisecond in pytimedelta,
append 's' to keywords in pytimedelta and pytimedelta64
1 parent 7391b8d commit 8f28567

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

src/Convert/numpy.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ function pydatetime64(
3232
year::Integer=_year, month::Integer=_month, day::Integer=_day, hour::Integer=_hour, minute::Integer=_minute, second::Integer=_second,
3333
millisecond::Integer=_millisecond, microsecond::Integer=_microsecond, nanosecond::Integer=_nanosecond
3434
)
35-
pyimport("numpy").datetime64("$(DateTime(year, month, day, hour, minute, second))") + pytimedelta64(;millisecond, microsecond, nanosecond)
35+
pyimport("numpy").datetime64("$(DateTime(year, month, day, hour, minute, second))") +
36+
pytimedelta64(; milliseconds = millisecond, microseconds = microsecond, nanoseconds = nanosecond)
3637
end
3738
function pydatetime64(@nospecialize(x::T)) where T <: Period
3839
T <: Union{Week, Day, Hour, Minute, Second, Millisecond, Microsecond} ||
@@ -47,13 +48,13 @@ end
4748
export pydatetime64
4849

4950
function pytimedelta64(
50-
_year::Integer=0, _month::Integer=0, _day::Integer=0, _hour::Integer=0, _minute::Integer=0, _second::Integer=0, _millisecond::Integer=0, _microsecond::Integer=0, _nanosecond::Integer=0, _week::Integer=0;
51-
year::Integer=_year, month::Integer=_month, day::Integer=_day, hour::Integer=_hour, minute::Integer=_minute, second::Integer=_second, microsecond::Integer=_microsecond, millisecond::Integer=_millisecond, nanosecond::Integer=_nanosecond, week::Integer=_week)
51+
_years::Integer=0, _months::Integer=0, _days::Integer=0, _hours::Integer=0, _minutes::Integer=0, _seconds::Integer=0, _milliseconds::Integer=0, _microseconds::Integer=0, _nanoseconds::Integer=0, _weeks::Integer=0;
52+
years::Integer=_years, months::Integer=_months, days::Integer=_days, hours::Integer=_hours, minutes::Integer=_minutes, seconds::Integer=_seconds, microseconds::Integer=_microseconds, milliseconds::Integer=_milliseconds, nanoseconds::Integer=_nanoseconds, weeks::Integer=_weeks)
5253
pytimedelta64(sum((
53-
Year(year), Month(month),
54+
Year(years), Month(months),
5455
# you cannot mix year or month with any of the below units in python
5556
# in case of wrong usage a descriptive error message will by thrown by the underlying python function
56-
Day(day), Hour(hour), Minute(minute), Second(second), Millisecond(millisecond), Microsecond(microsecond), Nanosecond(nanosecond), Week(week))
57+
Day(days), Hour(hours), Minute(minutes), Second(seconds), Millisecond(milliseconds), Microsecond(microseconds), Nanosecond(nanoseconds), Week(weeks))
5758
))
5859
end
5960
function pytimedelta64(@nospecialize(x::T)) where T <: Period

src/Core/builtins.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,15 +1168,15 @@ pydatetime(x::Date) = pydatetime(year(x), month(x), day(x))
11681168
export pydatetime
11691169

11701170
function pytimedelta(
1171-
_day::Int=0, _second::Int=0, _microsecond::Int=0, _millisecond::Int=0, _minute::Int=0, _hour::Int=0, _week::Int=0;
1172-
day::Int=_day, second::Int=_second, microsecond::Int=_microsecond, millisecond::Int=_millisecond, minute::Int=_minute, hour::Int=_hour, week::Int=_week
1171+
_days::Int=0, _seconds::Int=0, _microseconds::Int=0, _milliseconds::Int=0, _minutes::Int=0, _hours::Int=0, _weeks::Int=0;
1172+
days::Int=_days, seconds::Int=_seconds, microseconds::Int=_microseconds, milliseconds::Int=_milliseconds, minutes::Int=_minutes, hours::Int=_hours, weeks::Int=_weeks
11731173
)
1174-
pyimport("datetime").timedelta(day, second, microsecond, millisecond, minute, hour, week)
1174+
pyimport("datetime").timedelta(days, seconds, microseconds, milliseconds, minutes, hours, weeks)
11751175
end
11761176
function pytimedelta(@nospecialize(x::T)) where T <: Period
11771177
T <: Union{Week, Day, Hour, Minute, Second, Millisecond, Microsecond} ||
11781178
error("Unsupported Period type: ", "Year, Month and Nanosecond are not supported, consider using pytimedelta64 instead.")
1179-
args = T .== (Day, Second, Millisecond, Microsecond, Minute, Hour, Week)
1179+
args = T .== (Day, Second, Microsecond, Millisecond, Minute, Hour, Week)
11801180
pytimedelta(x.value .* args...)
11811181
end
11821182
function pytimedelta(x::CompoundPeriod)

0 commit comments

Comments
 (0)