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

fix show box for vscode #885

Merged
merged 2 commits into from
Dec 14, 2024
Merged
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
9 changes: 3 additions & 6 deletions src/Dimensions/dimension.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ A = DimArray(zeros(3, 5, 12), (y, x, ti))

# output

╭─────────────────────────────╮
│ 3×5×12 DimArray{Float64, 3} │
┌ 3×5×12 DimArray{Float64, 3} ┐
├─────────────────────────────┴────────────────────────────────────────── dims ┐
↓ Y Categorical{Char} ['a', 'b', 'c'] ForwardOrdered,
→ X Sampled{Int64} 2:2:10 ForwardOrdered Regular Points,
Expand All @@ -54,8 +53,7 @@ x = A[X(2), Y(3)]

# output

╭─────────────────────────────────╮
│ 12-element DimArray{Float64, 1} │
┌ 12-element DimArray{Float64, 1} ┐
├─────────────────────────────────┴────────────────────────────────────── dims ┐
↓ Ti Sampled{DateTime} DateTime("2021-01-01T00:00:00"):Month(1):DateTime("2021-12-01T00:00:00") ForwardOrdered Regular Points
└──────────────────────────────────────────────────────────────────────────────┘
Expand All @@ -80,8 +78,7 @@ x = A[X(Between(3, 4)), Y(At('b'))]

# output

╭───────────────────────────╮
│ 1×12 DimArray{Float64, 2} │
┌ 1×12 DimArray{Float64, 2} ┐
├───────────────────────────┴──────────────────────────────────────────── dims ┐
↓ X Sampled{Int64} 4:2:4 ForwardOrdered Regular Points,
→ Ti Sampled{DateTime} DateTime("2021-01-01T00:00:00"):Month(1):DateTime("2021-12-01T00:00:00") ForwardOrdered Regular Points
Expand Down
6 changes: 2 additions & 4 deletions src/Dimensions/primitives.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ any combination of either.
julia> using DimensionalData

julia> A = DimArray(ones(2, 3, 2), (X, Y, Z))
╭────────────────────────────╮
│ 2×3×2 DimArray{Float64, 3} │
┌ 2×3×2 DimArray{Float64, 3} ┐
├────────────────────── dims ┤
↓ X, → Y, ↗ Z
└────────────────────────────┘
Expand Down Expand Up @@ -364,8 +363,7 @@ A = ones(X(2), Y(4), Z(2))
Dimensions.swapdims(A, (Dim{:a}, Dim{:b}, Dim{:c}))

# output
╭────────────────────────────╮
│ 2×4×2 DimArray{Float64, 3} │
┌ 2×4×2 DimArray{Float64, 3} ┐
├────────────────────── dims ┤
↓ a, → b, ↗ c
└────────────────────────────┘
Expand Down
3 changes: 1 addition & 2 deletions src/Lookups/lookup_arrays.jl
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,7 @@ y = Y(Sampled([1, 4, 7, 10]; span=Regular(3), sampling=Intervals(Start())))
A = ones(x, y)

# output
╭──────────────────────────╮
│ 5×4 DimArray{Float64, 2} │
┌ 5×4 DimArray{Float64, 2} ┐
├──────────────────────────┴───────────────────────────────────────── dims ┐
↓ X Sampled{Int64} 100:-20:20 ReverseOrdered Regular Intervals{Start},
→ Y Sampled{Int64} [1, 4, 7, 10] ForwardOrdered Regular Intervals{Start}
Expand Down
12 changes: 4 additions & 8 deletions src/Lookups/selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,7 @@ A[X(Between(15, 25)), Y(Between(4, 6.5))]

# output

╭────────────────────────╮
│ 1×2 DimArray{Int64, 2} │
┌ 1×2 DimArray{Int64, 2} ┐
├────────────────────────┴───────────────────────────── dims ┐
↓ X Sampled{Int64} 20:10:20 ForwardOrdered Regular Points,
→ Y Sampled{Int64} 5:6 ForwardOrdered Regular Points
Expand Down Expand Up @@ -807,8 +806,7 @@ A = DimArray([1 2 3; 4 5 6], (X(10:10:20), Y(5:7)))
A[X(Touches(15, 25)), Y(Touches(4, 6.5))]

