Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
11 changes: 7 additions & 4 deletions src/abstractdataframe/reshape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,10 @@ end

Unstack data frame `df`, i.e. convert it from long to wide format.

Row keys and values from value column will be ordered in the order produced
by `groupby`.
Row and column keys will be ordered in the order of their first appearance except
when they are stored in an `AbstractVector` which supports `DataAPI.refpool`
(two most common cases are `CategoricalVector` and `PooledVector`),
in which case the odrer follows the order of values in this pool.

# Positional arguments
- `df` : the AbstractDataFrame to be unstacked
Expand Down Expand Up @@ -369,15 +371,16 @@ function find_group_row(gdf::GroupedDataFrame)

filled = 0
i = 1
groups = gdf.groups
while filled < length(gdf)
group = gdf.groups[i]
group = groups[i]
if rows[group] == 0
rows[group] = i
filled += 1
end
i += 1
end
return rows # return row index of first occurence of each group in gdf
return rows # return row index of first occurrence of each group in gdf
end

function _unstack(df::AbstractDataFrame, rowkeys::AbstractVector{Int},
Expand Down
2 changes: 1 addition & 1 deletion test/reshape.jl
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ end
@test unstack(df, [:id, :id2], :var, :val) == unstack(df, :var, :val) ==
DataFrame(id=1:3, id2=1:3, a=1:3:7, b=2:3:8, c=3:3:9)

# an exertice on current unstack invariants
# an exercise on current unstack invariants
Random.seed!(1234)
for i in 1:16
df = df[Random.shuffle(1:9), :]
Expand Down