Skip to content

Commit 6e33f9d

Browse files
Felix Cremerrafaqz
andauthored
Add _show_data function to skip data loading during show (#1130)
* Add _show_data function to ensure DiskArrays don't try to load data during show * Apply suggestions from code reviewRename to can_show_data Co-authored-by: Rafael Schouten <[email protected]> * Fix DiskArray show test * Convert string descriptors to comments in Makie tests This is to fix the nightly tests. Because the behaviour has changed in Julia 1.14 --------- Co-authored-by: Rafael Schouten <[email protected]>
1 parent 6db30de commit 6e33f9d

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

ext/DimensionalDataDiskArraysExt.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ DiskArrays.eachchunk(da::AbstractBasicDimArray) = DiskArrays.eachchunk(parent(da
1616

1717
# Only define methods if they are available,
1818
# to avoid dropping older DiskArrays versions
19-
# TODO remove these checks
19+
# TODO remove these checks when we drop DiskArrays below 0.4.8
2020
@static if isdefined(DiskArrays, :isdisk)
2121
DiskArrays.isdisk(x::AbstractDimArray) = DiskArrays.isdisk(parent(x))
2222
DiskArrays.isdisk(x::AbstractDimStack) = any(map(DiskArrays.isdisk, layers(x)))
@@ -96,4 +96,6 @@ end
9696
modify(A -> DiskArrays.mockchunks(A, chunks), x)
9797
end
9898

99+
DD.can_show_data(A::DiskArrays.AbstractDiskArray) = false
100+
99101
end

src/array/show.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,14 @@ But read the DimensionalData.jl `show.jl` code for details.
9191
function show_after(io::IO, mime, A::AbstractBasicDimArray)
9292
blockwidth = get(io, :blockwidth, 0)
9393
print_block_close(io, blockwidth)
94+
can_show_data(parent(A)) || return
9495
ndims(A) > 0 && println(io)
9596
any(==(0), size(A)) && return
9697
print_array(io, mime, A)
9798
end
9899

100+
can_show_data(A) = true
101+
99102
function print_ndims(io, size::Tuple;
100103
colors=map(dimcolor, ntuple(identity, length(size)))
101104
)

test/makie.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -744,12 +744,12 @@ end
744744
volumeslices!(ax, A3abc; zdim=:a)
745745
volumeslices!(A3abc;zdim=:a)
746746

747-
"LScene support"
747+
#LScene support
748748
f, a, p = heatmap(A2ab; axis=(; type=LScene, show_axis=false))
749749
@test a isa LScene
750750
@test isnothing(a.scene[OldAxis])
751751

752-
"Colorbar support"
752+
#Colorbar support
753753
fig, ax, _ = plot(A2ab; colorbar=(; width=50))
754754
colorbars = filter(x -> x isa Colorbar, fig.content)
755755
@test length(colorbars) == 1

test/show.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using DimensionalData, Test, Dates
22
using DimensionalData.Lookups, DimensionalData.Dimensions
33
using DimensionalData: LazyLabelledPrintMatrix, ShowWith, showrowlabel, showcollabel, showarrows
4+
using DiskArrays.TestTypes: AccessCountDiskArray, getindex_count
45

56
# define dims with both long name and Type name
67
@dim Lon "Longitude"
@@ -261,4 +262,11 @@ end
261262
@test occursin("mybranch", sc)
262263
@test occursin(":c", sc)
263264

265+
end
266+
267+
@testset "DiskArray show" begin
268+
da = AccessCountDiskArray(rand(10,10))
269+
dd = DimArray(da, (X(1:10), Y(1:10)))
270+
sc = sprint(show, MIME("text/plain"), dd)
271+
@test getindex_count(da) == 0
264272
end

0 commit comments

Comments
 (0)