Skip to content
This repository has been archived by the owner on May 4, 2019. It is now read-only.

Commit

Permalink
Fix issue #96
Browse files Browse the repository at this point in the history
Issue caused by changes to alignment and related method signatures in the
following PR: JuliaLang/julia#13825
  • Loading branch information
davidagold committed Jan 17, 2016
1 parent f313f06 commit 0009af7
Showing 1 changed file with 156 additions and 45 deletions.
201 changes: 156 additions & 45 deletions src/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ abstract NULL

Base.showcompact(io::IO, ::Type{NULL}) = show(io, NULL)
Base.show(io::IO, ::Type{NULL}) = print(io, "#NULL")
Base.alignment(::Type{NULL}) = (5,0)
Base.alignment(io::IO, ::Type{NULL}) = (5,0)

function Base.show(io::IO, X::NullableArray)
print(io, typeof(X))
Expand All @@ -25,7 +25,7 @@ function Base.show_delim_array(io::IO, X::NullableArray, op, delim, cl,
multiline = false
else
x = X.isnull[i] ? NULL : X.values[i]
multiline = isa(x,AbstractArray) && ndims(x)>1 && length(x)>0
multiline = isa(x, AbstractArray) && ndims(x) > 1 && length(x) > 0
newline && multiline && println(io)
if !isbits(x) && is(x, X)
print(io, "#= circular reference =#")
Expand Down Expand Up @@ -54,19 +54,19 @@ function Base.show_delim_array(io::IO, X::NullableArray, op, delim, cl,
end

function Base.alignment{T,N,U<:NullableArray}(
X::SubArray{T,N,U},
io::IO, X::SubArray{T,N,U},
rows::AbstractVector, cols::AbstractVector,
cols_if_complete::Integer, cols_otherwise::Integer, sep::Integer
)
a = []
for j in cols
l = r = 0
for i in rows
if isassigned(X,i,j)
if isassigned(X, i, j)
if isnull(X, i, j)
aij = alignment(NULL)
aij = alignment(io, NULL)
else
aij = alignment(values(X, i,j))
aij = alignment(io, values(X, i, j))
end
else
aij = undef_ref_alignment
Expand All @@ -75,33 +75,33 @@ function Base.alignment{T,N,U<:NullableArray}(
r = max(r, aij[2])
end
push!(a, (l, r))
if length(a) > 1 && sum(map(sum,a)) + sep*length(a) >= cols_if_complete
if length(a) > 1 && sum(map(sum, a)) + sep*length(a) >= cols_if_complete
pop!(a)
break
end
end
if 1 < length(a) < size(X,2)
while sum(map(sum,a)) + sep*length(a) >= cols_otherwise
if 1 < length(a) < size(X, 2)
while sum(map(sum, a)) + sep*length(a) >= cols_otherwise
pop!(a)
end
end
return a
end

function Base.alignment(
X::Union{NullableArray, NullableMatrix},
io::IO, X::Union{NullableArray, NullableMatrix},
rows::AbstractVector, cols::AbstractVector,
cols_if_complete::Integer, cols_otherwise::Integer, sep::Integer
)
a = []
for j in cols
l = r = 0
for i in rows
if isassigned(X,i,j)
if isassigned(X, i, j)
if isnull(X, i, j)
aij = alignment(NULL)
aij = alignment(io, NULL)
else
aij = alignment(values(X, i,j))
aij = alignment(io, values(X, i, j))
end
else
aij = undef_ref_alignment
Expand All @@ -115,52 +115,163 @@ function Base.alignment(
break
end
end
if 1 < length(a) < size(X,2)
while sum(map(sum,a)) + sep*length(a) >= cols_otherwise
if 1 < length(a) < size(X, 2)
while sum(map(sum, a)) + sep*length(a) >= cols_otherwise
pop!(a)
end
end
return a
end

function Base.print_matrix_row{T,N,P<:NullableArray}(io::IO,
X::SubArray{T,N,P}, A::Vector,
function Base.print_matrix_row{T,N,P<:NullableArray}(
io::IO, X::SubArray{T,N,P}, A::Vector,
i::Integer, cols::AbstractVector, sep::AbstractString
)
for k = 1:length(A)
j = cols[k]
if isassigned(X,i,j)
x = isnull(X,i,j) ? NULL : values(X,i,j)
a = alignment(x)
sx = sprint(showcompact_lim, x)
else
a = undef_ref_alignment
sx = undef_ref_str
end
l = repeat(" ", A[k][1]-a[1])
r = repeat(" ", A[k][2]-a[2])
print(io, l, sx, r)
if k < length(A); print(io, sep); end
if VERSION < v"0.5.0-dev+1936" # compat issues from
# https://github.com/JuliaLang/julia/pull/13825
for k = 1:length(A)
j = cols[k]
if isassigned(X, i, j)
x = isnull(X, i, j) ? NULL : values(X, i, j)
a = alignment(x)
sx = sprint(showcompact_lim, x)
else
a = undef_ref_alignment
sx = undef_ref_str
end
l = repeat(" ", A[k][1]-a[1])
r = repeat(" ", A[k][2]-a[2])
print(io, l, sx, r)
if k < length(A); print(io, sep); end
end
else
for k = 1:length(A)
j = cols[k]
if isassigned(X, i, j)
x = isnull(X, i, j) ? NULL : values(X, i, j)
a = alignment(io, x)
sx = sprint(showcompact_lim, x)
else
a = undef_ref_alignment
sx = undef_ref_str
end
l = repeat(" ", A[k][1]-a[1])
r = repeat(" ", A[k][2]-a[2])
print(io, l, sx, r)
if k < length(A); print(io, sep); end
end
end
end

function Base.print_matrix_row(io::IO,
X::Union{NullableVector, NullableMatrix}, A::Vector,
i::Integer, cols::AbstractVector, sep::AbstractString
)
for k = 1:length(A)
j = cols[k]
if isassigned(X,i,j)
x = isnull(X,i,j) ? NULL : values(X,i,j)
a = alignment(x)
sx = sprint(showcompact_lim, x)
else
a = undef_ref_alignment
sx = undef_ref_str
end
l = repeat(" ", A[k][1]-a[1])
r = repeat(" ", A[k][2]-a[2])
print(io, l, sx, r)
if k < length(A); print(io, sep); end
if VERSION < v"0.5.0-dev+1936" # compat issues from
# https://github.com/JuliaLang/julia/pull/13825
for k = 1:length(A)
j = cols[k]
if isassigned(X, i, j)
x = isnull(X, i, j) ? NULL : values(X, i, j)
a = alignment(x)
sx = sprint(showcompact_lim, x)
else
a = undef_ref_alignment
sx = undef_ref_str
end
l = repeat(" ", A[k][1]-a[1])
r = repeat(" ", A[k][2]-a[2])
print(io, l, sx, r)
if k < length(A); print(io, sep); end
end
else
for k = 1:length(A)
j = cols[k]
if isassigned(X, i, j)
x = isnull(X, i, j) ? NULL : values(X, i, j)
a = alignment(io, x)
sx = sprint(showcompact_lim, x)
else
a = undef_ref_alignment
sx = undef_ref_str
end
l = repeat(" ", A[k][1]-a[1])
r = repeat(" ", A[k][2]-a[2])
print(io, l, sx, r)
if k < length(A); print(io, sep); end
end
end
end

# Methods for compatibility issues for VERSION < 0.5.0-dev+1936 stemming
# from https://github.com/JuliaLang/julia/pull/13825

Base.alignment(::Type{NULL}) = (5,0)
function Base.alignment{T,N,U<:NullableArray}(
X::SubArray{T,N,U},
rows::AbstractVector, cols::AbstractVector,
cols_if_complete::Integer, cols_otherwise::Integer, sep::Integer
)
a = []
for j in cols
l = r = 0
for i in rows
if isassigned(X, i, j)
if isnull(X, i, j)
aij = alignment(NULL)
else
aij = alignment(values(X, i, j))
end
else
aij = undef_ref_alignment
end
l = max(l, aij[1])
r = max(r, aij[2])
end
push!(a, (l, r))
if length(a) > 1 && sum(map(sum, a)) + sep*length(a) >= cols_if_complete
pop!(a)
break
end
end
if 1 < length(a) < size(X, 2)
while sum(map(sum, a)) + sep*length(a) >= cols_otherwise
pop!(a)
end
end
return a
end
function Base.alignment(
X::Union{NullableArray, NullableMatrix},
rows::AbstractVector, cols::AbstractVector,
cols_if_complete::Integer, cols_otherwise::Integer, sep::Integer
)
a = []
for j in cols
l = r = 0
for i in rows
if isassigned(X, i, j)
if isnull(X, i, j)
aij = alignment(NULL)
else
aij = alignment(values(X, i, j))
end
else
aij = undef_ref_alignment
end
l = max(l, aij[1])
r = max(r, aij[2])
end
push!(a, (l, r))
if length(a) > 1 && sum(map(sum,a)) + sep*length(a) >= cols_if_complete
pop!(a)
break
end
end
if 1 < length(a) < size(X, 2)
while sum(map(sum, a)) + sep*length(a) >= cols_otherwise
pop!(a)
end
end
return a
end

0 comments on commit 0009af7

Please sign in to comment.