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

[BREAKING] Add column indexing using strings #2199

Merged
merged 28 commits into from
Apr 27, 2020
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
60e72bf
change rename to pass string to columns
bkamins Apr 16, 2020
3a44c8f
allow string indexing (minimal test and docs updates)
bkamins Apr 16, 2020
ae2691a
Merge branch 'master' into add_string_col_indexing
bkamins Apr 17, 2020
cc9bbca
make keys consistent
bkamins Apr 17, 2020
73a5a1a
fixed old tests
bkamins Apr 17, 2020
64741b2
update manual
bkamins Apr 17, 2020
e1e04bb
correct location of deleterows! deprecated tests
bkamins Apr 17, 2020
b390558
fix for Julia 1.0
bkamins Apr 17, 2020
ddb84f2
only abstractdataframe.jl and dataframe.jl left to test
bkamins Apr 17, 2020
981e8bf
only dataframe.jl left
bkamins Apr 17, 2020
5de0354
remove internal keys test
bkamins Apr 17, 2020
4f8b2dc
ready for review
bkamins Apr 18, 2020
38ad85c
sync with DataAPI v1.2
bkamins Apr 20, 2020
e0cf2bd
Apply suggestions from code review
bkamins Apr 21, 2020
95aa693
updates after the code review
bkamins Apr 21, 2020
670664e
update documentation and tests
bkamins Apr 22, 2020
4b52cc8
Apply suggestions from code review
bkamins Apr 22, 2020
ab29c54
move one ! to a correct place
bkamins Apr 22, 2020
b93a807
Merge remote-tracking branch 'origin/add_string_col_indexing' into ad…
bkamins Apr 22, 2020
26b1980
fix cols documentation
bkamins Apr 22, 2020
3678130
update constructor tests
bkamins Apr 22, 2020
0bb2a99
Apply suggestions from code review
bkamins Apr 22, 2020
30a8f70
introduce MultiColumnIndex and fix overlong lines
bkamins Apr 22, 2020
9a3cee0
add comment why AbstractVector is excluded when handling cols in sort
bkamins Apr 22, 2020
cf879d3
Apply suggestions from code review
bkamins Apr 23, 2020
9cc3702
updates after code review
bkamins Apr 23, 2020
2a935a6
Update docs/src/man/getting_started.md
bkamins Apr 24, 2020
e40461e
define SymbolOrString
bkamins Apr 24, 2020
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
78 changes: 23 additions & 55 deletions test/constructors.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,66 +16,34 @@ const ≅ = isequal
@test index(df) == Index()
@test size(DataFrame!()) == (0,0)

df = DataFrame(Any[CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))],
Index([:x1, :x2]))
vecvec = [CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))]

df = DataFrame(collect(Any, vecvec), Index([:x1, :x2]))
@test size(df, 1) == 3
@test size(df, 2) == 2

df2 = DataFrame!(Any[CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))],
Index([:x1, :x2]))
df2 = DataFrame!(collect(Any, vecvec), Index([:x1, :x2]))
@test size(df2, 1) == 3
@test size(df2, 2) == 2

@test df == DataFrame([CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))])
@test df == DataFrame!([CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))])
@test df == DataFrame([CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))], [:x1, :x2])
@test df == DataFrame([CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))], ["x1", "x2"])
@test df == DataFrame(Any[CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))])
@test df == DataFrame(Any[CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))], [:x1, :x2])
@test df == DataFrame(Any[CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))], ["x1", "x2"])
@test df == DataFrame(AbstractVector[CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))], [:x1, :x2])
@test df == DataFrame(AbstractVector[CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))], ["x1", "x2"])
@test df == DataFrame((CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))))
@test df == DataFrame((CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))), (:x1, :x2))
@test df == DataFrame((CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))), (:x1, :x2))
@test df == DataFrame((CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))), ("x1", "x2"))
@test df == DataFrame((CategoricalVector{Union{Float64, Missing}}(zeros(3)),
CategoricalVector{Union{Float64, Missing}}(ones(3))), ("x1", "x2"))
@test df == DataFrame(x1 = Union{Int, Missing}[0.0, 0.0, 0.0],
x2 = Union{Int, Missing}[1.0, 1.0, 1.0])
@test df == DataFrame!(x1 = Union{Int, Missing}[0.0, 0.0, 0.0],
x2 = Union{Int, Missing}[1.0, 1.0, 1.0])
@test df == DataFrame([:x1=>Union{Int, Missing}[0.0, 0.0, 0.0],
:x2=>Union{Int, Missing}[1.0, 1.0, 1.0]])
@test df == DataFrame([:x1=>Union{Int, Missing}[0.0, 0.0, 0.0],
:x2=>Union{Int, Missing}[1.0, 1.0, 1.0]])
@test df == DataFrame!((:x1=>Union{Int, Missing}[0.0, 0.0, 0.0],
:x2=>Union{Int, Missing}[1.0, 1.0, 1.0]))
@test df == DataFrame!((:x1=>Union{Int, Missing}[0.0, 0.0, 0.0],
:x2=>Union{Int, Missing}[1.0, 1.0, 1.0]))
@test df == DataFrame(["x1"=>Union{Int, Missing}[0.0, 0.0, 0.0],
"x2"=>Union{Int, Missing}[1.0, 1.0, 1.0]])
@test df == DataFrame!(["x1"=>Union{Int, Missing}[0.0, 0.0, 0.0],
"x2"=>Union{Int, Missing}[1.0, 1.0, 1.0]])
@test df == DataFrame(("x1"=>Union{Int, Missing}[0.0, 0.0, 0.0],
"x2"=>Union{Int, Missing}[1.0, 1.0, 1.0]))
@test df == DataFrame!(("x1"=>Union{Int, Missing}[0.0, 0.0, 0.0],
"x2"=>Union{Int, Missing}[1.0, 1.0, 1.0]))
@test df2.x1 === vecvec[1]
@test df2.x2 === vecvec[2]

for fun in (DataFrame, DataFrame!)
@test df == fun(vecvec)
@test df == fun(collect(Any, vecvec))
@test df == fun(collect(AbstractVector, vecvec))
@test df == fun(Tuple(vecvec))
@test df == fun(x1 = vecvec[1], x2 = vecvec[2])

for cols in ([:x1, :x2], ["x1", "x2"])
@test df == fun(vecvec, cols)
@test df == fun(collect(Any, vecvec), cols)
@test df == fun(collect(AbstractVector, vecvec), cols)
@test df == fun(Tuple(vecvec), Tuple(cols))
@test df == fun([col=>vect for (col, vect) in zip(cols, vecvec)])
end
end

@test DataFrame([1:3, 1:3]) == DataFrame(Any[1:3, 1:3]) ==
DataFrame(UnitRange[1:3, 1:3]) == DataFrame(AbstractVector[1:3, 1:3]) ==
Expand Down