From 669a30810272b13a2c4a238d41a57c99027babfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Wed, 28 Sep 2022 10:20:55 +0200 Subject: [PATCH 01/10] update metadata API --- Project.toml | 2 +- src/DataAPI.jl | 57 ++++++++++++++++-------------------------------- test/runtests.jl | 32 +++++++++++++-------------- 3 files changed, 36 insertions(+), 55 deletions(-) diff --git a/Project.toml b/Project.toml index 5106aa0..9b720f8 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "DataAPI" uuid = "9a962f9c-6df0-11e9-0e5d-c546b8b5ee8a" authors = ["quinnj "] -version = "1.11.0" +version = "1.12.0" [compat] julia = "1" diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 9cc1dfc..81973c3 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -305,9 +305,8 @@ 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. 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 @@ -315,8 +314,7 @@ 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) @@ -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. $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 @@ -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]) @@ -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 diff --git a/test/runtests.jl b/test/runtests.jl index c8384de..833176d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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) == () From a5f3ca6937754e95bf4783febce855f3309a354b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Thu, 29 Sep 2022 21:57:20 +0200 Subject: [PATCH 02/10] Apply suggestions from code review Co-authored-by: Milan Bouchet-Valat --- src/DataAPI.jl | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 81973c3..0096c72 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -305,8 +305,7 @@ 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 error. -If `x` supports metadata, but does not have a mapping for `key` throw error. +Throw an error if `x` does not support metadata or does not have a mapping for `key`. 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 @@ -329,7 +328,7 @@ 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 error. +Throw an error if `x` does not support setting metadata. $STYLE_INFO """ From c9a12e42b7b736e3e1d690d3c9215925b4b4f010 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Thu, 29 Sep 2022 22:02:01 +0200 Subject: [PATCH 03/10] add default for `metadata` and `colmetadata` --- src/DataAPI.jl | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 0096c72..5812617 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -302,7 +302,7 @@ Passing `col` that is not a column of `x` throws an error. """ """ - metadata(x, key::AbstractString; style::Bool=false) + metadata(x, key::AbstractString, [default]; style::Bool=false) Return metadata value associated with object `x` for key `key`. Throw an error if `x` does not support metadata or does not have a mapping for `key`. @@ -312,6 +312,9 @@ style is an additional information about the kind of metadata that is stored for the `key`. $STYLE_INFO + +If `default` is passed then return it if mapping for `key` is missing. If +`style=true` return `(default, :default)`. """ function metadata end @@ -352,7 +355,7 @@ If `x` does not support metadata deletion throw error. function emptymetadata! end """ - colmetadata(x, col, key::AbstractString; style::Bool=false) + colmetadata(x, col, key::AbstractString, default; 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 error. If `x` @@ -366,6 +369,9 @@ style is an additional information about the kind of metadata that is stored for the `key`. $STYLE_INFO + +If `default` is passed then return it if mapping for `key` is missing. If +`style=true` return `(default, :default)`. """ function colmetadata end From 2ae70cfed76dc9e4adaf9027223559e1ddd01ef7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Fri, 30 Sep 2022 10:46:55 +0200 Subject: [PATCH 04/10] add metadatasupport --- src/DataAPI.jl | 77 ++++++++++++++++++++++++++++++------------------ test/runtests.jl | 31 ++++++++++++++++--- 2 files changed, 75 insertions(+), 33 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 5812617..1e3ae39 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -298,23 +298,46 @@ performed). All types supporting metadata allow at least this style. const COL_INFO = """ `col` must have a type that is supported by table `x` for column indexing. Following the Tables.jl contract `Symbol` and `Int` are always allowed. -Passing `col` that is not a column of `x` throws an error. +Throw an error if if `col`is not a column of `x`. """ +""" + metadatasupport(T::Type) + +Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` giving information if +values of type `T` support metadata. The `read` field indicates if +reading meteadata with the `metadata` and `metadatakeys` functions is supported. +The `write` field indicates if modifying metadata with the `metadata!`, +`deletemetadata!`, and `emptymetadata!` functions is supported. +""" +metadatasupport(::Type) == (read=false, write=false) + +""" + colmetadatasupport(T::Type) + +Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` giving information if +values of type `T` support column metadata. The `read` field indicates if +reading column meteadata with the `colmetadata` and `colmetadatakeys` functions +is supported. The `write` field indicates if modifying metadata with the +`colmetadata!`, `deletecolmetadata!`, and `emptycolmetadata!` functions is +supported. +""" +colmetadatasupport(::Type) == (read=false, write=false) + """ metadata(x, key::AbstractString, [default]; style::Bool=false) -Return metadata value associated with object `x` for key `key`. -Throw an error if `x` does not support metadata or does not have a mapping for `key`. +Return metadata value associated with object `x` for key `key`. Throw an error +if `x` does not support reading metadata or does not have a mapping for `key`. 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 is an additional information about the kind of metadata that is stored for +the `key`. $STYLE_INFO -If `default` is passed then return it if mapping for `key` is missing. If -`style=true` return `(default, :default)`. +If `default` is passed then return it if reading metadata is supported but +mapping for `key` is missing. If `style=true` return `(default, :default)`. """ function metadata end @@ -322,9 +345,10 @@ function metadata end metadatakeys(x) Return an iterator of metadata keys for which `metadata(x, key)` returns a -metadata value. If `x` does not support metadata return `()`. +metadata value. +Throw an error if `x` does not support reading metadata. """ -metadatakeys(::Any) = () +function metadatakeys end """ metadata!(x, key::AbstractString, value; style) @@ -342,7 +366,7 @@ function metadata! end 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 error. +Throw an error if `x` does not support metadata deletion. """ function deletemetadata! end @@ -350,7 +374,7 @@ function deletemetadata! end emptymetadata!(x) Delete all metadata for object `x`. -If `x` does not support metadata deletion throw error. +Throw an error if `x` does not support metadata deletion. """ function emptymetadata! end @@ -358,9 +382,8 @@ function emptymetadata! end colmetadata(x, col, key::AbstractString, default; 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 error. If `x` -supports metadata, but does not have a mapping for column `col` for `key` throw -error. +Throw an error if `x` does not support reading metadata for column `col` or `x` +supports reading metadata, but does not have a mapping for column `col` for `key`. $COL_INFO @@ -370,38 +393,34 @@ the `key`. $STYLE_INFO -If `default` is passed then return it if mapping for `key` is missing. If -`style=true` return `(default, :default)`. +If `default` is passed then return it if `x` supports reading metadata and has +column `col` but mapping for `key` is missing. +If `style=true` return `(default, :default)`. """ function colmetadata end """ colmetadatakeys(x, [col]) -If `col` is passed return an iterator of metadata keys for which `metadata(x, -col, key)` returns a metadata value. If `x` does not support metadata for column -`col` return `()`. +If `col` is passed return an iterator of metadata keys for which +`metadata(x, col, key)` returns a metadata value. Throw an error if `x` does not +support reading column metadata or if `col` is not a column of `x`. `col` must have a type that is supported by table `x` for column indexing. -Following the Tables.jl contract `Symbol` and `Int` are always allowed. Passing -`col` that is not a column of `x` either throws an error (this is a -preferred behavior if it is possible) or returns `()` (this duality is allowed -as some Tables.jl tables do not have a schema). +Following the Tables.jl contract `Symbol` and `Int` are always allowed. If `col` is not passed return an iterator of `col => colmetadatakeys(x, col)` pairs for all columns that have metadata, where `col` are `Symbol`. If `x` does not support column metadata return `()`. """ -colmetadatakeys(::Any, ::Int) = () -colmetadatakeys(::Any, ::Symbol) = () -colmetadatakeys(::Any) = () +function colmetadatakeys end """ colmetadata!(x, col, key::AbstractString, value; style) 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 error. +Throw an error if `x` does not support setting metadata for column `col`. $COL_INFO @@ -414,7 +433,7 @@ function colmetadata! end 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 error. +Throw an error if `x` does not support metadata deletion for column `col`. """ function deletecolmetadata! end @@ -423,7 +442,7 @@ function deletecolmetadata! end 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 error. +Throw an error if `x` does not support metadata deletion for column `col`. """ function emptycolmetadata! end diff --git a/test/runtests.jl b/test/runtests.jl index 833176d..ec41c2b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -21,10 +21,18 @@ struct TestMeta TestMeta() = new(Dict{String, Any}(), Dict{Symbol, Dict{String, Any}}()) end +DataAPI.metadatasupport(::Type{TestMeta}) = (read=true, write=true) +DataAPI.colmetadatasupport(::Type{TestMeta}) = (read=true, write=true) + function DataAPI.metadata(x::TestMeta, key::AbstractString; style::Bool=false) return style ? x.table[key] : x.table[key][1] end +function DataAPI.metadata(x::TestMeta, key::AbstractString, default; style::Bool=false) + haskey(x.table, key) && return DataAPI.metadata(x, key, style=style) + return style ? (default, :default) : default +end + DataAPI.metadatakeys(x::TestMeta) = keys(x.table) function DataAPI.metadata!(x::TestMeta, key::AbstractString, value; style) @@ -44,6 +52,11 @@ function DataAPI.colmetadata(x::TestMeta, col::Symbol, key::AbstractString; styl return style ? x.col[col][key] : x.col[col][key][1] end +function DataAPI.colmetadata(x::TestMeta, col::Symbol, key::AbstractString, default; style::Bool=false) + haskey(x.table, col) && haskey(x.table[col], key) && return DataAPI.metadata(x, key, style=style) + return style ? (default, :default) : default +end + function DataAPI.colmetadatakeys(x::TestMeta, col::Symbol) haskey(x.col, col) && return keys(x.col[col]) return () @@ -252,7 +265,7 @@ end @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 MethodError DataAPI.metadatakeys(1) @test_throws MethodError DataAPI.colmetadata!(1, :col, "a", 10, style=:default) @test_throws MethodError DataAPI.deletecolmetadata!(1, :col, "a") @@ -265,16 +278,24 @@ end @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) == () + @test_throws MethodError DataAPI.colmetadatakeys(1, :col) + @test_throws MethodError DataAPI.colmetadatakeys(1, 1) + @test_throws MethodError DataAPI.colmetadatakeys(1) + + @test DataAPI.metadatasupport(Int) == (read=false, write=false) + @test DataAPI.colmetadatasupport(Int) == (read=false, write=false) tm = TestMeta() + @test DataAPI.metadatasupport(TestMeta) == (read=false, write=false) + @test DataAPI.colmetadatasupport(TestMeta) == (read=false, write=false) + @test isempty(DataAPI.metadatakeys(tm)) @test DataAPI.metadata!(tm, "a", "100", style=:note) == tm @test collect(DataAPI.metadatakeys(tm)) == ["a"] @test_throws KeyError DataAPI.metadata(tm, "b") + @test DataAPI.metadata(tm, "b", 123) == 123 @test_throws KeyError DataAPI.metadata(tm, "b", style=true) + @test DataAPI.metadata(tm, "b", 123, style=true) == (123, :default) @test DataAPI.metadata(tm, "a") == "100" @test DataAPI.metadata(tm, "a", style=true) == ("100", :note) DataAPI.deletemetadata!(tm, "a") @@ -289,7 +310,9 @@ end @test [k => collect(v) for (k, v) in DataAPI.colmetadatakeys(tm)] == [:col => ["a"]] @test collect(DataAPI.colmetadatakeys(tm, :col)) == ["a"] @test_throws KeyError DataAPI.colmetadata(tm, :col, "b") + @test DataAPI.colmetadata(tm, :col, "b", 123) == 123 @test_throws KeyError DataAPI.colmetadata(tm, :col, "b", style=true) + @test DataAPI.colmetadata(tm, :col, "b", 123, style=true) == (123, :default) @test_throws KeyError DataAPI.colmetadata(tm, :col2, "a") @test_throws KeyError DataAPI.colmetadata(tm, :col2, "a", style=true) @test DataAPI.colmetadata(tm, :col, "a") == "100" From 9d95f1c284b72cd0c742c9457b602323e3d715e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Fri, 30 Sep 2022 10:57:13 +0200 Subject: [PATCH 05/10] fix typos --- src/DataAPI.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 1e3ae39..a39d8aa 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -310,7 +310,7 @@ reading meteadata with the `metadata` and `metadatakeys` functions is supported. The `write` field indicates if modifying metadata with the `metadata!`, `deletemetadata!`, and `emptymetadata!` functions is supported. """ -metadatasupport(::Type) == (read=false, write=false) +metadatasupport(::Type) = (read=false, write=false) """ colmetadatasupport(T::Type) @@ -322,7 +322,7 @@ is supported. The `write` field indicates if modifying metadata with the `colmetadata!`, `deletecolmetadata!`, and `emptycolmetadata!` functions is supported. """ -colmetadatasupport(::Type) == (read=false, write=false) +colmetadatasupport(::Type) = (read=false, write=false) """ metadata(x, key::AbstractString, [default]; style::Bool=false) From 9d9310c890e48c31bbd87294e690ac8993d0ae63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Fri, 30 Sep 2022 10:57:31 +0200 Subject: [PATCH 06/10] fix typos --- test/runtests.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index ec41c2b..5b4fc3b 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -286,8 +286,8 @@ end @test DataAPI.colmetadatasupport(Int) == (read=false, write=false) tm = TestMeta() - @test DataAPI.metadatasupport(TestMeta) == (read=false, write=false) - @test DataAPI.colmetadatasupport(TestMeta) == (read=false, write=false) + @test DataAPI.metadatasupport(TestMeta) == (read=true, write=true) + @test DataAPI.colmetadatasupport(TestMeta) == (read=true, write=true) @test isempty(DataAPI.metadatakeys(tm)) @test DataAPI.metadata!(tm, "a", "100", style=:note) == tm From ddd04958748fdcb345c9b5999878e2f78c300f6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Fri, 30 Sep 2022 18:12:37 +0200 Subject: [PATCH 07/10] Apply suggestions from code review Co-authored-by: Milan Bouchet-Valat --- src/DataAPI.jl | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index a39d8aa..1ddaff3 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -298,29 +298,31 @@ performed). All types supporting metadata allow at least this style. const COL_INFO = """ `col` must have a type that is supported by table `x` for column indexing. Following the Tables.jl contract `Symbol` and `Int` are always allowed. -Throw an error if if `col`is not a column of `x`. +Throw an error if `col`is not a column of `x`. """ """ metadatasupport(T::Type) -Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` giving information if -values of type `T` support metadata. The `read` field indicates if -reading meteadata with the `metadata` and `metadatakeys` functions is supported. -The `write` field indicates if modifying metadata with the `metadata!`, -`deletemetadata!`, and `emptymetadata!` functions is supported. +Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` indicating whether +values of type `T` support metadata. The `read` field indicates whether +reading metadata with the [`metadata`](@ref) and [`metadatakeys`]](@ref) +functions is supported. +The `write` field indicates whether modifying metadata with the [`metadata!`](@ref), +[`deletemetadata!`](@ref), and [`emptymetadata!`](@ref) functions is supported. """ metadatasupport(::Type) = (read=false, write=false) """ colmetadatasupport(T::Type) -Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` giving information if -values of type `T` support column metadata. The `read` field indicates if -reading column meteadata with the `colmetadata` and `colmetadatakeys` functions -is supported. The `write` field indicates if modifying metadata with the -`colmetadata!`, `deletecolmetadata!`, and `emptycolmetadata!` functions is -supported. + +Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` indicating whether +values of type `T` support column metadata. The `read` field indicates whether +reading metadata with the [`colmetadata`](@ref) and [`colmetadatakeys`](@ref) +functions is supported. +The `write` field indicates whether modifying metadata with the [`colmetadata!`](@ref), +[`deletecolmetadata!`](@ref), and [`emptycolmetadata!`](@ref) functions is supported. """ colmetadatasupport(::Type) = (read=false, write=false) @@ -379,7 +381,7 @@ Throw an error if `x` does not support metadata deletion. function emptymetadata! end """ - colmetadata(x, col, key::AbstractString, default; style::Bool=false) + colmetadata(x, col, key::AbstractString, [default]; style::Bool=false) Return metadata value associated with table `x` for column `col` and key `key`. Throw an error if `x` does not support reading metadata for column `col` or `x` From 23f431487c409733a9239ea95be8ae5cb2190fd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Fri, 30 Sep 2022 18:51:54 +0200 Subject: [PATCH 08/10] Apply suggestions from code review Co-authored-by: Milan Bouchet-Valat --- src/DataAPI.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 1ddaff3..4379936 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -298,7 +298,7 @@ performed). All types supporting metadata allow at least this style. const COL_INFO = """ `col` must have a type that is supported by table `x` for column indexing. Following the Tables.jl contract `Symbol` and `Int` are always allowed. -Throw an error if `col`is not a column of `x`. +Throw an error if `col` is not a column of `x`. """ """ From 1dd48875d64a24647900d0e2bfa2437aac13a605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Mon, 3 Oct 2022 08:27:32 +0200 Subject: [PATCH 09/10] Update src/DataAPI.jl --- src/DataAPI.jl | 1 - 1 file changed, 1 deletion(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index 4379936..e616ab5 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -316,7 +316,6 @@ metadatasupport(::Type) = (read=false, write=false) """ colmetadatasupport(T::Type) - Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` indicating whether values of type `T` support column metadata. The `read` field indicates whether reading metadata with the [`colmetadata`](@ref) and [`colmetadatakeys`](@ref) From 3d1671b0946a48b99d8ede713842aff2fcbc7ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bogumi=C5=82=20Kami=C5=84ski?= Date: Mon, 3 Oct 2022 09:04:13 +0200 Subject: [PATCH 10/10] minor docstring fixes --- src/DataAPI.jl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/DataAPI.jl b/src/DataAPI.jl index e616ab5..33076fa 100644 --- a/src/DataAPI.jl +++ b/src/DataAPI.jl @@ -305,9 +305,11 @@ Throw an error if `col` is not a column of `x`. metadatasupport(T::Type) Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` indicating whether -values of type `T` support metadata. The `read` field indicates whether -reading metadata with the [`metadata`](@ref) and [`metadatakeys`]](@ref) -functions is supported. +values of type `T` support metadata. + +The `read` field indicates whether reading metadata with the [`metadata`](@ref) +and [`metadatakeys`]](@ref) functions is supported. + The `write` field indicates whether modifying metadata with the [`metadata!`](@ref), [`deletemetadata!`](@ref), and [`emptymetadata!`](@ref) functions is supported. """ @@ -317,9 +319,11 @@ metadatasupport(::Type) = (read=false, write=false) colmetadatasupport(T::Type) Return a `NamedTuple{(:read, :write), Tuple{Bool, Bool}}` indicating whether -values of type `T` support column metadata. The `read` field indicates whether -reading metadata with the [`colmetadata`](@ref) and [`colmetadatakeys`](@ref) -functions is supported. +values of type `T` support column metadata. + +The `read` field indicates whether reading metadata with the [`colmetadata`](@ref) +and [`colmetadatakeys`](@ref) functions is supported. + The `write` field indicates whether modifying metadata with the [`colmetadata!`](@ref), [`deletecolmetadata!`](@ref), and [`emptycolmetadata!`](@ref) functions is supported. """