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

Julia 0.6 compatibility and Linux display #24

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
Lint 0.1.60
julia 0.3.11
julia 0.6
Compat 0.1
Formatting 0.1.2
DataArrays
DataFrames
DataFramesMeta
Lazy
Missings
21 changes: 13 additions & 8 deletions src/TermWin.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ end
using DataArrays
using DataFrames
using DataFramesMeta
using Missings

macro lintpragma( s )
end
Expand Down Expand Up @@ -120,17 +121,21 @@ function initsession()
throw( "terminal doesn't support colors")
end
mousemask( BUTTON1_PRESSED | REPORT_MOUSE_POSITION )
acs_map_ptr = cglobal( Libdl.dlsym( libncurses, :acs_map), UInt32 )
acs_map_arr = pointer_to_array( acs_map_ptr, 128)
if is_apple()
acs_map_ptr = cglobal( Libdl.dlsym( libncurses, :acs_map), UInt32 )
else
acs_map_ptr = cglobal( Libdl.dlsym( libncurses, :acs_map), UInt64 )
end
acs_map_arr = unsafe_wrap(Array, acs_map_ptr, 128)

start_color()
# figure out how many colors are supported
colorsptr = cglobal( Libdl.dlsym( libncurses, :COLORS), Int16 )
colorsarr = pointer_to_array( colorsptr, 1 )
colorsarr = unsafe_wrap(Array, colorsptr, 1 )
COLORS = colorsarr[1]

colorsptr = cglobal( Libdl.dlsym( libncurses, :COLOR_PAIRS), Int16 )
colorsarr = pointer_to_array( colorsptr, 1 )
colorsarr = unsafe_wrap(Array, colorsptr, 1 )
COLOR_PAIRS = colorsarr[1]

init_pair( 1, COLOR_RED, COLOR_BLACK )
Expand Down Expand Up @@ -342,9 +347,9 @@ end
function titleof( x::Any )
typx = typeof( x )
if typx == Module || typx == Function
return utf8( string( x ) )
return string( x )
else
return utf8( string( typx ) )
return string( typx )
end
end

Expand Down Expand Up @@ -387,7 +392,7 @@ function tshow( x; kwargs... )
catch err
bt = catch_backtrace()
msg = wordwrap( string(err) * "\n" * string( bt ), 80 )
widget = tshow_( msg; title=utf8("Error") )
widget = tshow_( msg; title="Error" )
end
if widget != nothing
refresh( rootTwScreen )
Expand Down Expand Up @@ -459,7 +464,7 @@ function testkeydialog()
win = winnewcenter( 6, width )
panel = new_panel( win )
box( win, 0, 0 )
title = utf8( "Test Key/Mouse/Unicode" )
title = "Test Key/Mouse/Unicode"
keyhint = "[Esc to continue]"

mvwprintw( win, 0, (@compat Int( (width-length(title))>>1)), "%s", title )
Expand Down
16 changes: 8 additions & 8 deletions src/ccall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ function initscr()
global libncurses, libpanel
if libncurses == false
try
libncurses = Libdl.dlopen("libncurses")
catch
libncurses = Libdl.dlopen("libncursesw")
catch
libncurses = Libdl.dlopen("libncurses")
end
try
libpanel = Libdl.dlopen("libpanel")
catch
libpanel = Libdl.dlopen("libpanelw")
catch
libpanel = Libdl.dlopen("libpanel")
end
end
ccall( Libdl.dlsym( libncurses, :initscr), Ptr{Void}, () )
Expand Down Expand Up @@ -66,14 +66,14 @@ function mvwaddch( w::TwWindow, y::Int, x::Int, c )
end
end

function mvwprintw{T<:AbstractString}( win::Ptr{Void}, row::Int, height::Int, fmt::ASCIIString, str::T )
function mvwprintw{T<:AbstractString}( win::Ptr{Void}, row::Int, height::Int, fmt::String, str::T )
ccall( Libdl.dlsym( libncurses, :mvwprintw), Void,
( Ptr{Void}, Int, Int, Cstring, Cstring ),
win, row, height, fmt, str )
end