# output
╭────────────────────────╮
│ 1×2 DimArray{Int64, 2} │
┌ 1×2 DimArray{Int64, 2} ┐
├────────────────────────┴───────────────────────────── dims ┐
↓ X Sampled{Int64} 20:10:20 ForwardOrdered Regular Points,
→ Y Sampled{Int64} 5:6 ForwardOrdered Regular Points
Expand Down Expand Up @@ -975,8 +973,7 @@ A[X(Where(x -> x > 15)), Y(Where(x -> x in (19, 21)))]

# output

╭────────────────────────╮
│ 1×2 DimArray{Int64, 2} │
┌ 1×2 DimArray{Int64, 2} ┐
├────────────────────────┴────────────────────────────── dims ┐
↓ X Sampled{Int64} [20] ForwardOrdered Irregular Points,
→ Y Sampled{Int64} [19, 21] ForwardOrdered Irregular Points
Expand Down Expand Up @@ -1017,8 +1014,7 @@ A[X=All(At(10.0), At(50.0)), Ti=All(1u"s"..10u"s", 90u"s"..100u"s")]

# output

╭────────────────────────╮
│ 2×4 DimArray{Int64, 2} │
┌ 2×4 DimArray{Int64, 2} ┐
├────────────────────────┴─────────────────────────────────────────────── dims ┐
↓ X Sampled{Float64} [10.0, 50.0] ForwardOrdered Irregular Points,
→ Ti Sampled{Unitful.Quantity{Int64, 𝐓, Unitful.FreeUnits{(s,), 𝐓, nothing}}} [1 s, 6 s, 91 s, 96 s] ForwardOrdered Irregular Points
Expand Down
30 changes: 10 additions & 20 deletions src/array/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,15 @@ julia> x = X(10:10:100);
julia> A = DimArray(rand(12,10), (ti, x), name="example");

julia> A[X(Near([12, 35])), Ti(At(DateTime(2001,5)))]
╭────────────────────────────────────────╮
│ 2-element DimArray{Float64, 1} example │
┌ 2-element DimArray{Float64, 1} example ┐
├────────────────────────────────────────┴────────────── dims ┐
↓ X Sampled{Int64} [10, 40] ForwardOrdered Irregular Points
└─────────────────────────────────────────────────────────────┘
10 0.253849
40 0.637077

julia> A[Near(DateTime(2001, 5, 4)), Between(20, 50)]
╭────────────────────────────────────────╮
│ 4-element DimArray{Float64, 1} example │
┌ 4-element DimArray{Float64, 1} example ┐
├────────────────────────────────────────┴──────────── dims ┐
↓ X Sampled{Int64} 20:10:50 ForwardOrdered Regular Points
└───────────────────────────────────────────────────────────┘
Expand All @@ -425,8 +423,7 @@ Generator expression:

