Skip to content

Commit 37a4f5a

Browse files
committed
Add guarded conversion tests
1 parent 9a2ec5a commit 37a4f5a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

test/Convert.jl

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,48 @@ end
265265
@test_throws Exception pyconvert(Microsecond, td(days = -200_000_000))
266266
end
267267

268+
@testitem "ctypes scalars" begin
269+
ctypes = pyimport("ctypes")
270+
271+
@test pyconvert(Int, ctypes.c_int(42)) === 42
272+
@test pyconvert(Float64, ctypes.c_double(3.25)) === 3.25
273+
@test pyconvert(Ptr{Cvoid}, ctypes.c_void_p(0)) == C_NULL
274+
end
275+
276+
@testitem "numpy scalars" setup=[Setup] begin
277+
if Setup.devdeps
278+
np = try
279+
pyimport("numpy")
280+
catch
281+
@test_skip "numpy not available"
282+
return
283+
end
284+
285+
@test pyconvert(Int, np.int64(5)) === 5
286+
@test pyconvert(Float32, np.float32(1.25)) === Float32(1.25)
287+
@test pyconvert(Missing, np.datetime64("NaT")) === missing
288+
@test pyconvert(Missing, np.timedelta64("NaT")) === missing
289+
else
290+
@test_skip Setup.devdeps
291+
end
292+
end
293+
294+
@testitem "pandas NA" setup=[Setup] begin
295+
if Setup.devdeps
296+
pd = try
297+
pyimport("pandas")
298+
catch
299+
@test_skip "pandas not available"
300+
return
301+
end
302+
303+
@test pyconvert(Missing, pd.NA) === missing
304+
@test pyconvert(Nothing, pd.NA) === nothing
305+
else
306+
@test_skip Setup.devdeps
307+
end
308+
end
309+
268310
@testitem "timedelta → Millisecond" begin
269311
using Dates
270312
td = pyimport("datetime").timedelta

0 commit comments

Comments
 (0)