-
Notifications
You must be signed in to change notification settings - Fork 13
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
add metadata
#48
add metadata
#48
Changes from 40 commits
ff31aa7
96b1e39
f7cb305
77e3604
7d53c4b
c28d7c5
37ef469
4617f60
5a493b6
aa15118
992d1e8
bbeda80
45b433a
6897052
2ac9c88
43cec64
320f9db
3e7ed28
f2e4eb1
76bfba5
9db264a
b863431
0df50d7
0c685ad
0d75fce
40edcd9
c3d7f94
a75b965
47629ed
51add3c
f0c9fc0
be8102f
435e062
56f98b7
b909f01
3e32920
b2d2636
a589cee
c612a12
15303a6
3b61e32
edfd350
b33b62e
c5f699e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.10.0" | ||
version = "1.11.0" | ||
|
||
[compat] | ||
julia = "1" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,4 +287,158 @@ using a `sink` function to materialize the table. | |
""" | ||
function allcombinations end | ||
|
||
const STYLE_INFO = """ | ||
One of the uses of the metadata `style` is decision | ||
how the metadata should be propagated when `x` is transformed. This interface | ||
defines the `:none` style that indicates that metadata should not be propagated | ||
under transformations. 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. | ||
""" | ||
|
||
""" | ||
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 `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")) | ||
|
||
""" | ||
metadatakeys(x) | ||
|
||
Return an iterator of metadata keys for which `metadata(x, key)` returns a | ||
metadata value. If `x` does not support metadata return `()`. | ||
""" | ||
metadatakeys(::Any) = () | ||
|
||
""" | ||
metadata!(x, key::AbstractString, value; style) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking about it, maybe the syntax would be more natural as A counter-argument is that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As a first reaction it makes sense. My only reservation was that in DataFrames.jl The question is how would it look for
(which does not look that nice) Also note that In summary - I would keep the things as they are here and consider what we design here a low-level API. I assume that the extra new package planned (tentatively named TableMetadataTools.jl) will provide convenient high-level functions. In practice I even expect that if we define there:
this will cover 95% of use cases of metadata in practice. In summary - I propose to discuss a convenience high-level API in TableMetadataTools.jl, as I expect that in that package we will drop the requirement to specify |
||
|
||
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`. | ||
|
||
$STYLE_INFO | ||
""" | ||
metadata!(::T, ::AbstractString, ::Any; style) where {T} = | ||
throw(ArgumentError("Objects of type $T do not support setting metadata")) | ||
|
||
""" | ||
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 `key` is not passed delete all metadata for object `x`. | ||
bkamins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
If `x` does not support metadata deletion throw `ArgumentError`. | ||
""" | ||
deletemetadata!(::T, ::AbstractString) where {T} = | ||
throw(ArgumentError("Objects of type $T do not support metadata deletion")) | ||
|
||
""" | ||
emptymetadata!(x) | ||
|
||
Delete all metadata for object `x`. | ||
If `x` does not support metadata deletion throw `ArgumentError`. | ||
""" | ||
emptymetadata!(::T) where {T} = | ||
throw(ArgumentError("Objects of type $T do not support metadata deletion")) | ||
|
||
bkamins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
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` | ||
supports metadata, but does not have a mapping for column `col` for `key` throw | ||
`KeyError`. | ||
|
||
$COL_INFO | ||
|
||
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 | ||
""" | ||
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")) | ||
|
||
""" | ||
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 `()`. | ||
|
||
`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). | ||
|
||
If `col` is not passed return an iterator of `col => colmetadatakeys(x, col)` | ||
pairs for all columns that have metadata. If `x` does not support column | ||
metadata return `()`. | ||
bkamins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
colmetadatakeys(::Any, ::Int) = () | ||
colmetadatakeys(::Any, ::Symbol) = () | ||
colmetadatakeys(::Any) = () | ||
|
||
""" | ||
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 `ArgumentError`. | ||
|
||
$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")) | ||
|
||
""" | ||
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`. | ||
""" | ||
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")) | ||
|
||
""" | ||
emptycolmetadata!(x, [col]) | ||
|
||
bkamins marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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")) | ||
|
||
end # module |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nalimilan - maybe we should make this description more precise? Currently in DataFrames.jl I needed to make a decision when
:none
metadata is kept and it is kept only in two cases:DataFrame
constructor;copy
;all other operations drop all
:none
metadata. So, essentially both table level and column level:none
metadata are attached to a concrete instance of a table or its copies (this is a safest approach, i.e. making sure that indeed when metadata could be invalidated it is dropped). Are we in agreement here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given no response I will make the definition more precise.