@@ -37,23 +37,24 @@ Tables.columnaccess(::Type{<:KeyedArray{T,N,AT}}) where {T,N,AT} =
3737function Tables. columns (A:: Union{KeyedArray, NdaKa} )
3838 L = hasnames (A) ? (dimnames (A)... , :value ) :
3939 (ntuple (d -> Symbol (:dim_ ,d), ndims (A))... , :value )
40- R = keys_or_axes (A)
40+ G = _get_keys_columns (A)
41+ C = (G... , vec (parent (A)))
42+ NamedTuple {L} (C)
43+ end
4144
42- # R_inds comprises the indices for each of the keys.
43-
45+ # indices is a tuple, the dth element of which is an index for the dth column of R.
46+ # By using these indices, and mapping over the columns of R, the compiler seems to
47+ # successfully infer the types in G, because it knows the element types of each column
48+ # of R, so is presumably able to unroll the call to map.
49+ # The previous implementation called `Iterators.product` on `R` and pulled out
50+ # the dth element of `indices`, whose type it could not infer.
51+ function _get_keys_columns (A)
52+ R = keys_or_axes (A)
4453 R_inds = map (eachindex, R)
45- # indices is a tuple, the dth element of which is an index for the dth column of R.
46- # By using these indices, and mapping over the columns of R, the compiler seems to
47- # successfully infer the types in G, because it knows the element types of each column
48- # of R, so is presumably able to unroll the call to map.
49- # The previous implementation called `Iterators.product` on `R` and pulled out
50- # the dth element of `indices`, whose type it could not infer.
51- G = map (
54+ return map (
5255 (r, d) -> vec ([r[indices[d]] for indices in Iterators. product (R_inds... )]),
5356 R, ntuple (identity, length (R)),
5457 )
55- C = (G... , vec (parent (A)))
56- NamedTuple {L} (C)
5758end
5859
5960function Tables. Schema (nt:: NamedTuple ) # 🏴☠️
0 commit comments