Skip to content

Commit

Permalink
Don't use Base.Callable (#99)
Browse files Browse the repository at this point in the history
Also use `Core.Typeof` to get type info:
- `typeof(Int) === DataType`
- `Core.Typeof(Int) === Type{Int}`
  • Loading branch information
nickrobinson251 authored and nalimilan committed Sep 1, 2019
1 parent d4cf5f9 commit 57113f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Missings.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,6 @@ julia> passmissing((x,y)->"\$x \$y")(1, 2)
julia> passmissing((x,y)->"\$x \$y")(missing)
missing
"""
passmissing(f::Base.Callable) = PassMissing{typeof(f)}(f)
passmissing(f) = PassMissing{Core.Typeof(f)}(f)

end # module
16 changes: 16 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using Test, SparseArrays, Missings

# Must be defined outside testset on v1.0
struct CubeRooter end
(::CubeRooter)(x) = cbrt(x)

@testset "Missings" begin
x = Missings.replace([1, 2, missing, 4], 3)
@test eltype(x) === Int
Expand Down Expand Up @@ -139,13 +143,25 @@ using Test, SparseArrays, Missings
@test_throws MethodError disallowmissing([missing missing])

# Lifting
## functor
cuberoot = CubeRooter() # defined at top of file
@test passmissing(cuberoot)(27) == 3.0
@test isequal(passmissing(cuberoot)(missing), missing)
## type
@test passmissing(Int)(1.0) == 1
@test isequal(passmissing(Int)(missing), missing)
## function
@test passmissing(sqrt)(4) == 2.0
@test isequal(passmissing(sqrt)(missing), missing)
@test isequal(passmissing(sqrt).([missing, 4]), [missing, 2.0])
@test passmissing((x,y)->"$x $y")(1, 2) == "1 2"
@test isequal(passmissing((x,y)->"$x $y")(missing), missing)
@test_throws ErrorException passmissing(string)(missing, base=2)

@test passmissing(sin) === Missings.PassMissing{typeof(sin)}(sin)
@test passmissing(Int) === Missings.PassMissing{Type{Int}}(Int)
@test passmissing(cuberoot) === Missings.PassMissing{CubeRooter}(cuberoot)

@testset "deprecated" begin
# The (unexported) `Missings.T` was deprecated to `Missings.nonmissingtype`
for x in (Union{Int, Missing}, Any, Missing, Union{Array{Int}, Missing})
Expand Down

0 comments on commit 57113f0

Please sign in to comment.