Skip to content

Commit daf9759

Browse files
committed
reviewers suggestions part III
1 parent a3a2b97 commit daf9759

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

src/Convert/numpy.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ const NUMPY_SIMPLE_TYPES = [
2828
]
2929

3030
function pydatetime64(
31-
_year::Int=0, _month::Int=1, _day::Int=1, _hour::Int=0, _minute::Int=0,_second::Int=0, _millisecond::Int=0, _microsecond::Int=0, _nanosecond::Int=0;
32-
year::Int=_year, month::Int=_month, day::Int=_day, hour::Int=_hour, minute::Int=_minute, second::Int=_second,
33-
millisecond::Int=_millisecond, microsecond::Int=_microsecond, nanosecond::Int=_nanosecond
31+
_year::Integer=0, _month::Integer=1, _day::Integer=1, _hour::Integer=0, _minute::Integer=0,_second::Integer=0, _millisecond::Integer=0, _microsecond::Integer=0, _nanosecond::Integer=0;
32+
year::Integer=_year, month::Integer=_month, day::Integer=_day, hour::Integer=_hour, minute::Integer=_minute, second::Integer=_second,
33+
millisecond::Integer=_millisecond, microsecond::Integer=_microsecond, nanosecond::Integer=_nanosecond
3434
)
3535
pyimport("numpy").datetime64("$(DateTime(year, month, day, hour, minute, second))") + pytimedelta64(;millisecond, microsecond, nanosecond)
3636
end
@@ -47,10 +47,12 @@ end
4747
export pydatetime64
4848

4949
function pytimedelta64(
50-
_year::Int=0, _month::Int=0, _day::Int=0, _hour::Int=0, _minute::Int=0, _second::Int=0, _millisecond::Int=0, _microsecond::Int=0, _nanosecond::Int=0, _week::Int=0;
51-
year::Int=_year, month::Int=_month, day::Int=_day, hour::Int=_hour, minute::Int=_minute, second::Int=_second, microsecond::Int=_microsecond, millisecond::Int=_millisecond, nanosecond::Int=_nanosecond, week::Int=_week)
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)
5252
pytimedelta64(sum((
53-
Year(year), Month(month), # you cannot mix year or month with any of the below units in python, the error will be thrown by `pytimedelta64(::CompoundPeriod)`
53+
Year(year), Month(month),
54+
# you cannot mix year or month with any of the below units in python
55+
# in case of wrong usage a descriptive error message will by thrown by the underlying python function
5456
Day(day), Hour(hour), Minute(minute), Second(second), Millisecond(millisecond), Microsecond(microsecond), Nanosecond(nanosecond), Week(week))
5557
))
5658
end
@@ -117,8 +119,8 @@ function init_numpy()
117119

118120
priority = PYCONVERT_PRIORITY_ARRAY
119121
pyconvert_add_rule("numpy:datetime64", DateTime, pyconvert_rule_datetime64, priority)
120-
for T in (CompoundPeriod, Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond, Week)
121-
pyconvert_add_rule("numpy:timedelta64", T, pyconvert_rule_timedelta64, priority)
122+
let TT = (CompoundPeriod, Year, Month, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond, Week)
123+
Base.Cartesian.@nexprs 11 i -> pyconvert_add_rule("numpy:timedelta64", TT[i], pyconvert_rule_timedelta64, priority)
122124
end
123125

124126
priority = PYCONVERT_PRIORITY_CANONICAL

0 commit comments

Comments
 (0)