This repository was archived by the owner on May 5, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Stack should use similar_nullable, not NullableArray #54
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,12 +198,7 @@ function unstack(dt::AbstractDataTable, rowkey::Int, colkey::Int, value::Int) | |
keycol = NullableCategoricalArray(dt[colkey]) | ||
Nrow = length(refkeycol.pool) | ||
Ncol = length(keycol.pool) | ||
T = eltype(valuecol) | ||
if T <: Nullable | ||
T = eltype(T) | ||
end | ||
payload = DataTable(Any[NullableArray(T, Nrow) for i in 1:Ncol], | ||
map(Symbol, levels(keycol))) | ||
payload = DataTable(Any[similar_nullable(valuecol, Nrow) for i in 1:Ncol], map(Symbol, levels(keycol))) | ||
nowarning = true | ||
for k in 1:nrow(dt) | ||
j = Int(CategoricalArrays.order(keycol.pool)[keycol.refs[k]]) | ||
|
@@ -216,7 +211,9 @@ function unstack(dt::AbstractDataTable, rowkey::Int, colkey::Int, value::Int) | |
payload[j][i] = valuecol[k] | ||
end | ||
end | ||
insert!(payload, 1, NullableArray(levels(refkeycol)), _names(dt)[rowkey]) | ||
levs = levels(refkeycol) | ||
col = similar_nullable(dt[rowkey], length(levs)) | ||
insert!(payload, 1, copy!(col, levs), _names(dt)[rowkey]) | ||
end | ||
unstack(dt::AbstractDataTable, rowkey, colkey, value) = | ||
unstack(dt, index(dt)[rowkey], index(dt)[colkey], index(dt)[value]) | ||
|
@@ -235,15 +232,10 @@ function unstack(dt::AbstractDataTable, colkey::Int, value::Int) | |
end | ||
keycol = NullableCategoricalArray(dt[colkey]) | ||
valuecol = dt[value] | ||
dt1 = dt[g.idx[g.starts], g.cols] | ||
dt1 = nullable!(dt[g.idx[g.starts], g.cols], g.cols) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No need to specify There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The julia> nullable!(DataTable(a = 1:4))
ERROR: MethodError: no method matching nullable!(::DataTables.DataTable)
Closest candidates are:
nullable!(::DataTables.DataTable, ::Union{Real, Symbol}) at /Users/Cameron/.julia/v0.6/DataTables/src/datatable/datatable.jl:779
nullable!(::DataTables.DataTable, ::Array{T<:Union{Real, Symbol},1}) where T<:Union{Real, Symbol} at /Users/Cameron/.julia/v0.6/DataTables/src/datatable/datatable.jl:783
nullable!(::Array{Symbol,1}, ::DataTables.AbstractDataTable) at deprecated.jl:50
...
julia> nullable!(DataTable(a = 1:4), :a)
4×1 DataTables.DataTable
│ Row │ a │
├─────┼───┤
│ 1 │ 1 │
│ 2 │ 2 │
│ 3 │ 3 │
│ 4 │ 4 │ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK, so that's fine for now. |
||
Nrow = length(g) | ||
Ncol = length(levels(keycol)) | ||
T = eltype(valuecol) | ||
if T <: Nullable | ||
T = eltype(T) | ||
end | ||
dt2 = DataTable(Any[NullableArray(T, Nrow) for i in 1:Ncol], | ||
map(@compat(Symbol), levels(keycol))) | ||
dt2 = DataTable(Any[similar_nullable(valuecol, Nrow) for i in 1:Ncol], map(Symbol, levels(keycol))) | ||
nowarning = true | ||
for k in 1:nrow(dt) | ||
j = Int(CategoricalArrays.order(keycol.pool)[keycol.refs[k]]) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be more logical to add this definition right after that for
CategoricalArray
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The AbstractDataTable function that separates the two will disappear in #44. I thought adding the new function to the end of the set like this would minimize the risk of a merge conflict, although that's purely speculative. I can reverse them if you'd like, but I'm not sure it will matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a big deal, but it's always better to have commits be correct when taken in isolation.