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

Fixed logic of warning on dimension mismatch #4735

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions RecipesPipeline/src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ for st in (
:volume,
:wireframe,
:mesh3d,
:spy,
)
@eval is3d(::Type{Val{Symbol($(string(st)))}}) = true
end
Expand Down
18 changes: 12 additions & 6 deletions src/recipes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -418,15 +418,21 @@ end
end

# compute half-width of bars
bw = plotattributes[:bar_width]
bw = pop_kw!(plotattributes, :bar_width)
hw = if bw === nothing
0.5_bar_width * if nx > 1
ignorenan_minimum(filter(x -> x > 0, diff(sort(procx))))
else
1
end
else
map(i -> 0.5_cycle(bw, i), eachindex(procx))
bw isa AVec &&
eachindex(bw) != eachindex(procx) &&
@warn """
Indices of `bar_width` attribute ($(eachindex(bw))) do not match data indices ($(eachindex(procx))).
Bar widths will be repeated cyclically.
"""
bw ./ 2
end

# make fillto a vector... default fills to 0
Expand Down Expand Up @@ -490,8 +496,8 @@ end
markersize := 0
markeralpha := 0
fillrange := nothing
x := x
y := y
x := procx
y := procy
()
end
@deps bar shape
Expand Down Expand Up @@ -700,10 +706,10 @@ end
@deps stepbins path

function wand_edges(x...)
@warn """"
@warn """
Load the StatsPlots package in order to use :wand bins.
Defaulting to :auto
""" once = true
""" maxlog = 1
:auto
end

Expand Down
30 changes: 15 additions & 15 deletions src/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,10 @@ struct NaNSegmentsIterator
end

function iter_segments(args...)
tup = Plots.wraptuple(args)
n1 = minimum(map(firstindex, tup))
n2 = maximum(map(lastindex, tup))
NaNSegmentsIterator(tup, n1, n2)
i = eachindex(first(args))
all(eachindex(a) == i for a in args) ||
@warn "Inconsistent indices of plot args: $(eachindex.(args))"
NaNSegmentsIterator(args, first(i), last(i))
end

"floor number x in base b, note this is different from using Base.round(...; base=b) !"
Expand All @@ -94,6 +94,8 @@ function series_segments(series::Series, seriestype::Symbol = :path; check = fal
x, y, z = series[:x], series[:y], series[:z]
(x === nothing || isempty(x)) && return UnitRange{Int}[]

warn_on_attr_dim_mismatch(series, eachindex(x))

args = RecipesPipeline.is3d(series) ? (x, y, z) : (x, y)
nan_segments = collect(iter_segments(args...))

Expand Down Expand Up @@ -125,21 +127,19 @@ function series_segments(series::Series, seriestype::Symbol = :path; check = fal
else
(SeriesSegment(r, 1) for r in nan_segments)
end

warn_on_attr_dim_mismatch(series, x, y, z, segments)
segments
end

function warn_on_attr_dim_mismatch(series, x, y, z, segments)
isempty(segments) && return
seg_range = UnitRange(
minimum(map(seg -> first(seg.range), segments)),
maximum(map(seg -> last(seg.range), segments)),
)
function warn_on_attr_dim_mismatch(series, indices)

# TODO a more precise set of attributes that is relevant here?
for attr in _segmenting_vector_attributes
if (v = get(series, attr, nothing)) isa AVec && eachindex(v) != seg_range
@warn "Indices $(eachindex(v)) of attribute `$attr` does not match data indices $seg_range."
if any(v -> !isnothing(v) && any(isnan, v), (x, y, z))
if (v = get(series, attr, nothing)) isa AVec && eachindex(v) != indices
@warn "Indices $(eachindex(v)) of attribute `$attr` does not match data indices $indices."
if any(
v -> !isnothing(v) && any(isnan, v),
(series[:x], series[:y], series[:z]),
)
@info """Data contains NaNs or missing values, and indices of `$attr` vector do not match data indices.
If you intend elements of `$attr` to apply to individual NaN-separated segments in the data,
pass each segment in a separate vector instead, and use a row vector for `$attr`. Legend entries
Expand Down
3 changes: 2 additions & 1 deletion test/test_misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ end
dsp = TextDisplay(IOContext(IOBuffer(), :color => true))

@testset "plot" begin
for pl in [
@test_nowarn for pl in [
histogram([1, 0, 0, 0, 0, 0]),
plot([missing]),
plot([missing, missing]),
plot(fill(missing, 10)),
plot([missing; 1:4]),
plot([missing; 1:4], color = 1:5),
plot([fill(missing, 10); 1:4]),
plot([1 1; 1 missing]),
plot(["a" "b"; missing "d"], [1 2; 3 4]),
Expand Down
5 changes: 3 additions & 2 deletions test/test_pgfplotsx.jl
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,12 @@ with(:pgfplotsx) do
end

@testset "Markers and Paths" begin
cycle_upto(itr, n) = collect(Iterators.take(Iterators.cycle(itr), n))
pl = plot(
5 .- ones(9),
markershape = [:utriangle, :rect],
markershape = cycle_upto([:utriangle, :rect], 9),
markersize = 8,
color = [:red, :black],
color = cycle_upto([:red, :black], 9),
)
axis_contents = first(get_pgf_axes(pl)).contents
plots = filter(x -> x isa PGFPlotsX.Plot, axis_contents)
Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ end
@test segments([nan10; 1:5]) == [11:15]
@test segments([1:5; nan10]) == [1:5]
@test segments([nan10; 1:5; nan10; 1:5; nan10]) == [11:15, 26:30]
@test segments([NaN; 1], 1:10) == [2:2, 4:4, 6:6, 8:8, 10:10]
@test segments(repeat([NaN; 1], 5), 1:10) == [2:2, 4:4, 6:6, 8:8, 10:10]
@test segments([nan10; 1:15], [1:15; nan10]) == [11:15]
end

Expand Down
Loading