Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update metadata API #53

Merged
merged 10 commits into from
Oct 3, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DataAPI"
uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a"
authors = ["quinnj <[email protected]>"]
version = "1.11.0"
version = "1.12.0"

[compat]
julia = "1"
Expand Down
57 changes: 19 additions & 38 deletions src/DataAPI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -305,18 +305,16 @@ Passing `col` that is not a column of `x` throws an error.
metadata(x, key::AbstractString; style::Bool=false)

Return metadata value associated with object `x` for key `key`.
If `x` does not support metadata throw `ArgumentError`.
If `x` supports metadata, but does not have a mapping for `key` throw
`KeyError`.
If `x` does not support metadata throw error.
If `x` supports metadata, but does not have a mapping for `key` throw error.
bkamins marked this conversation as resolved.
Show resolved Hide resolved

If `style=true` return a tuple of metadata value and metadata style. Metadata
style is an additional information about the kind of metadata that is stored
for the `key`.

$STYLE_INFO
"""
metadata(::T, ::AbstractString; style::Bool=false) where {T} =
throw(ArgumentError("Objects of type $T do not support getting metadata"))
function metadata end

"""
metadatakeys(x)
Expand All @@ -331,39 +329,36 @@ metadatakeys(::Any) = ()

Set metadata for object `x` for key `key` to have value `value`
and style `style` and return `x`.
If `x` does not support setting metadata throw `ArgumentError`.
If `x` does not support setting metadata throw error.
bkamins marked this conversation as resolved.
Show resolved Hide resolved

$STYLE_INFO
"""
metadata!(::T, ::AbstractString, ::Any; style) where {T} =
throw(ArgumentError("Objects of type $T do not support setting metadata"))
function metadata! end

"""
deletemetadata!(x, key::AbstractString)

Delete metadata for object `x` for key `key` and return `x`
(if metadata for `key` is not present do not perform any action).
If `x` does not support metadata deletion throw `ArgumentError`.
If `x` does not support metadata deletion throw error.
"""
deletemetadata!(::T, ::AbstractString) where {T} =
throw(ArgumentError("Objects of type $T do not support metadata deletion"))
function deletemetadata! end

"""
emptymetadata!(x)

Delete all metadata for object `x`.
If `x` does not support metadata deletion throw `ArgumentError`.
If `x` does not support metadata deletion throw error.
"""
emptymetadata!(::T) where {T} =
throw(ArgumentError("Objects of type $T do not support metadata deletion"))
function emptymetadata! end

"""
colmetadata(x, col, key::AbstractString; style::Bool=false)

Return metadata value associated with table `x` for column `col` and key `key`.
If `x` does not support metadata for column `col` throw `ArgumentError`. If `x`
If `x` does not support metadata for column `col` throw error. If `x`
supports metadata, but does not have a mapping for column `col` for `key` throw
`KeyError`.
error.

$COL_INFO

Expand All @@ -373,10 +368,7 @@ the `key`.

$STYLE_INFO
"""
colmetadata(::T, ::Int, ::AbstractString; style::Bool=false) where {T} =
throw(ArgumentError("Objects of type $T do not support getting column metadata"))
colmetadata(::T, ::Symbol, ::AbstractString; style::Bool=false) where {T} =
throw(ArgumentError("Objects of type $T do not support getting column metadata"))
function colmetadata end

"""
colmetadatakeys(x, [col])
Expand Down Expand Up @@ -404,41 +396,30 @@ colmetadatakeys(::Any) = ()

Set metadata for table `x` for column `col` for key `key` to have value `value`
and style `style` and return `x`.
If `x` does not support setting metadata for column `col` throw `ArgumentError`.
If `x` does not support setting metadata for column `col` throw error.

$COL_INFO

$STYLE_INFO
"""
colmetadata!(::T, ::Int, ::AbstractString, ::Any; style) where {T} =
throw(ArgumentError("Objects of type $T do not support setting metadata"))
colmetadata!(::T, ::Symbol, ::AbstractString, ::Any; style) where {T} =
throw(ArgumentError("Objects of type $T do not support setting metadata"))
function colmetadata! end

"""
deletecolmetadata!(x, col, key::AbstractString)