# note that it could in turn call another TwWindow...
function mvwprintw{T<:AbstractString}( w::TwWindow, y::Int, x::Int, fmt::ASCIIString, s::T )
function mvwprintw{T<:AbstractString}( w::TwWindow, y::Int, x::Int, fmt::String, s::T )
if objtype( w.parent.value ) == :List && typeof( w.parent.value.window ) != TwWindow
# terminal layer. use its pad
mvwprintw( w.parent.value.data.pad, y+w.yloc, x+w.xloc, fmt, s )
Expand Down Expand Up @@ -322,7 +322,7 @@ function has_mouse()
end

function mousemask( mask )
oldmm = Array( UInt64, 1 )
oldmm = Array{UInt64}(1)
resultmm = ccall( Libdl.dlsym( libncurses, :mousemask), UInt64, (UInt64, Ptr{UInt64}), mask, oldmm )
( resultmm, oldmm[1])
end
Expand All @@ -332,7 +332,7 @@ function mouseinterval( n::Int )
end

#hack!
const mouseByteString = bytestring( Array( UInt8, 64 ) )
mouseByteString = Vector{UInt8}(64) #unsafe_string( Array( UInt8, 64 ) )
function getmouse()
#=
type Mouse_Event_t
Expand Down
73 changes: 39 additions & 34 deletions src/dfutils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ defaultAggr( ::Type{} ) = :uniqvalue
defaultAggr{T<:Real}( ::Type{T} ) = :sum
defaultAggr{T}( ::Type{Array{T,1}} ) = :unionall

function liftAggrSpecToFunc( c::Symbol, dfa::UTF8String )
function liftAggrSpecToFunc( c::Symbol, dfa::String )
if haskey( DataFrameAggrCache, (c, dfa ) )
return DataFrameAggrCache[ (c, dfa ) ]
end
ret = liftAggrSpecToFunc( c, parse( dfa ) )
DataFrameAggrCache[ (c, dfa) ] = ret
end
liftAggrSpecToFunc( c::Symbol, dfa::ASCIIString ) = liftAggrSpecToFunc( c, utf8( dfa ) )

function liftAggrSpecToFunc( c::Symbol, dfa::Union{ Function, Symbol, Expr } )
if typeof( dfa ) == Function
Expand Down Expand Up @@ -71,7 +70,7 @@ function liftAggrSpecToFunc( c::Symbol, dfa::Union{ Function, Symbol, Expr } )
convertExpression!( cdfa, c )

membernames = Dict{Union{Symbol,Expr}, Symbol}()
cdfa = DataFramesMeta.replace_syms(cdfa, membernames)
cdfa = DataFramesMeta.replace_syms!(cdfa, membernames)
funargs = map(x -> :( getindex( _df_, $(x)) ), collect(keys(membernames)))
funnameouter = gensym("DFAggr")
funname = gensym()
Expand Down Expand Up @@ -130,12 +129,20 @@ function uniqvalue( x::AbstractDataArray; skipna::Bool=true )
if length(l) == 1
return l[1]
end
return NA
return missing
end
if length(lvls) == 1
return lvls[1]
end
return NA
return missing
end

function uniqvalue( x::Array )
lvls = DataArrays.levels(x)
if length(lvls) == 1
return lvls[1]
end
return missing
end

