|
46 | 46 | rebuild(A, data, dims, refdims, name, metadata) # Rebuild as a reguilar DimArray
|
47 | 47 | end
|
48 | 48 |
|
49 |
| -function Base.summary(io::IO, A::DimGroupByArray{T,N}) where {T,N} |
| 49 | +function Base.summary(io::IO, A::DimGroupByArray{T,N}) where {T<:AbstractArray{T1,N1},N} where {T1,N1} |
50 | 50 | print_ndims(io, size(A))
|
51 |
| - print(io, string(nameof(typeof(A)), "{$(nameof(T)),$N}")) |
| 51 | + print(io, string(nameof(typeof(A)), "{$(nameof(T)){$T1,$N1},$N}")) |
52 | 52 | end
|
53 | 53 |
|
54 | 54 | function show_after(io::IO, mime, A::DimGroupByArray)
|
@@ -80,6 +80,17 @@ function Base.show(io::IO, s::DimSummariser)
|
80 | 80 | end
|
81 | 81 | Base.alignment(io::IO, s::DimSummariser) = (textwidth(sprint(show, s)), 0)
|
82 | 82 |
|
| 83 | +# An array that doesn't know what it holds, to simplify dispatch |
| 84 | +struct OpaqueArray{T,N,A<:AbstractArray{T,N}} <: AbstractArray{T,N} |
| 85 | + parent::A |
| 86 | +end |
| 87 | +Base.parent(A::OpaqueArray) = A.parent |
| 88 | +Base.size(A::OpaqueArray) = size(parent(A)) |
| 89 | +for f in (:getindex, :view, :dotview) |
| 90 | + @eval Base.$f(A::OpaqueArray, args...) = Base.$f(parent(A), args...) |
| 91 | +end |
| 92 | +Base.setindex!(A::OpaqueArray, args...) = Base.setindex!(parent(A), args...) |
| 93 | + |
83 | 94 |
|
84 | 95 | abstract type AbstractBins <: Function end
|
85 | 96 |
|
@@ -331,9 +342,11 @@ function DataAPI.groupby(A::DimArrayOrStack, dimfuncs::DimTuple)
|
331 | 342 | end
|
332 | 343 | # Separate lookups dims from indices
|
333 | 344 | group_dims = map(first, dim_groups_indices)
|
334 |
| - indices = map(rebuild, dimfuncs, map(last, dim_groups_indices)) |
| 345 | + # Get indices for each group wrapped with dims for indexing |
| 346 | + indices = map(rebuild, group_dims, map(last, dim_groups_indices)) |
335 | 347 |
|
336 |
| - views = DimSlices(A, indices) |
| 348 | + # Hide that the parent is a DimSlices |
| 349 | + views = OpaqueArray(DimSlices(A, indices)) |
337 | 350 | # Put the groupby query in metadata
|
338 | 351 | meta = map(d -> dim2key(d) => val(d), dimfuncs)
|
339 | 352 | metadata = Dict{Symbol,Any}(:groupby => length(meta) == 1 ? only(meta) : meta)
|
@@ -394,7 +407,6 @@ function _group_indices(dim::Dimension, bins::AbstractBins; labels=bins.labels)
|
394 | 407 | return _group_indices(transformed_lookup, group_lookup; labels)
|
395 | 408 | end
|
396 | 409 |
|
397 |
| - |
398 | 410 | # Get a vector of intervals for the bins
|
399 | 411 | _groups_from(_, bins::Bins{<:Any,<:AbstractArray}) = bins.bins
|
400 | 412 | function _groups_from(transformed, bins::Bins{<:Any,<:Integer})
|
|
0 commit comments