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
Redesign ReadStatMeta
and add ReadStatColMeta
for DataAPI.jl v1.13
#6
Changes from 1 commit
3ec444b
d96dd01
f6fc67a
b826c8d
6dc02e8
5520ea4
d47bc11
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 |
---|---|---|
|
@@ -123,6 +123,53 @@ Retrieve the metadata parsed from a data file. | |
""" | ||
getmeta(tb::ReadStatTable) = getfield(tb, :meta) | ||
|
||
hasmetadata(tb::ReadStatTable) = getmeta(tb) !== nothing | ||
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. it should be |
||
hasmetadata(tb::ReadStatTable, col::Symbol) = getmeta(tb) !== nothing && haskey(tb, col) | ||
|
||
function metadata(tb::ReadStatTable) | ||
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. also |
||
meta = getmeta(tb) | ||
meta === nothing && throw(ArgumentError("File has no metadata")) | ||
|
||
ret = Dict{String, Any}("file_modified" => meta.timestamp, | ||
"file_extension" => meta.fileext) | ||
|
||
label = meta.filelabel | ||
if label != "" | ||
ret["label"] = label | ||
end | ||
|
||
return ret | ||
end | ||
|
||
function metadata(tb::ReadStatTable, col::Symbol) | ||
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. this should be |
||
meta = getmeta(tb) | ||
meta === nothing && throw(ArgumentError("File has no metadata")) | ||
haskey(tb, col) || throw(ArgumentError("File has no column :$col")) | ||
|
||
ret = Dict{String, Any}() | ||
|
||
format = meta.formats[col] | ||
if format != "" | ||
ret["variable_format"] = format | ||
end | ||
|
||
label = meta.labels[col] | ||
if label != "" | ||
ret["label"] = label | ||
end | ||
|
||
# ReadStat.jl does not handle value labels for SAS at this moment | ||
if meta.fileext != ".xpt" && meta.fileext != ".sas7bdat" | ||
val_label = get(meta.val_label_keys, col, nothing) | ||
if val_label != "" | ||
ret["value_label_name"] = val_label | ||
ret["value_labels"] = meta.val_label_dict[val_label] | ||
end | ||
end | ||
|
||
return ret | ||
end | ||
|
||
varlabels(tb::ReadStatTable) = varlabels(getmeta(tb)) | ||
varformats(tb::ReadStatTable) = varformats(getmeta(tb)) | ||
val_label_keys(tb::ReadStatTable) = val_label_keys(getmeta(tb)) | ||
|
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.
I would prepare this PR against DataAPI.jl 1.13 (it will be released this week)