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

Juno Display #1121

Merged
merged 13 commits into from
Nov 13, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ SortingAlgorithms
Reexport
Compat 0.8.4
FileIO 0.1.2
Juno 0.2.4
25 changes: 25 additions & 0 deletions src/abstractdataframe/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -579,3 +579,28 @@ function showcols(io::IO, df::AbstractDataFrame) # -> Void
end

showcols(df::AbstractDataFrame) = showcols(STDOUT, df) # -> Void

using Juno
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not needed, redundant with following line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using will import all of the symbols exported from Juno, but using Juno: stuff gets specific, potentially unexported symbols, so it's not entirely redundant, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah right. only other thing that should be needed that isn't listed yet is @render, so adding that could replace the first line.

Mike, please communicate in sentences, single word responses (and commit messages) are not an effective way of justifying anything.

using Juno: Inline, LazyTree, Table, Row, strong

const SIZE = 25
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want to allow users to tweak this somewhere in Juno?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly, but we'd have to implement a Juno.jl API for that. I think a better approach would be to extend this view to be capable of showing the entire dataframe at once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Though showing the full data frame could be quite problematic if it contains one million rows and one hundred columns. Better take a subset first.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not if we lazy-load it as needed


function to_matrix(df::AbstractDataFrame)
res = Array{Any}(size(df))
for (j, col) in enumerate(columns(df)), i = 1:length(col)
isassigned(col, i) && (res[i, j] = col[i])
end
return res
end

function _render(df::AbstractDataFrame)
width = min(size(df, 2), SIZE)
height = min(size(df, 1), SIZE)
header = map(x->strong(string(x)), names(df)[1:width]')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

julia> [:foo, :bar]'
WARNING: the no-op `transpose` fallback is deprecated, and no more specific `transpose` method for Symbol exists. Consider `permutedims(x, [2, 1])` or writing a specific `transpose(x::Symbol)` method if appropriate.
1×2 Array{Symbol,2}:
 :foo  :bar

This seems like broken behaviour on Julia's part – I can only transpose arrays of transposable objects?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Transpose is recursive.

JuliaLang/julia#17834

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

transpose is a linear algebraic operation, and recursive on elements

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see where the error is coming from, but the ultimate behaviour – arrays of Xs are transposable but arrays of Ys are not – seems pretty arbitrary to me. What makes a number transposable, other than as a hack to get array transpose to work?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reshape(names(df)[1:width], 1, 2) works, btw.

body = Juno.undefs(to_matrix(df))[1:height, 1:width]
view = Table(vcat(header, body))
LazyTree(Row(typeof(df), text" ", Juno.dims(size(df)...)),
() -> [view])
end

@render Inline df::AbstractDataFrame _render(df)
1 change: 1 addition & 0 deletions test/REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Compat 0.9.0
DataStructures
RDatasets # can be removed when deprecated.jl doesn't test read_rda anymore
RData
Atom
9 changes: 9 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ module TestShow
showall(io, subdf)
showall(io, subdf, true)

if VERSION > v"0.5-"
using Juno
out = DataFrames._render(df)
@assert out.head.xs[1] == DataFrame
@assert isa(out.children()[1], Juno.Table)
@assert size(out.children()[1].xs) == (4, 2)
end

dfvec = DataFrame[df for _=1:3]
show(io, dfvec)
showall(io, dfvec)
Expand All @@ -35,4 +43,5 @@ module TestShow
show(io, A)
A = DataFrames.RepeatedVector([1, 2, 3], 1, 5)
show(io, A)

end