Better methods for showing metadata

Open
#3 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
35/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
julia
Domain
data

Research direction

Start by reviewing the existing colmetadata API and how names(df) exposes table columns. Compare the proposed showcolmetadata overloads and their example output, then check the current tests or documentation for metadata display; done means the requested column and label combinations are supported with readable tabular output.

Written by the indexing model from the issue text.

Description

I'm using metadata for the first time today (I usually use Stata and R for data cleaning) and I found it helpful to define the following functions to make it easier to see metadata

function showcolmetadata(df, col::Union{AbstractString, Symbol}, label::AbstractString)
    colmetadata(df, col, label)
end

function showcolmetadata(df, cols::AbstractVector{<:Union{AbstractString, Symbol}}, label::AbstractString)
    labvals = [colmetadata(df, col, label) for col in cols]
    nt = (; :variable => cols, Symbol(label) => labvals)
    pretty_table(nt; nosubheader = true, crop = :horizontal, alignment = [:l, :l])
end

function showcolmetadata(df, col::Union{AbstractString, Symbol}, labels::AbstractVector{<:AbstractString})
    labvals = [colmetadata(df, col, label) for label in labels]
    nt(; :label => labels, :value => labvals)
    pretty_table(nt; nosubheader = true, tile = "colmetadata for $col",  crop = :horizontal, alignment = [:l, :l])
end

function showcolmetadata(df, cols::Colon, label::AbstractString)
    showcolmetadata(df, names(df), label)
end

function showcolmetadata(df, col::Union{AbstractString, Symbol}, labels::Colon)
    d = colmetadata(df, col)
    labnames = names(d)
    showcolmetadata(df, col, labnames)
end

They would be used like following: You can see that the column names are pretty uninformative in the Penn World Tables, exactly the kind of situation metadata is great for.

julia> showcolmetadata(pwt[:, 1:10], :, "label")
┌───────────────┬──────────────────────────────────────────────────────────
│ variable      │ label                                                   ⋯
├───────────────┼──────────────────────────────────────────────────────────
│ countrycode   │ 3-letter ISO country code                               ⋯
│ country       │ Country name                                            ⋯
│ currency_unit │ Currency unit                                           ⋯
│ year          │ Year                                                    ⋯
│ rgdpe         │ Expenditure-side real GDP at chained PPPs (in mil. 2017 ⋯
│ rgdpo         │ Output-side real GDP at chained PPPs (in mil. 2017US$)  ⋯
│ pop           │ Population (in millions)                                ⋯
│ emp           │ Number of persons engaged (in millions)                 ⋯
│ avh           │ Average annual hours worked by persons engaged (source: ⋯
│ hc            │ Human capital index, see note hc                        ⋯
└───────────────┴──────────────────────────────────────────────────────────
                                                           1 column omitted

Dominant language
Julia
Stars
19
Forks
1
PR merge metrics
No merged PRs in 30d

Getting set up

This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from JuliaData/TableMetadataTools.jl

All issues in JuliaData/TableMetadataTools.jl

Similar issues

More Julia issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.