Delete metadata for table `x` for column `col` for key `key` and return `x`
(if metadata for `key` is not present do not perform any action).
If `x` does not support metadata deletion for column `col` throw `ArgumentError`.
If `x` does not support metadata deletion for column `col` throw error.
"""
deletecolmetadata!(::T, ::Symbol, ::AbstractString) where {T} =
throw(ArgumentError("Objects of type $T do not support metadata deletion"))
deletecolmetadata!(::T, ::Int, ::AbstractString) where {T} =
throw(ArgumentError("Objects of type $T do not support metadata deletion"))
function deletecolmetadata! end

"""
emptycolmetadata!(x, [col])

Delete all metadata for table `x` for column `col`.
If `col` is not passed delete all column level metadata for table `x`.
If `x` does not support metadata deletion for column `col` throw `ArgumentError`.
"""
emptycolmetadata!(::T, ::Symbol) where {T} =
throw(ArgumentError("Objects of type $T do not support metadata deletion"))
emptycolmetadata!(::T, ::Int) where {T} =
throw(ArgumentError("Objects of type $T do not support metadata deletion"))
emptycolmetadata!(::T) where {T} =
throw(ArgumentError("Objects of type $T do not support metadata deletion"))
If `x` does not support metadata deletion for column `col` throw error.
"""
function emptycolmetadata! end

end # module
32 changes: 16 additions & 16 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -247,24 +247,24 @@ end
end

@testset "metadata" begin
@test_throws ArgumentError DataAPI.metadata!(1, "a", 10, style=:default)
@test_throws ArgumentError DataAPI.deletemetadata!(1, "a")
@test_throws ArgumentError DataAPI.emptymetadata!(1)
@test_throws ArgumentError DataAPI.metadata(1, "a")
@test_throws ArgumentError DataAPI.metadata(1, "a", style=true)
@test_throws MethodError DataAPI.metadata!(1, "a", 10, style=:default)
@test_throws MethodError DataAPI.deletemetadata!(1, "a")
@test_throws MethodError DataAPI.emptymetadata!(1)
@test_throws MethodError DataAPI.metadata(1, "a")
@test_throws MethodError DataAPI.metadata(1, "a", style=true)
@test DataAPI.metadatakeys(1) == ()

@test_throws ArgumentError DataAPI.colmetadata!(1, :col, "a", 10, style=:default)
@test_throws ArgumentError DataAPI.deletecolmetadata!(1, :col, "a")
@test_throws ArgumentError DataAPI.emptycolmetadata!(1, :col)
@test_throws ArgumentError DataAPI.deletecolmetadata!(1, 1, "a")
@test_throws ArgumentError DataAPI.emptycolmetadata!(1, 1)
@test_throws ArgumentError DataAPI.emptycolmetadata!(1)
@test_throws ArgumentError DataAPI.colmetadata(1, :col, "a")
@test_throws ArgumentError DataAPI.colmetadata(1, :col, "a", style=true)
@test_throws ArgumentError DataAPI.colmetadata!(1, 1, "a", 10, style=:default)
@test_throws ArgumentError DataAPI.colmetadata(1, 1, "a")
@test_throws ArgumentError DataAPI.colmetadata(1, 1, "a", style=true)
@test_throws MethodError DataAPI.colmetadata!(1, :col, "a", 10, style=:default)
@test_throws MethodError DataAPI.deletecolmetadata!(1, :col, "a")
@test_throws MethodError DataAPI.emptycolmetadata!(1, :col)
@test_throws MethodError DataAPI.deletecolmetadata!(1, 1, "a")
@test_throws MethodError DataAPI.emptycolmetadata!(1, 1)
@test_throws MethodError DataAPI.emptycolmetadata!(1)
@test_throws MethodError DataAPI.colmetadata(1, :col, "a")
@test_throws MethodError DataAPI.colmetadata(1, :col, "a", style=true)
@test_throws MethodError DataAPI.colmetadata!(1, 1, "a", 10, style=:default)
@test_throws MethodError DataAPI.colmetadata(1, 1, "a")
@test_throws MethodError DataAPI.colmetadata(1, 1, "a", style=true)
@test DataAPI.colmetadatakeys(1, :col) == ()
@test DataAPI.colmetadatakeys(1, 1) == ()
@test DataAPI.colmetadatakeys(1) == ()
Expand Down