Skip to content

Commit 6b27566

Browse files
author
Christopher Doris
committed
array conversions
1 parent 9abc742 commit 6b27566

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

src/convert.jl

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,18 @@ function pytryconvert(::Type{T}, o::PyObject) where {T}
2121
r === PyConvertFail() || return r
2222
end
2323

24-
# interfaces
25-
# TODO: buffer
26-
# TODO: IO
27-
# TODO: number?
24+
# buffer/array interface
25+
if (C.PyObject_CheckBuffer(o) != 0) || (pyhasattr(o, "__array__") && !pyisnone(o.__array__)) || (pyhasattr(o, "__array_interface__") && !pyisnone(o.__array_interface__))
26+
r = tryconvert(T, PyArray(o))
27+
r === PyConvertFail() || return r
28+
end
29+
# iterable interface (includes sequences, mappings and sets)
2830
if pyisinstance(o, pyiterableabc)
2931
r = pyiterable_tryconvert(T, o) :: Union{T, PyConvertFail}
3032
r === PyConvertFail() || return r
3133
end
34+
# TODO: IO interface
35+
# TODO: number interface
3236

3337
# so that T=Any always succeeds
3438
if o isa T

src/object.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ pyobject(o::DateTime) = pydatetime(o)
9494
pyobject(o::Date) = pydate(o)
9595
pyobject(o::Time) = pytime(o)
9696
pyobject(o::IO) = pybufferedio(o)
97+
pyobject(o::Function) = pyjl(o, Function) # functions are singleton types - this avoids compiling a separate type for each one
9798
pyobject(o) = pyjl(o)
9899
export pyobject
99100

0 commit comments

Comments
 (0)