Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
suvayu committed Apr 18, 2024
1 parent 1f31e42 commit 9878af1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ function set_tbl_col(
variant::String = "",
tmp::Bool = false,
show::Bool = false,
) where T <: Union{Int64, Float64, String, Bool}
) where {T<:Union{Int64,Float64,String,Bool}}
# TODO: is it worth it to have the ability to set multiple
# columns? If such a feature is required, we can use
# cols::Dict{Symbol, Vector{Any}}, and get the cols and vals
Expand Down Expand Up @@ -298,13 +298,13 @@ function.
function set_tbl_col(
con::DB,
source::String,
cols::Dict{Symbol, T};
cols::Dict{Symbol,T};
on::Symbol,
where_::String = "",
variant::String = "",
tmp::Bool = false,
show::Bool = false,
) where T
) where {T}
# FIXME: accept NamedTuple|Dict as cols in stead of value & col
source = fmt_source(con, source)
subquery = fmt_select(source; cols...)
Expand All @@ -313,7 +313,13 @@ function set_tbl_col(
end

# FIXME: resolve String|Symbol schizophrenic API
query = fmt_join(source, "($subquery)"; on = ["$on"], cols = map(string, [keys(cols)...]), fill = true)
query = fmt_join(
source,
"($subquery)";
on = ["$on"],
cols = map(string, [keys(cols)...]),
fill = true,
)

if (length(variant) == 0) && !show
tmp = true
Expand Down
11 changes: 9 additions & 2 deletions test/test-pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,16 @@ end

@testset "w/ constant after filtering" begin
where_clause = TIO.FmtSQL.@where_(lifetime in 25:50, name % "Valhalla_%")
df_res = TIO.set_tbl_col(con, csv_path, Dict(:investable => true); opts..., where_ = where_clause)
df_res = TIO.set_tbl_col(
con,
csv_path,
Dict(:investable => true);
opts...,
where_ = where_clause,
)
@test shape(df_res) == shape(df_org)
df_res = filter(row -> 25 <= row.lifetime <= 50 && startswith(row.name, "Valhalla_"), df_res)
df_res =
filter(row -> 25 <= row.lifetime <= 50 && startswith(row.name, "Valhalla_"), df_res)
@test df_res.investable |> all
end
end

0 comments on commit 9878af1

Please sign in to comment.