Skip to content

Commit

Permalink
fix DimSlices type (#912)
Browse files Browse the repository at this point in the history
* fix DimSlices type

* fix eltype in docs
  • Loading branch information
rafaqz authored Jan 27, 2025
1 parent 4ba7bad commit ffba13f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/dimindices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -325,9 +325,9 @@ function DimSlices(x, dims; drop=true)
else
dims
end
inds = map(basedims(newdims)) do d
rebuild(d, first(axes(x, d)))
end
inds = map(newdims) do d
rebuild(d, first(d))
end
# `getindex` returns these views
T = typeof(view(x, inds...))
N = length(newdims)
Expand Down
2 changes: 1 addition & 1 deletion src/groupby.jl
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +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,3},1} ┐
├───────────────────────────────────────────────────┴───────────── dims ┐
↓ Ti Sampled{Int64} [1, 2, …, 11, 12] ForwardOrdered Irregular Points
├───────────────────────────────────────────────────────────── metadata ┤
Expand Down
7 changes: 7 additions & 0 deletions test/groupby.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ days = DateTime(2000):Day(1):DateTime(2000, 12, 31)
A = DimArray((1:6) * (1:366)', (X(1:0.2:2), Ti(days)))
st = DimStack((a=A, b=A, c=A[X=1]))


@testset "group eltype matches indexed values" begin
da = rand(X(1:10), Y(1:10))
grps = groupby(da, X => isodd)
@test first(grps) isa eltype(grps) # false
end

@testset "manual groupby comparisons" begin
# Group by month and even/odd Y axis values
months = DateTime(2000):Month(1):DateTime(2000, 12, 31)
Expand Down

0 comments on commit ffba13f

Please sign in to comment.