```jldoctest dimarray
julia> DimArray((x, y) for x in X(1:3), y in Y(1:2); name = :Value)
╭────────────────────────────────────────────╮
│ 3×2 DimArray{Tuple{Int64, Int64}, 2} Value │
┌ 3×2 DimArray{Tuple{Int64, Int64}, 2} Value ┐
├────────────────────────────────────────────┴──── dims ┐
↓ X Sampled{Int64} 1:3 ForwardOrdered Regular Points,
→ Y Sampled{Int64} 1:2 ForwardOrdered Regular Points
Expand Down Expand Up @@ -545,8 +542,7 @@ Keywords are the same as for [`DimArray`](@ref).
julia> using DimensionalData, Random; Random.seed!(123);

julia> fill(true, X(2), Y(4))
╭───────────────────────╮
│ 2×4 DimArray{Bool, 2} │
┌ 2×4 DimArray{Bool, 2} ┐
├───────────────── dims ┤
↓ X, → Y
└───────────────────────┘
Expand Down Expand Up @@ -578,17 +574,15 @@ Keywords are the same as for [`DimArray`](@ref).
julia> using DimensionalData

julia> rand(Bool, X(2), Y(4))
╭───────────────────────╮
│ 2×4 DimArray{Bool, 2} │
┌ 2×4 DimArray{Bool, 2} ┐
├───────────────── dims ┤
↓ X, → Y
└───────────────────────┘
0 0 0 0
1 0 0 1

julia> rand(X([:a, :b, :c]), Y(100.0:50:200.0))
╭──────────────────────────╮
│ 3×3 DimArray{Float64, 2} │
┌ 3×3 DimArray{Float64, 2} ┐
├──────────────────────────┴──────────────────────────────────── dims ┐
↓ X Categorical{Symbol} [:a, :b, :c] ForwardOrdered,
→ Y Sampled{Float64} 100.0:50.0:200.0 ForwardOrdered Regular Points
Expand Down Expand Up @@ -621,17 +615,15 @@ Keywords are the same as for [`DimArray`](@ref).
julia> using DimensionalData

julia> zeros(Bool, X(2), Y(4))
╭───────────────────────╮
│ 2×4 DimArray{Bool, 2} │
┌ 2×4 DimArray{Bool, 2} ┐
├───────────────── dims ┤
↓ X, → Y
└───────────────────────┘
0 0 0 0
0 0 0 0

julia> zeros(X([:a, :b, :c]), Y(100.0:50:200.0))
╭──────────────────────────╮
│ 3×3 DimArray{Float64, 2} │
┌ 3×3 DimArray{Float64, 2} ┐
├──────────────────────────┴──────────────────────────────────── dims ┐
↓ X Categorical{Symbol} [:a, :b, :c] ForwardOrdered,
→ Y Sampled{Float64} 100.0:50.0:200.0 ForwardOrdered Regular Points
Expand Down Expand Up @@ -665,17 +657,15 @@ Keywords are the same as for [`DimArray`](@ref).
julia> using DimensionalData

julia> ones(Bool, X(2), Y(4))
╭───────────────────────╮
│ 2×4 DimArray{Bool, 2} │
┌ 2×4 DimArray{Bool, 2} ┐
├───────────────── dims ┤
↓ X, → Y
└───────────────────────┘
1 1 1 1
1 1 1 1

julia> ones(X([:a, :b, :c]), Y(100.0:50:200.0))
╭──────────────────────────╮
│ 3×3 DimArray{Float64, 2} │
┌ 3×3 DimArray{Float64, 2} ┐
├──────────────────────────┴──────────────────────────────────── dims ┐
↓ X Categorical{Symbol} [:a, :b, :c] ForwardOrdered,
→ Y Sampled{Float64} 100.0:50.0:200.0 ForwardOrdered Regular Points
Expand Down
6 changes: 2 additions & 4 deletions src/array/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@ print_type(io, x) = print(io, string(nameof(typeof(x))))
function print_top(io, mime, A)
_, displaywidth = displaysize(io)
blockwidth = min(displaywidth - 2, textwidth(sprint(summary, A)) + 2)
printstyled(io, '╭', '─'^blockwidth, '╮'; color=:light_black)
println(io)
printstyled(io, "│ "; color=:light_black)
printstyled(io, "┌ "; color=:light_black)
summary(io, A)
printstyled(io, " "; color=:light_black)
printstyled(io, " "; color=:light_black)
println(io)
n, blockwidth = print_dims_block(io, mime, dims(A); displaywidth, blockwidth)
lines = 2 + n
Expand Down
12 changes: 4 additions & 8 deletions src/dimindices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ are not in the same order. Or even if they are not all contained in each.

```jldoctest; setup = :(using DimensionalData, Random; Random.seed!(123))
julia> A = rand(Y(0.0:0.3:1.0), X('a':'f'))
╭──────────────────────────╮
│ 4×6 DimArray{Float64, 2} │
┌ 4×6 DimArray{Float64, 2} ┐
├──────────────────────────┴──────────────────────────────── dims ┐
↓ Y Sampled{Float64} 0.0:0.3:0.9 ForwardOrdered Regular Points,
→ X Categorical{Char} 'a':1:'f' ForwardOrdered
Expand All @@ -89,8 +88,7 @@ julia> A = rand(Y(0.0:0.3:1.0), X('a':'f'))
0.9 0.512083 0.867547 0.136551 0.959434 0.150155 0.941133

