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

unstack in master expects sorted groups #1

Open
wants to merge 23 commits into
base: enhance_join
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
1 change: 1 addition & 0 deletions src/DataFrames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ for (dir, filename) in [
("subdataframe", "subdataframe.jl"),
("groupeddataframe", "grouping.jl"),
("dataframerow", "dataframerow.jl"),
("dataframerow", "utils.jl"),

("abstractdataframe", "iteration.jl"),
("abstractdataframe", "join.jl"),
Expand Down
30 changes: 9 additions & 21 deletions src/abstractdataframe/abstractdataframe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -574,17 +574,16 @@ nonunique(df)

"""
function nonunique(df::AbstractDataFrame)
res = fill(false, nrow(df))
rows = Set{DataFrameRow}()
for i in 1:nrow(df)
arow = DataFrameRow(df, i)
if in(arow, rows)
res[i] = true
else
push!(rows, arow)
end
gslots = _row_group_slots(df)[3]
# unique rows are the first encountered group representatives,
# nonunique are everything else
res = fill(true, nrow(df))
for g_row in gslots
if g_row > 0
res[g_row] = false
end
end
res
return res
end

unique!(df::AbstractDataFrame) = deleterows!(df, find(nonunique(df)))
Expand Down Expand Up @@ -622,17 +621,6 @@ unique!(df) # modifies df
"""
(unique, unique!)

function nonuniquekey(df::AbstractDataFrame)
# Here's another (probably a lot faster) way to do `nonunique`
# by grouping on all columns. It will fail if columns cannot be
# made into PooledDataVector's.
gd = groupby(df, _names(df))
idx = [1:length(gd.idx)][gd.idx][gd.starts]
res = fill(true, nrow(df))
res[idx] = false
res
end

# Count the number of missing values in every column of an AbstractDataFrame.
function colmissing(df::AbstractDataFrame) # -> Vector{Int}
nrows, ncols = size(df)
Expand Down
10 changes: 6 additions & 4 deletions src/abstractdataframe/iteration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@
# Iteration by rows
immutable DFRowIterator{T <: AbstractDataFrame}
df::T
nrow::Int
DFRowIterator(df::T) = new(df, nrow(df))
end
eachrow(df::AbstractDataFrame) = DFRowIterator(df)
eachrow{T <: AbstractDataFrame}(df::T) = DFRowIterator{T}(df)

Base.start(itr::DFRowIterator) = 1
Base.done(itr::DFRowIterator, i::Int) = i > size(itr.df, 1)
Base.done(itr::DFRowIterator, i::Int) = i > itr.nrow
Base.next(itr::DFRowIterator, i::Int) = (DataFrameRow(itr.df, i), i + 1)
Base.size(itr::DFRowIterator) = (size(itr.df, 1), )
Base.length(itr::DFRowIterator) = size(itr.df, 1)
Base.size(itr::DFRowIterator) = (itr.nrow, )
Base.length(itr::DFRowIterator) = itr.nrow
Base.getindex(itr::DFRowIterator, i::Any) = DataFrameRow(itr.df, i)
Base.map(f::Function, dfri::DFRowIterator) = [f(row) for row in dfri]

Expand Down
Loading