|
66 | 66 | export pytimedelta64
|
67 | 67 |
|
68 | 68 | function pyconvert_rule_datetime64(::Type{DateTime}, x::Py)
|
69 |
| - unit, value = pyconvert(Tuple, pyimport("numpy").datetime_data(x)) |
70 |
| - # strangely, datetime_data does not return the value correctly |
71 |
| - # so we retrieve the value from the byte representation |
| 69 | + unit, count = pyconvert(Tuple, pyimport("numpy").datetime_data(x)) |
72 | 70 | value = reinterpret(Int64, pyconvert(Vector, x))[1]
|
73 | 71 | units = ("Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns")
|
74 | 72 | types = (Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
|
75 | 73 | T = types[findfirst(==(unit), units)]
|
76 |
| - pyconvert_return(DateTime(_base_datetime) + T(value)) |
| 74 | + pyconvert_return(DateTime(_base_datetime) + T(value * count)) |
77 | 75 | end
|
78 | 76 |
|
79 | 77 | function pyconvert_rule_timedelta64(::Type{CompoundPeriod}, x::Py)
|
80 |
| - unit, value = pyconvert(Tuple, pyimport("numpy").datetime_data(x)) |
81 |
| - # strangely, datetime_data does not return the value correctly |
82 |
| - # so we retrieve the value from the byte representation |
| 78 | + unit, count = pyconvert(Tuple, pyimport("numpy").datetime_data(x)) |
83 | 79 | value = reinterpret(Int64, pyconvert(Vector, x))[1]
|
84 | 80 | units = ("Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns")
|
85 | 81 | types = (Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
|
86 | 82 | T = types[findfirst(==(unit), units)]
|
87 |
| - pyconvert_return(CompoundPeriod(T(value)) |> canonicalize) |
| 83 | + pyconvert_return(CompoundPeriod(T(value * count)) |> canonicalize) |
88 | 84 | end
|
89 | 85 |
|
90 | 86 | function pyconvert_rule_timedelta64(::Type{T}, x::Py) where T<:Period
|
|
0 commit comments