julia> di = DimIndices((X(1:2:4), Y(1:2:4)))
╭──────────────────────────────────────────────╮
│ 2×2 DimIndices{Tuple{X{Int64}, Y{Int64}}, 2} │
┌ 2×2 DimIndices{Tuple{X{Int64}, Y{Int64}}, 2} ┐
├──────────────────────────────────────── dims ┤
↓ X 1:2:3,
→ Y 1:2:3
Expand All @@ -100,8 +98,7 @@ julia> di = DimIndices((X(1:2:4), Y(1:2:4)))
3 (↓ X 3, → Y 1) (↓ X 3, → Y 3)

julia> A[di] # Index A with these indices
╭──────────────────────────╮
│ 2×2 DimArray{Float64, 2} │
┌ 2×2 DimArray{Float64, 2} ┐
├──────────────────────────┴──────────────────────────────── dims ┐
↓ Y Sampled{Float64} 0.0:0.6:0.6 ForwardOrdered Regular Points,
→ X Categorical{Char} 'a':2:'c' ForwardOrdered
Expand Down Expand Up @@ -228,8 +225,7 @@ julia> A = rand(X(1.0:3.0:30.0), Y(1.0:5.0:30.0), Ti(1:2));
julia> target = rand(X(1.0:10.0:30.0), Y(1.0:10.0:30.0));

julia> A[DimSelectors(target; selectors=Near), Ti=2]
╭──────────────────────────╮
│ 3×3 DimArray{Float64, 2} │
┌ 3×3 DimArray{Float64, 2} ┐
├──────────────────────────┴──────────────────────────────────────── dims ┐
↓ X Sampled{Float64} [1.0, 10.0, 22.0] ForwardOrdered Irregular Points,
→ Y Sampled{Float64} [1.0, 11.0, 21.0] ForwardOrdered Irregular Points
Expand Down
9 changes: 3 additions & 6 deletions src/groupby.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,7 @@ julia> using DimensionalData, Dates
julia> A = rand(X(1:0.1:20), Y(1:20), Ti(DateTime(2000):Day(3):DateTime(2003)));

julia> groups = groupby(A, Ti => month) # Group by month
╭───────────────────────────────────────────────────╮
│ 12-element DimGroupByArray{DimArray{Float64,2},1} │
┌ 12-element DimGroupByArray{DimArray{Float64,2},1} ┐
├───────────────────────────────────────────────────┴───────────── dims ┐
↓ Ti Sampled{Int64} [1, 2, …, 11, 12] ForwardOrdered Irregular Points
├───────────────────────────────────────────────────────────── metadata ┤
Expand All @@ -275,8 +274,7 @@ And take the mean:

```jldoctest groupby; setup = :(using Statistics)
julia> groupmeans = mean.(groups) # Take the monthly mean
╭─────────────────────────────────╮
│ 12-element DimArray{Float64, 1} │
┌ 12-element DimArray{Float64, 1} ┐
├─────────────────────────────────┴─────────────────────────────── dims ┐
↓ Ti Sampled{Int64} [1, 2, …, 11, 12] ForwardOrdered Irregular Points
├───────────────────────────────────────────────────────────── metadata ┤
Expand Down Expand Up @@ -305,8 +303,7 @@ Or do something else with Y:

```jldoctest groupby
julia> groupmeans = mean.(groupby(A, Ti=>month, Y=>isodd))
╭───────────────────────────╮
│ 12×2 DimArray{Float64, 2} │
┌ 12×2 DimArray{Float64, 2} ┐
├───────────────────────────┴────────────────────────────────────── dims ┐
↓ Ti Sampled{Int64} [1, 2, …, 11, 12] ForwardOrdered Irregular Points,
→ Y Sampled{Bool} [false, true] ForwardOrdered Irregular Points
Expand Down
Loading
Loading