@@ -37,15 +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)
41- G = ntuple (ndims (A)) do d
42- vec ([rs[d] for rs in Iterators. product (R... )])
43- # _vec(rs[d] for rs in Iterators.product(R...))
44- end
40+ G = _get_keys_columns (keys_or_axes (A))
4541 C = (G... , vec (parent (A)))
4642 NamedTuple {L} (C)
4743end
4844
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 (R)
52+ R_inds = map (eachindex, R)
53+ return map (R, ntuple (identity, length (R))) do r, d
54+ vec ([r[indices[d]] for indices in Iterators. product (R_inds... )])
55+ end
56+ end
57+
4958function Tables. Schema (nt:: NamedTuple ) # 🏴☠️
5059 L = keys (nt)
5160 T = map (v -> typeof (first (v)), values (nt))
0 commit comments