Skip to content
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

[AUTO] Format files using DocumentFormat #300

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 101 additions & 101 deletions benchmark/Rdatatable.jl

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions docs/make.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using Documenter, Query, DataFrames

makedocs(
modules = [Query],
sitename = "Query.jl",
modules=[Query],
sitename="Query.jl",
analytics="UA-132838790-1",
pages = [
pages=[
"Introduction" => "index.md",
"Getting Started" => "gettingstarted.md",
"Standalone Query Commands" => "standalonequerycommands.md",
Expand All @@ -16,5 +16,5 @@ makedocs(
)

deploydocs(
repo = "github.com/queryverse/Query.jl.git"
repo="github.com/queryverse/Query.jl.git"
)
4 changes: 2 additions & 2 deletions example/01-DataFrame.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ using DataFrames
df = DataFrame(name=["John", "Sally", "Kirk"], age=[23., 42., 59.], children=[3,5,2])

x = @from i in df begin
@where i.age>30. && i.children > 2
@select {Name=lowercase(i.name)}
@where i.age > 30. && i.children > 2
@select {Name = lowercase(i.name)}
@collect DataFrame
end

Expand Down
12 changes: 6 additions & 6 deletions example/02-Dict.jl
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
using Query
using DataFrames

source = Dict("John"=>34., "Sally"=>56.)
source = Dict("John" => 34., "Sally" => 56.)

result = @from i in source begin
@where i.second>36.
@select {Name=lowercase(i.first)}
@collect DataFrame
@where i.second > 36.
@select {Name = lowercase(i.first)}
@collect DataFrame
end

println(result)

result = @from i in source begin
@where i.second>36.
@select {Name=lowercase(i.first)}
@where i.second > 36.
@select {Name = lowercase(i.first)}
@collect
end

Expand Down
8 changes: 4 additions & 4 deletions example/03-Array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ push!(source, Person("John", ["Sally", "Miles", "Frank"]))
push!(source, Person("Sally", ["Don", "Martin"]))

result = @from i in source begin
@where length(i.Friends) > 2
@select {i.Name, Friendcount=length(i.Friends)}
@collect
@where length(i.Friends) > 2
@select {i.Name, Friendcount = length(i.Friends)}
@collect
end

println(result)

result = @from i in source begin
@where length(i.Friends) > 2
@select {i.Name, Friendcount=length(i.Friends)}
@select {i.Name, Friendcount = length(i.Friends)}
@collect DataFrame
end

Expand Down
4 changes: 2 additions & 2 deletions example/05-NA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ using DataFrames
df = DataFrame(name=["John", missing, "Kirk"], age=[23., 42., 59.], children=[3,5,2])

x = @from i in df begin
@where i.age>30 && i.children >2
@select {Name=lowercase(i.name)}
@where i.age > 30 && i.children > 2
@select {Name = lowercase(i.name)}
@collect DataFrame
end

Expand Down
4 changes: 2 additions & 2 deletions example/08-join.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ df1 = DataFrame(a=[1,2,3], b=[1.,2.,3.])
df2 = DataFrame(c=[2.,4.,2.], d=["John", "Jim","Sally"])

x = @from i in df1 begin
@join j in df2 on i.a equals convert(Int,j.c)
@select {i.a,i.b,j.c,j.d,e="Name: $(j.d)"}
@join j in df2 on i.a equals convert(Int, j.c)
@select {i.a,i.b,j.c,j.d,e = "Name: $(j.d)"}
@collect DataFrame
end

Expand Down
2 changes: 1 addition & 1 deletion example/09-let.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ x = @from i in df begin
@let count = length(i.name)
@let kids_per_year = i.children / i.age
@where count > 4
@select {Name=i.name, Count=count, KidsPerYear=kids_per_year}
@select {Name = i.name, Count = count, KidsPerYear = kids_per_year}
@collect DataFrame
end

Expand Down
6 changes: 3 additions & 3 deletions example/10-orderby.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ df = DataFrame(name=["John", "Sally", "Kirk"], age=[23., 42., 59.], children=[3,

x = @from i in df begin
@orderby i.age
@select {Name=lowercase(i.name)}
@select {Name = lowercase(i.name)}
@collect DataFrame
end

println(x)

x = @from i in df begin
@orderby descending(i.age)
@select {Name=lowercase(i.name)}
@select {Name = lowercase(i.name)}
@collect DataFrame
end

println(x)

x = @from i in df begin
@orderby ascending(i.age)
@select {Name=lowercase(i.name)}
@select {Name = lowercase(i.name)}
@collect DataFrame
end

Expand Down
4 changes: 2 additions & 2 deletions example/13-selectmany.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ end

println(q)

source_dict = Dict(:a=>[1,2,3], :b=>[4,5])
source_dict = Dict(:a => [1,2,3], :b => [4,5])

q = @from i in source_dict begin
@from j in i.second
@select {Key=i.first,Value=j}
@select {Key = i.first,Value = j}
@collect DataFrame
end

Expand Down
2 changes: 1 addition & 1 deletion example/15-groupinto.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ df = DataFrame(name=["John", "Sally", "Kirk"], age=[23., 42., 59.], children=[3,

x = @from i in df begin
@group i by i.children into g
@select {Key=key(g),Count=length(g)}
@select {Key = key(g),Count = length(g)}
@collect DataFrame
end

Expand Down
6 changes: 3 additions & 3 deletions example/17-groupjoin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ df1 = DataFrame(a=[1,2,3], b=[1.,2.,3.])
df2 = DataFrame(c=[2.,4.,2.], d=["John", "Jim","Sally"])

x = @from i in df1 begin
@join j in df2 on i.a equals convert(Int,j.c) into k
@where i.a>1
@select {t1=i,t2=k}
@join j in df2 on i.a equals convert(Int, j.c) into k
@where i.a > 1
@select {t1 = i,t2 = k}
@collect DataFrame
end

Expand Down
2 changes: 1 addition & 1 deletion example/18-orderby-nested.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using Query
using DataFrames

df = DataFrame(a=[2,1,1,2,1,3],b=[2,2,1,1,3,2])
df = DataFrame(a=[2,1,1,2,1,3], b=[2,2,1,1,3,2])

x = @from i in df begin
@orderby descending(i.a), i.b
Expand Down
2 changes: 1 addition & 1 deletion example/23-dict-sink.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using DataFrames
df = DataFrame(name=["John", "Sally", "Kirk"], age=[23., 42., 59.], children=[3,5,2])

q = @from i in df begin
@select i.name=>i.children
@select i.name => i.children
@collect Dict
end

Expand Down
8 changes: 4 additions & 4 deletions example/25-ab-syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ using Query
using DataFrames
using Statistics

df = DataFrame(name=repeat(["John", "Sally", "Kirk"],inner=[1],outer=[2]),
age=vcat([10., 20., 30.],[10., 20., 30.].+3),
children=repeat([3,2,2],inner=[1],outer=[2]),state=[:a,:a,:a,:b,:b,:b])
df = DataFrame(name=repeat(["John", "Sally", "Kirk"], inner=[1], outer=[2]),
age=vcat([10., 20., 30.], [10., 20., 30.] .+ 3),
children=repeat([3,2,2], inner=[1], outer=[2]),state=[:a,:a,:a,:b,:b,:b])

x = @from i in df begin
@group i by i.state into g
@select {group=key(g),mage=mean(g.age), oldest=maximum(g.age), youngest=minimum(g.age)}
@select {group = key(g),mage = mean(g.age), oldest = maximum(g.age), youngest = minimum(g.age)}
@collect DataFrame
end

Expand Down
8 changes: 4 additions & 4 deletions example/prep_data.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
using DataFrames

n=10_000_000
n = 10_000_000

# Right now things only work columns of type Array, so
# we need this slighlty cumbersome DataFrame construction
# to prevent DataArray or NullableArray creation
# We are also skipping all Strings because of #14955 (I think)
data_friends = fill(4,n)
data_age = fill(38.2,n)
data_children = fill(2,n)
data_friends = fill(4, n)
data_age = fill(38.2, n)
data_children = fill(2, n)

columns = []
push!(columns, data_friends)
Expand Down
12 changes: 6 additions & 6 deletions src/Query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Query

import IterableTables
using DataValues
using MacroTools: postwalk
using MacroTools:postwalk
using QueryOperators

export @from, @query, @count, Grouping, key
Expand All @@ -23,25 +23,25 @@ include("standalone_query_macros.jl")
include("table_query_macros.jl")

macro from(range::Expr, body::Expr)
if range.head!=:call || (range.args[1]!=:in && range.args[1]!=in)
if range.head != :call || (range.args[1] != :in && range.args[1] != in)
error()
end

if body.head!=:block
if body.head != :block
error()
end

body.args = filter(i->!isa(i, LineNumberNode),body.args)
body.args = filter(i -> !isa(i, LineNumberNode), body.args)

insert!(body.args,1,:( @from $(range.args[2]) in $(range.args[3]) ))
insert!(body.args, 1, :( @from $(range.args[2]) in $(range.args[3]) ))

translate_query(body)

return body.args[1]
end

macro query(range::Symbol, body::Expr)
if body.head!=:block
if body.head != :block
error()
end

Expand Down
8 changes: 4 additions & 4 deletions src/query_utils.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ismacro(ex, name::Symbol, nargs::Integer=-1) =
isa(ex, Expr) && ex.head==:macrocall && ex.args[1]==name &&
(nargs == -1 || length(ex.args) == nargs+1)
isa(ex, Expr) && ex.head == :macrocall && ex.args[1] == name &&
(nargs == -1 || length(ex.args) == nargs + 1)
ismacro(ex, name::String, nargs::Integer=-1) = ismacro(ex, Symbol(name), nargs)

iscall(ex, name::Symbol, nargs::Integer=-1) =
isa(ex, Expr) && ex.head==:call && ex.args[1]==name &&
(nargs == -1 || length(ex.args) == nargs+1)
isa(ex, Expr) && ex.head == :call && ex.args[1] == name &&
(nargs == -1 || length(ex.args) == nargs + 1)
12 changes: 6 additions & 6 deletions src/standalone_query_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ end

macro groupby(elementSelector)
elementSelector_as_anonym_func = helper_replace_anon_func_syntax(elementSelector)
resultSelector_as_anonym_func = :(i->i)
resultSelector_as_anonym_func = :(i -> i)

q_elementSelector = Expr(:quote, elementSelector_as_anonym_func)
q_resultSelector = Expr(:quote, resultSelector_as_anonym_func)
Expand Down Expand Up @@ -178,11 +178,11 @@ end
macro map(f)
f_as_anonym_func = helper_replace_anon_func_syntax(f)
q = Expr(:quote, f_as_anonym_func)
return :( i-> QueryOperators.map(QueryOperators.query(i), $(esc(f_as_anonym_func)), $(esc(q))) ) |>
return :( i -> QueryOperators.map(QueryOperators.query(i), $(esc(f_as_anonym_func)), $(esc(q))) ) |>
helper_namedtuples_replacement
end

macro mapmany(source, collectionSelector,resultSelector)
macro mapmany(source, collectionSelector, resultSelector)
collectionSelector_as_anonym_func = helper_replace_anon_func_syntax(collectionSelector)
resultSelector_as_anonym_func = helper_replace_anon_func_syntax(resultSelector)

Expand All @@ -195,14 +195,14 @@ macro mapmany(source, collectionSelector,resultSelector)
helper_namedtuples_replacement
end

macro mapmany(collectionSelector,resultSelector)
macro mapmany(collectionSelector, resultSelector)
collectionSelector_as_anonym_func = helper_replace_anon_func_syntax(collectionSelector)
resultSelector_as_anonym_func = helper_replace_anon_func_syntax(resultSelector)

collectionSelector_q = Expr(:quote, collectionSelector_as_anonym_func)
resultSelector_q = Expr(:quote, resultSelector_as_anonym_func)

return :( i-> QueryOperators.mapmany(QueryOperators.query(i),
return :( i -> QueryOperators.mapmany(QueryOperators.query(i),
$(esc(collectionSelector_as_anonym_func)), $(esc(collectionSelector_q)),
$(esc(resultSelector_as_anonym_func)), $(esc(resultSelector_q)))) |>
helper_namedtuples_replacement
Expand Down Expand Up @@ -239,7 +239,7 @@ macro drop(n)
end

macro unique()
return :( i -> QueryOperators.unique(QueryOperators.query(i), q->q, :(q->q))) |>
return :( i -> QueryOperators.unique(QueryOperators.query(i), q -> q, :(q -> q))) |>
helper_namedtuples_replacement
end

Expand Down
24 changes: 12 additions & 12 deletions src/table_query_macros.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ macro select(args...)
elseif typeof(arg) == QuoteNode
# select by name
prev = :( merge($prev, QueryOperators.NamedTupleUtilities.select(_, Val($(arg)))) )
elseif arg isa Expr && arg.head==:call && length(arg.args)==3 && arg.args[1]==Symbol(":")
elseif arg isa Expr && arg.head == :call && length(arg.args) == 3 && arg.args[1] == Symbol(":")
arg = string(arg)
# select by range, with multiple syntaxes supported
m_range = match(r"^:([^,:]+) *: *:([^,:]+)", arg)
Expand Down Expand Up @@ -184,7 +184,7 @@ macro mutate(args...)
prev = :( Base.merge($prev, ($(arg.args[1]) = $(arg.args[2]),)) )
end

return :( Query.@map( $prev ) ) |> esc
return :( Query.@map( $prev ) ) |> esc
end

our_get(x) = x
Expand All @@ -198,36 +198,36 @@ macro disallowna()
end

macro disallowna(columns...)
return :( Query.@mutate( $( ( :( $(columns[i].value) = our_get(_.$(columns[i].value)) ) for i=1:length(columns) )... ) ) )
return :( Query.@mutate( $( ( :( $(columns[i].value) = our_get(_.$(columns[i].value)) ) for i = 1:length(columns) )... ) ) )
end

# The following is a backwards compat fix
macro dissallowna()
return :( Query.@map(map(our_get, _)) )
end
macro dissallowna(columns...)
return :( Query.@mutate( $( ( :( $(columns[i].value) = our_get(_.$(columns[i].value)) ) for i=1:length(columns) )... ) ) )
return :( Query.@mutate( $( ( :( $(columns[i].value) = our_get(_.$(columns[i].value)) ) for i = 1:length(columns) )... ) ) )
end

macro dropna()
return :( i-> i |> Query.@filter(!any(isna, _)) |> Query.@disallowna() )
return :( i -> i |> Query.@filter(!any(isna, _)) |> Query.@disallowna() )
end

macro dropna(columns...)
return :( i-> i |> Query.@filter(!any(($((:(isna(_.$(columns[i].value))) for i in 1:length(columns) )...),))) |> Query.@disallowna($(columns...)) )
return :( i -> i |> Query.@filter(!any(($((:(isna(_.$(columns[i].value))) for i in 1:length(columns) )...),))) |> Query.@disallowna($(columns...)) )
end

macro replacena(arg, args...)
if length(args)==0 && !(arg isa Expr && arg.head==:call && length(arg.args)==3 && arg.args[1]==:(=>))
return :( Query.@map(map(i->our_get(i, $arg), _)) )
if length(args) == 0 && !(arg isa Expr && arg.head == :call && length(arg.args) == 3 && arg.args[1] == :(=>))
return :( Query.@map(map(i -> our_get(i, $arg), _)) )
else
args = [arg; args...]

all(i isa Expr && i.head==:call && length(i.args)==3 && i.args[1]==:(=>) for i in args) || error("Invalid syntax.")
all(i isa Expr && i.head == :call && length(i.args) == 3 && i.args[1] == :(=>) for i in args) || error("Invalid syntax.")

columns = map(i->i.args[2].value, args)
replacement_values = map(i->i.args[3], args)
columns = map(i -> i.args[2].value, args)
replacement_values = map(i -> i.args[3], args)

return :( Query.@mutate( $( ( :( $(columns[i]) = our_get(_.$(columns[i]), $(replacement_values[i])) ) for i=1:length(columns) )... ) ) )
return :( Query.@mutate( $( ( :( $(columns[i]) = our_get(_.$(columns[i]), $(replacement_values[i])) ) for i = 1:length(columns) )... ) ) )
end
end
Loading