From 138c5beab96df972c80e1e9ea6239429cc4ddcb0 Mon Sep 17 00:00:00 2001 From: mathieu17g <72861595+mathieu17g@users.noreply.github.com> Date: Thu, 10 Mar 2022 22:50:59 +0100 Subject: [PATCH] `OrderedDict` for `dictrowtable` (#277) * `OrderedDict` for `dictrowtable` * Fixes docstrings on `dictcolumntable` and `dictrowtable` * Test of `size` implementation on `GenericColumn` with Julia nightly * Fallback from test in previous commit --- src/dicts.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dicts.jl b/src/dicts.jl index 7f377f5..292adb8 100644 --- a/src/dicts.jl +++ b/src/dicts.jl @@ -7,7 +7,7 @@ end Tables.dictcolumntable(x) => Tables.DictColumnTable Take any Tables.jl-compatible source `x` and return a `DictColumnTable`, which -can be thought of as a `Dict` mapping column names as `Symbol`s to `AbstractVector`s. +can be thought of as a `OrderedDict` mapping column names as `Symbol`s to `AbstractVector`s. The order of the input table columns is preserved via the `Tables.schema(::DictColumnTable)`. For "schema-less" input tables, `dictcolumntable` employs a "column unioning" behavior, @@ -126,7 +126,7 @@ end Tables.dictrowtable(x) => Tables.DictRowTable Take any Tables.jl-compatible source `x` and return a `DictRowTable`, which -can be thought of as a `Vector` of `Dict` rows mapping column names as `Symbol`s to values. +can be thought of as a `Vector` of `OrderedDict` rows mapping column names as `Symbol`s to values. The order of the input table columns is preserved via the `Tables.schema(::DictRowTable)`. For "schema-less" input tables, `dictrowtable` employs a "column unioning" behavior, @@ -141,12 +141,12 @@ the union behavior is needed. function dictrowtable(x) names = Symbol[] seen = Set{Symbol}() - types = Dict{Symbol, Type}() + types = OrderedDict{Symbol, Type}() r = rows(x) L = Base.IteratorSize(typeof(r)) - out = Vector{Dict{Symbol, Any}}(undef, Base.haslength(r) ? length(r) : 0) + out = Vector{OrderedDict{Symbol, Any}}(undef, Base.haslength(r) ? length(r) : 0) for (i, drow) in enumerate(r) - row = Dict{Symbol, Any}(nm => getcolumn(drow, nm) for nm in columnnames(drow)) + row = OrderedDict{Symbol, Any}(nm => getcolumn(drow, nm) for nm in columnnames(drow)) add!(row, 0, :_, out, L, i) if isempty(names) for (k, v) in row