Skip to content

Commit

Permalink
bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
bramtayl committed Nov 3, 2018
1 parent 2a1ec5a commit 099f1f4
Showing 1 changed file with 3 additions and 28 deletions.
31 changes: 3 additions & 28 deletions src/LightQuery.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ julia> order_by((a = [1, 2], b = [2, 1]), :b)
```
"""
function order_by(data::NamedTuple, columns...)
order = sortperm(zip(select(data, columns...)...))
order = sortperm(collect(zip(select(data, columns...)...)))
map(column -> column[order], data)
end

Expand Down Expand Up @@ -183,7 +183,7 @@ julia> group_by((a = [1, 1, 2, 2], b = [1, 2, 3, 4]), :a)
```
"""
function group_by(data::NamedTuple, columns...)
ranges = get_groups(zip(select(data, columns...)...))
ranges = get_groups(collect(zip(select(data, columns...)...)))
rows(map(column -> map(range -> column[range], ranges), data))
end

Expand Down Expand Up @@ -230,37 +230,14 @@ julia> remove((a = 1, b = 2), :b)
"""
remove(data, columns...) = Base.structdiff(data, NamedTuple{columns})

export gather
"""
gather(data, columns...)
```jldoctest
julia> using LightQuery
julia> gather((a = 1, b = 2, c = 3), :b, :c)
((a = 1, key = :b, value = 2), (a = 1, key = :c, value = 3))
```
"""
function gather(data::NamedTuple, columns...)
rest = remove(data, columns...)
map(
column -> merge(rest, (key = column, value = data[column])),
columns
)
end

export pretty
"""
pretty(data)
```jldoctest
julia> using LightQuery
julia> pretty([(a = 1, b = 2), (a = 2, b = 1)])
| :a | :b |
| ---:| ---:|
| 1 | 2 |
| 2 | 1 |
julia> pretty([(a = 1, b = 2), (a = 2, b = 1)]);
```
"""
function pretty(data)
Expand All @@ -270,6 +247,4 @@ function pretty(data)
MD(Table(result, map(column -> :r, first_row)))
end



end

0 comments on commit 099f1f4

Please sign in to comment.