Skip to content

Commit 1e8d410

Browse files
author
Helmut Hänsel
committed
correct handling of count in 64-bit conversion rules
1 parent f897600 commit 1e8d410

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

src/Convert/numpy.jl

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,25 +66,21 @@ end
6666
export pytimedelta64
6767

6868
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))
7270
value = reinterpret(Int64, pyconvert(Vector, x))[1]
7371
units = ("Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns")
7472
types = (Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
7573
T = types[findfirst(==(unit), units)]
76-
pyconvert_return(DateTime(_base_datetime) + T(value))
74+
pyconvert_return(DateTime(_base_datetime) + T(value * count))
7775
end
7876

7977
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))
8379
value = reinterpret(Int64, pyconvert(Vector, x))[1]
8480
units = ("Y", "M", "W", "D", "h", "m", "s", "ms", "us", "ns")
8581
types = (Year, Month, Week, Day, Hour, Minute, Second, Millisecond, Microsecond, Nanosecond)
8682
T = types[findfirst(==(unit), units)]
87-
pyconvert_return(CompoundPeriod(T(value)) |> canonicalize)
83+
pyconvert_return(CompoundPeriod(T(value * count)) |> canonicalize)
8884
end
8985

9086
function pyconvert_rule_timedelta64(::Type{T}, x::Py) where T<:Period

0 commit comments

Comments
 (0)