Skip to content

Commit 3015cda

Browse files
authored
Merge pull request #3 from JuliaData/jq/dv
Allow DataAPI itself to own datavaluetype, nondatavaluetype, and unwrap
2 parents cc2d2de + 8b7b145 commit 3015cda

File tree

2 files changed

+30
-11
lines changed

2 files changed

+30
-11
lines changed

src/DataAPI.jl

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ For a type `T`, return the corresponding non-`DataValue` type, translating betwe
7272
For example, `nondatavaluetype(Int64)` returns `Int64`, while
7373
`nondatavaluetype(DataValue{Int64})` returns `Union{Int64, Missing}`.
7474
75-
This generic function is owned by Tables.jl, which is the sole provider of the default
76-
definition.
75+
This generic function is owned by DataAPI.jl itself, which is the sole provider of the
76+
default definition.
7777
"""
7878
function nondatavaluetype end
7979

80+
nondatavaluetype(::Type{T}) where {T} = T
81+
nondatavaluetype(::Type{Union{}}) = Union{}
82+
8083
"""
8184
datavaluetype(T)
8285
@@ -86,21 +89,26 @@ For a type `T`, return the corresponding `DataValue` type, translating between
8689
For example, `datavaluetype(Int64)` returns `Int64`, while
8790
`datavaluetype(Union{Int64, Missing})` returns `DataValue{Int64}`.
8891
89-
This generic function is owned by Tables.jl, which is the sole provider of the default
90-
definition.
92+
This generic function is owned by DataAPI.jl itself, which is the sole provider of the
93+
default definition.
9194
"""
9295
function datavaluetype end
9396

97+
datavaluetype(::Type{T}) where {T} = T
98+
datavaluetype(::Type{Union{}}) = Union{}
99+
94100
"""
95101
unwrap(x)
96102
97103
For a value `x`, potentially "unwrap" it from a `DataValue` or similar container.
98104
99-
This generic function is owned by Tables.jl, which is the sole provider of the default
100-
definition.
105+
This generic function is owned by DataAPI.jl itself, which is the sole provider of the
106+
default definition.
101107
"""
102108
function unwrap end
103109

110+
unwrap(x) = x
111+
104112
"""
105113
describe(io::IO, x)
106114

test/runtests.jl

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,23 @@ end
2727

2828
end
2929

30-
@testset "generic functions" begin
30+
@testset "nondatavaluetype" begin
3131

32-
@test length(methods(DataAPI.nondatavaluetype)) == 0
33-
@test length(methods(DataAPI.datavaluetype)) == 0
34-
@test length(methods(DataAPI.unwrap)) == 0
35-
@test length(methods(DataAPI.describe)) == 0
32+
@test DataAPI.nondatavaluetype(Int64) == Int64
33+
@test DataAPI.nondatavaluetype(Union{}) == Union{}
34+
35+
end
36+
37+
@testset "datavaluetype" begin
38+
39+
@test DataAPI.datavaluetype(Int64) == Int64
40+
@test DataAPI.datavaluetype(Union{}) == Union{}
41+
42+
end
43+
44+
@testset "unwrap" begin
45+
46+
@test DataAPI.unwrap(1) == 1
3647

3748
end
3849

0 commit comments

Comments
 (0)