Skip to content

Commit d2084b3

Browse files
committed
more 0.7 fixes
1 parent 9a8673c commit d2084b3

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

Diff for: src/PyCall.jl

+1
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,7 @@ setindex!(o::PyObject, v, i1::Integer, i2::Integer) = set!(o, (ind2py(i1),ind2py
812812
getindex(o::PyObject, I::Integer...) = get(o, map(ind2py, I))
813813
setindex!(o::PyObject, v, I::Integer...) = set!(o, map(ind2py, I), v)
814814
length(o::PyObject) = @pycheckz ccall((@pysym :PySequence_Size), Int, (PyPtr,), o)
815+
size(o::PyObject) = (length(o),)
815816
firstindex(o::PyObject) = 1
816817
lastindex(o::PyObject) = length(o)
817818

Diff for: src/numpy.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ function copy(a::PyArray{T,N}) where {T,N}
346346
ccall(:memcpy, Cvoid, (Ptr{T}, Ptr{T}, Int), A, a, sizeof(T)*length(a))
347347
return A
348348
else
349-
return copy!(A, a)
349+
return copyto!(A, a)
350350
end
351351
end
352352

Diff for: src/pyiterator.jl

+17
Original file line numberDiff line numberDiff line change
@@ -83,3 +83,20 @@ function pyjlwrap_getiter(self_::PyPtr)
8383
end
8484
return PyPtr_NULL
8585
end
86+
87+
#########################################################################
88+
# Broadcasting: if the object is iterable, return collect(o), and otherwise
89+
# return o.
90+
91+
@static if isdefined(Base.Broadcast, :broadcastable)
92+
function Base.Broadcast.broadcastable(o::PyObject)
93+
iter = ccall((@pysym :PyObject_GetIter), PyPtr, (PyPtr,), o)
94+
if iter == C_NULL
95+
pyerr_clear()
96+
return Ref(o)
97+
else
98+
ccall(@pysym(:Py_DecRef), Cvoid, (PyPtr,), iter)
99+
return collect(o)
100+
end
101+
end
102+
end

Diff for: test/runtests.jl

+7-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pymodule_exists(s::AbstractString) = !ispynull(pyimport_e(s))
414414

415415
# updating operators .+= etcetera
416416
let o = PyObject(Any[1,2]), c = o
417-
o .+= Any[3,4]
417+
broadcast!(+, o, o, Any[3,4]) # o .+= x doesn't work yet in 0.7
418418
@test collect(o) == [1,2,3,4]
419419
@test o.o == c.o # updated in-place
420420
end
@@ -510,6 +510,12 @@ pymodule_exists(s::AbstractString) = !ispynull(pyimport_e(s))
510510
@test pyfunctionret(factorial, nothing, Int)(3) === nothing
511511
@test PyCall.is_pyjlwrap(pycall(pyfunctionret(factorial, Any, Int), PyObject, 3))
512512
@test pyfunctionret(max, Int, Vararg{Int})(3,4,5) === 5
513+
514+
# broadcasting scalars
515+
let o = PyObject(3) .+ [1,4]
516+
@test o isa Vector{PyObject}
517+
@test o == [4,7]
518+
end
513519
end
514520

515521
######################################################################

0 commit comments

Comments
 (0)