Skip to content

Commit

Permalink
OrderedDict for dictrowtable (#277)
Browse files Browse the repository at this point in the history
* `OrderedDict` for `dictrowtable`

* Fixes docstrings on `dictcolumntable` and `dictrowtable`

* Test of `size` implementation on `GenericColumn` with Julia nightly

* Fallback from test in previous commit
  • Loading branch information
mathieu17g committed Mar 10, 2022
1 parent 57e2753 commit 138c5be
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/dicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit 138c5be

Please sign in to comment.