From b6202eff686dfdc0cb7a0b80f3e79faa54c45f59 Mon Sep 17 00:00:00 2001 From: yha Date: Sat, 29 Apr 2023 00:59:25 +0300 Subject: [PATCH 1/3] Fixed logic of warning on dimension mismatch --- RecipesPipeline/src/utils.jl | 1 + src/recipes.jl | 13 +++++++++---- src/utils.jl | 26 +++++++++++--------------- test/test_animations.jl | 2 +- test/test_misc.jl | 3 ++- test/test_pgfplotsx.jl | 5 +++-- test/test_utils.jl | 2 +- 7 files changed, 28 insertions(+), 24 deletions(-) diff --git a/RecipesPipeline/src/utils.jl b/RecipesPipeline/src/utils.jl index 682b91d01..7ff875c35 100644 --- a/RecipesPipeline/src/utils.jl +++ b/RecipesPipeline/src/utils.jl @@ -150,6 +150,7 @@ for st in ( :volume, :wireframe, :mesh3d, + :spy ) @eval is3d(::Type{Val{Symbol($(string(st)))}}) = true end diff --git a/src/recipes.jl b/src/recipes.jl index 8f75dbeca..eb53e09d0 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -418,7 +418,7 @@ 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)))) @@ -426,7 +426,12 @@ end 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 @@ -490,8 +495,8 @@ end markersize := 0 markeralpha := 0 fillrange := nothing - x := x - y := y + x := procx + y := procy () end @deps bar shape diff --git a/src/utils.jl b/src/utils.jl index 74878824f..78d7b40ce 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -69,10 +69,9 @@ 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) !" @@ -94,6 +93,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...)) @@ -125,21 +126,16 @@ 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 diff --git a/test/test_animations.jl b/test/test_animations.jl index 4ad7fe2e6..d94d9068e 100644 --- a/test/test_animations.jl +++ b/test/test_animations.jl @@ -43,7 +43,7 @@ end circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines) end when i % 5 == 0 fps = 10 - @test_throws LoadError macroexpand( + @test_throws ErrorException macroexpand( @__MODULE__, quote @gif for i in 1:n diff --git a/test/test_misc.jl b/test/test_misc.jl index 9559b4fc7..5a391a861 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -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]), diff --git a/test/test_pgfplotsx.jl b/test/test_pgfplotsx.jl index c37072be5..c1b3fd8b9 100644 --- a/test/test_pgfplotsx.jl +++ b/test/test_pgfplotsx.jl @@ -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) diff --git a/test/test_utils.jl b/test/test_utils.jl index e597c90c2..969099b05 100644 --- a/test/test_utils.jl +++ b/test/test_utils.jl @@ -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 From 6c321056378d85243f4b2229f59c0b0054810cd0 Mon Sep 17 00:00:00 2001 From: yha Date: Sat, 29 Apr 2023 13:34:46 +0300 Subject: [PATCH 2/3] formatting --- RecipesPipeline/src/utils.jl | 2 +- src/recipes.jl | 9 +++++---- src/utils.jl | 8 ++++++-- test/test_misc.jl | 2 +- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/RecipesPipeline/src/utils.jl b/RecipesPipeline/src/utils.jl index 7ff875c35..f91b67abd 100644 --- a/RecipesPipeline/src/utils.jl +++ b/RecipesPipeline/src/utils.jl @@ -150,7 +150,7 @@ for st in ( :volume, :wireframe, :mesh3d, - :spy + :spy, ) @eval is3d(::Type{Val{Symbol($(string(st)))}}) = true end diff --git a/src/recipes.jl b/src/recipes.jl index eb53e09d0..07b2341b6 100644 --- a/src/recipes.jl +++ b/src/recipes.jl @@ -426,11 +426,12 @@ end 1 end else - bw isa AVec && eachindex(bw) != eachindex(procx) && @warn(""" + 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 @@ -705,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 diff --git a/src/utils.jl b/src/utils.jl index 78d7b40ce..e32148eb0 100644 --- a/src/utils.jl +++ b/src/utils.jl @@ -70,7 +70,8 @@ end function iter_segments(args...) i = eachindex(first(args)) - all(eachindex(a) == i for a in args) || @warn "Inconsistent indices of plot args: $(eachindex.(args))" + all(eachindex(a) == i for a in args) || + @warn "Inconsistent indices of plot args: $(eachindex.(args))" NaNSegmentsIterator(args, first(i), last(i)) end @@ -135,7 +136,10 @@ function warn_on_attr_dim_mismatch(series, indices) for attr in _segmenting_vector_attributes 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])) + 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 diff --git a/test/test_misc.jl b/test/test_misc.jl index 5a391a861..9524df5e5 100644 --- a/test/test_misc.jl +++ b/test/test_misc.jl @@ -32,7 +32,7 @@ end plot([missing, missing]), plot(fill(missing, 10)), plot([missing; 1:4]), - plot([missing; 1:4], color=1:5), + 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]), From 77de082065270434673abdafe976a93a2c46dcdf Mon Sep 17 00:00:00 2001 From: yha Date: Tue, 15 Aug 2023 15:05:59 +0300 Subject: [PATCH 3/3] revert ErrorException to LoadError --- test/test_animations.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_animations.jl b/test/test_animations.jl index d94d9068e..4ad7fe2e6 100644 --- a/test/test_animations.jl +++ b/test/test_animations.jl @@ -43,7 +43,7 @@ end circleplot(x, y, i, line_z = 1:n, cbar = false, framestyle = :zerolines) end when i % 5 == 0 fps = 10 - @test_throws ErrorException macroexpand( + @test_throws LoadError macroexpand( @__MODULE__, quote @gif for i in 1:n