Skip to content

Commit f766ac7

Browse files
committed
Avoid calling extrema(...; dims) with empty arrays. See PR #1711
1 parent 1f3ac2a commit f766ac7

10 files changed

+16
-1
lines changed

src/extras/lowess.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ function lowess(x::AbstractVector{R}, y::AbstractVector{S}; span::T=2/3, nsteps:
4040
lowess((R <: AbstractFloat) ? x : Vector{Float64}(x), (S <: AbstractFloat) ? y : Vector{Float64}(y); span=span, nsteps=nsteps, delta=delta)
4141
end
4242

43-
function lowess(mat::Matrix{<:Real}; span=2/3, nsteps::Integer=3, delta=0.1*diff(collect(extrema(view(mat, :,2))), dims=1)[1])
43+
function lowess(mat::Matrix{<:Real}; span=2/3, nsteps::Integer=3, delta=0.0)
44+
isempty(mat) && error("lowess: 'mat' cannot be an empty matrix")
45+
(delta == 0.0) && (delta = 0.1*diff(collect(extrema(view(mat, :,2))), dims=1)[1])
4446
new_y = lowess(view(mat, :,1), view(mat, :,2); span=span, nsteps=nsteps, delta=delta)
4547
return [mat[:,1] new_y]
4648
end

src/gmt_main.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1431,6 +1431,7 @@ function ogr2GMTdataset(in::Ptr{OGR_FEATURES}, drop_islands=false)::Union{GMTdat
14311431
end
14321432
(n_total_segments > (n-1)) && deleteat!(D, n:n_total_segments)
14331433
for k = 1:length(D) # Compute the BoundingBoxes per segment (C version doesn't do it)
1434+
isempty(D[k].data) && continue # #1711
14341435
bb = Base.invokelatest(extrema, D[k].data, dims=1) # A N Tuple.
14351436
D[k].bbox = collect(Float64, Iterators.flatten(bb))
14361437
end

src/grd_operations.jl

+1
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,7 @@ function rotate(FV::GMTfv, a=Float64[]; rx=0.0, ry=0.0, rz=0.0, insitu::Bool=fal
467467
!isempty(a) && (@assert length(a) == 3 "Angle vector must be of length 3")
468468
isempty(a) && (a = [rx, ry, rz])
469469
V = FV.verts * eulermat(a)[1]
470+
isempty(V) && error("The 'V' input cannot be empty.") # #1711
470471
mimas = extrema(V, dims=1)
471472
bbox = [mimas[1][1], mimas[1][2], mimas[2][1], mimas[2][2], mimas[3][1], mimas[3][2]] # So stu..
472473
if insitu

src/imgtiles.jl

+1
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,7 @@ function quadbounds_limits(quadtree::Matrix{<:AbstractString}; geog=true, quadke
708708
flatness = 0.0
709709

710710
tiles_bb = zeros(length(quadtree), 4)
711+
isempty(tiles_bb) && error("The 'quadtree' input cannot be empty.") # #1711
711712
zoomL = 0 # Can't stand this need. F. F. F
712713
for k = 1:length(quadtree)
713714
lim, zoomL = getQuadLims(quadtree[k], quadkey, "") # Remember that lim(3) = y_max

src/laszip/lazwrite.jl

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ end
2323
function lazwrite(fname::AbstractString, xyz; grd_hdr=Float64[], scaleX=nothing, scaleY=nothing, scaleZ=nothing,
2424
offX=nothing, offY=nothing, offZ=nothing, layout::String="")
2525

26+
isempty(xyz) && error("The 'xyz' input cannot be empty as it is.")
2627
n_rows, n_cols = parse_inputs_dat2las(xyz, grd_hdr)
2728

2829
if (!isempty(grd_hdr))

src/linefit.jl

+1
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ function plotlinefit(D::GMTdataset; first::Bool=true, grp::Bool=false, kw...)
245245
tl, bl = (a - σa) .+ (b + σb)*X, (a + σa) .+ (b - σb)*X
246246
recta = a .+ b * X
247247
if (do_rib_ab)
248+
(isempty(tl) || isempty(bl)) && error("One of 'tl'' or ''bl'' is empty."); # Should never happen but see #1711
248249
σp, σm = vec(maximum([tl bl], dims=2)) .- recta, recta .- vec(minimum([tl bl], dims=2))
249250
end
250251

src/plot.jl

+3
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,7 @@ function stem(cmd0::String="", arg1=nothing; first=true, kwargs...)
909909
add2ds!(arg1[1]) # Fix arg1 meta after column insertion.
910910
end
911911
else # Case of plain matrices
912+
isempty(arg1) && error("stem: 'arg1' cannot be empty.")
912913
if (!haveR)
913914
mm = extrema(arg1, dims=1)
914915
mimas = [mm[1][1], mm[1][2], mm[2][1], mm[2][2]]
@@ -1080,6 +1081,8 @@ end
10801081
function helper_vecBug(d, arg1, first::Bool, haveR::Bool, haveVarFill::Bool, typevec::Int; isfeather::Bool=false)
10811082
# Helper function that deals with setting several defaults and mostly patch a GMT vectors bug.
10821083
# TYPEVEC = 0, ==> u,v = theta,rho. TYPEVEC = 1, ==> u,v = u,v. TYPEVEC = 2, ==> u,v = x2,y2
1084+
1085+
isempty(arg1) && error("'arg1' input cannot be empty.")
10831086

10841087
function get_minmaxs(D::GMTdataset)
10851088
# Get x,y minmax from datasets that may have had teir columns rearranged.

src/pshistogram.jl

+2
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ function histogram_helper(cmd0::String, arg1; first=true, kwargs...)
166166
do_zoom = ((find_in_dict(d, [:zoom])[1]) !== nothing) ? true : false # Automatic zoom to interesting region
167167

168168
function if_zoom(cmd, opt_R, limit_L, hst)
169+
isempty(hst) && error("No histogram data to compute the region limits.")
169170
mm = extrema(hst, dims=1) # 1×2 Array{Tuple{UInt16,UInt16},2}
170171
x_max = min(limit_R * 1.15, hst[end,1]) # 15% to the right but not fall the cliff
171172
opt_R_ = " -R$(limit_L * 0.85)/$x_max/0/$(mm[2][2] * 1.1) "
@@ -259,6 +260,7 @@ function histogram_helper(cmd0::String, arg1; first=true, kwargs...)
259260
# And if wished, plot the two vertical lines with the limits annotated in them
260261
if (limit_L !== nothing)
261262
if (opt_R == " ") # Set a region for the vlines
263+
isempty(hst) && error("No histogram data to compute the region limits.")
262264
mm = extrema(hst, dims=1)
263265
opt_R = " -R$(mm[1][1])/$(mm[1][2])/0/$(mm[2][2])"
264266
end

src/statplots.jl

+1
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,7 @@ function parplot_helper(cmd0::String, arg1; first::Bool=true, axeslabels::Vector
11081108
labels::Vector{String}=String[], group::AbstractVector=AbstractVector[], groupvar="", normalize="range", kwargs...)
11091109
d = KW(kwargs)
11101110
(cmd0 != "") && (arg1 = read_data(d, cmd0, "", arg1, " ", false, true)[2]) # Make sure we have the data here
1111+
isempty(arg1) && error("The 'arg1' input cannot be empty.") # #1711
11111112
if (isa(arg1, Matrix{<:Real})) data = mat2ds(arg1)
11121113
elseif (isa(arg1, Vector{<:GMTdataset})) data = ds2ds(arg1)
11131114
else data = mat2ds(arg1)

src/utils_types.jl

+2
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,7 @@ function set_dsBB!(D, all_bbs::Bool=true)
544544

545545
if (all_bbs) # Compute all BBs
546546
if isa(D, GMTdataset)
547+
isempty(D.data) && return nothing # Likely a Text only DS
547548
D.ds_bbox = D.bbox = collect(Float64, Iterators.flatten(extrema(D.data, dims=1)))
548549
ind = findall(.!isfinite.(D.bbox)) # If we have some columns with NaNs or Infs
549550
if (!isempty(ind))
@@ -555,6 +556,7 @@ function set_dsBB!(D, all_bbs::Bool=true)
555556
return nothing
556557
else
557558
for k = 1:lastindex(D)
559+
isempty(D[k].data) && continue # Likely a Text only DS
558560
bb = Base.invokelatest(extrema, D[k].data, dims=1) # A N Tuple.
559561
_bb = collect(Float64, Iterators.flatten(bb))
560562
if (any(isnan.(_bb))) # Shit, we don't have a minimum_nan(A, dims)

0 commit comments

Comments
 (0)