function uniqvalue{T<:AbstractString}( x::Union{ Array{T}, DataArray{T}, PooledDataArray{T} }; skipna::Bool=true, skipempty::Bool=true )
Expand All @@ -156,7 +163,7 @@ function uniqvalue{T<:AbstractString}( x::Union{ Array{T}, DataArray{T}, PooledD
elseif length( l ) == 1
return l[1]
end
return NA
return missing
end
if skipempty
emptyidx = findfirst( lvls, "" )
Expand All @@ -172,16 +179,14 @@ function uniqvalue{T<:AbstractString}( x::Union{ Array{T}, DataArray{T}, PooledD
elseif length( lvls ) == 1
return lvls[1]
end
return NA
return missing
end

immutable CalcPivot
spec::Expr
by::Array{Symbol,1}
CalcPivot( x::UTF8String, by::Array{Symbol,1}=Symbol[] ) = CalcPivot( parse(x), by )
CalcPivot( x::ASCIIString, by::Array{Symbol,1}=Symbol[] ) = CalcPivot( parse(utf8(x)), by )
CalcPivot( x::UTF8String, by::Symbol ) = CalcPivot( parse(x), Symbol[ by ] )
CalcPivot( x::ASCIIString, by::Symbol ) = CalcPivot( parse(utf8(x)), Symbol[ by ] )
CalcPivot( x::String, by::Array{Symbol,1}=Symbol[] ) = CalcPivot( parse(x), by )
CalcPivot( x::String, by::Symbol ) = CalcPivot( parse(x), Symbol[ by ] )
function CalcPivot( x::Expr, by::Symbol )
CalcPivot( x, Symbol[ by ] )
end
Expand Down Expand Up @@ -238,7 +243,7 @@ function liftCalcPivotToFunc( ex::Expr, by::Array{Symbol,1} )
funname = gensym()

membernames = Dict{Union{Symbol,Expr}, Symbol}()
cex = DataFramesMeta.replace_syms(cex, membernames)
cex = DataFramesMeta.replace_syms!(cex, membernames)
# keys are the columns. values are the unique gensyms

if !isempty( by ) # micro split-apply-combine
Expand All @@ -253,7 +258,7 @@ function liftCalcPivotToFunc( ex::Expr, by::Array{Symbol,1} )
push!( aggr_args, Expr( :kw, a, Expr( :call, Expr( :ref, :aggrfuncs, QuoteNode( a ) ), lambdasym ) ) )
end

bycolsexpr=Expr( :vcat, map( _->QuoteNode(_), by )... ) # [ :a, :b, :c ... ]
bycolsexpr=Expr( :vcat, map( x->QuoteNode(x), by )... ) # [ :a, :b, :c ... ]
aggrcode = Expr( :->, lambdasym, Expr( :call, DataFrame, aggr_args... ) )
code = :(
function $funnameouter( _df_::AbstractDataFrame, c::Symbol; kwargs... ) # we need kwargs here for aggregate specs
Expand Down Expand Up @@ -311,9 +316,9 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T};
mixedfraction=false,autoscale=:none,conversion=""
)
n = length(breaks)
breakstrs = UTF8String[]
function formatter(_)
prefix * format( _*scale,
breakstrs = String[]
function formatter(x)
prefix * format( x*scale,
precision=precision,
commas=commas,
stripzeros=stripzeros,
Expand All @@ -332,12 +337,12 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T};
else
ncategories = n
end
pool = Array(UTF8String, ncategories )
pool = Array(String, ncategories )
if rank
rankwidth = length(string(ncategories))
end
if !rank
rankprefixfunc = _->""
rankprefixfunc = x->""
elseif reverse
rankprefixfunc = j -> format( n+2-j, width=rankwidth ) * ranksep
else
Expand All @@ -347,7 +352,7 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T};
if S <: Integer && T <: Integer && scale == 1
# we use 1...5, 6, 7...10, 11+etc.
if leftequal
breakminus1strs = UTF8String[]
breakminus1strs = String[]
for b in breaks
push!( breakminus1strs, formatter( b-1 ) )
end
Expand All @@ -367,7 +372,7 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T};
pool[n+1+poolindexshift] = rankprefixfunc(n+1+poolindexshift)*breakstrs[n]*"+"
end
else
breakplus1strs = UTF8String[]
breakplus1strs = String[]
for b in breaks
push!( breakminus1strs, formatter( b+1 ) )
end
Expand All @@ -391,13 +396,13 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T};
if leftequal
brackL = "["
brackR = ")"
compareL = utf8( "<" )
compareL = "<"
compareR = "≥"
else
brackL = "("
brackR = "]"
compareL = "≤"
compareR = utf8(">")
compareR = ">"
end
poolindexshift = -1
if boundedness in [ :unbounded, :boundedabove ]
Expand Down Expand Up @@ -425,9 +430,9 @@ function cut_categories{S<:Real, T<:Real}( ::Type{S}, breaks::Vector{T};
end
if leftequal
compareL = " ≤ "
compareR = utf8(" < ")
compareR = " < "
else
compareL = utf8(" < ")
compareL = " < "
compareR = " ≤ "
end
poolindexshift = -1
Expand Down Expand Up @@ -458,7 +463,7 @@ end
# bounded gives n-1 categories for n breaks. Values below min or above max will be NA
function discretize{S<:Real, T<:Real}(x::AbstractArray{S,1}, breaks::Vector{T};
boundedness = :unbounded,
bucketstrs = UTF8String[], # if provided, all of below will be ignored. length must be length(breaks)+1
bucketstrs = String[], # if provided, all of below will be ignored. length must be length(breaks)+1
leftequal=true, # t1 <= x < t2 or t1 < x <= t2?
absolute=false, # t1 <= |x| < t2?
rank=true, # add a rank to the string output for easier sorting?
Expand Down Expand Up @@ -511,7 +516,7 @@ function discretize{S<:Real, T<:Real}(x::AbstractArray{S,1}, breaks::Vector{T};

if leftequal
for i in 1:length(x)
if isna( x, i )
if ismissing( x, i )
refs[i] = 0
elseif x2[i] < breaks[1]
refs[i] = below_min_mult
Expand All @@ -529,7 +534,7 @@ function discretize{S<:Real, T<:Real}(x::AbstractArray{S,1}, breaks::Vector{T};
end
else
for i in 1:length(x)
if isna( x, i )
if ismissing( x, i )
refs[i] = 0
elseif x2[i] < breaks[1]
refs[i] = below_min_mult
Expand Down Expand Up @@ -579,7 +584,7 @@ end
# use scale=100.0, suffix="%", to express the quantiles in percentages
function discretize{S<:Real}(x::AbstractArray{S,1}; quantiles = Float64[], ngroups::Int = 4, kwargs ... )
if length( quantiles ) != 0
if any( _ -> _ < 0.0 || _ > 1.0 , quantiles )
if any( x -> x < 0.0 || x > 1.0 , quantiles )
error( "illegal quantile numbers outside [0,1]")
end
if !issorted(quantiles)
Expand Down Expand Up @@ -629,12 +634,12 @@ function topnames{S<:AbstractString,T<:Real}( name::AbstractArray{S,1}, measure:
nr = nrow( dfsorted )

if !absolute
pool = UTF8String[]
pool = String[]
refs = fill(zero(DataArrays.DEFAULT_POOLED_REF_TYPE), nr )
lastval = zero( T )
lastrank = 0
for r in 1:nr
if isna( dfsorted[:measure], r )
if ismissing( dfsorted[:measure], r )
continue
else
val = dfsorted[ r, :measure ]
Expand Down Expand Up @@ -663,7 +668,7 @@ function topnames{S<:AbstractString,T<:Real}( name::AbstractArray{S,1}, measure:
lastval = zero( T )
lastrank = 0
for r in 1:nr
if isna( dfsorted[:measure], r )
if ismissing( dfsorted[:measure], r )
continue
else
val = dfsorted[ r, :measure ]
Expand All @@ -684,12 +689,12 @@ function topnames{S<:AbstractString,T<:Real}( name::AbstractArray{S,1}, measure:
end
dfsorted[ :rankedflag ] = rankedflag
dfsorted2 = sort( dfsorted, cols = [ :measure ], rev = [ true ] )
rankstr = DataArray(UTF8String,nr)
rankstr = DataArray(String,nr)
rankcount = 1
lastval = zero( T )
lastrank = 0
for r in 1:nr
if isna( dfsorted2[ :measure ], r )
if ismissing( dfsorted2[ :measure ], r )
continue
elseif dfsorted2[ r, :rankedflag ]
val = dfsorted2[ r, :measure ]
Expand Down Expand Up @@ -735,6 +740,6 @@ end
import DataFrames.describe
export describe

function describe{T}( io, dv::Array{T,1} )
function describe{T}( io::IO, dv::Array{T,1} )
describe( io, DataArray( dv ) )
end
Loading