Skip to content

Commit d236431

Browse files
author
Will Tebbutt
committed
Refactor + add regression test
1 parent 577622a commit d236431

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

src/tables.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Tables.columnaccess(::Type{<:KeyedArray{T,N,AT}}) where {T,N,AT} =
3737
function Tables.columns(A::Union{KeyedArray, NdaKa})
3838
L = hasnames(A) ? (dimnames(A)..., :value) :
3939
(ntuple(d -> Symbol(:dim_,d), ndims(A))..., :value)
40-
G = _get_keys_columns(A)
40+
G = _get_keys_columns(keys_or_axes(A))
4141
C = (G..., vec(parent(A)))
4242
NamedTuple{L}(C)
4343
end
@@ -48,8 +48,7 @@ end
4848
# of R, so is presumably able to unroll the call to map.
4949
# The previous implementation called `Iterators.product` on `R` and pulled out
5050
# the dth element of `indices`, whose type it could not infer.
51-
function _get_keys_columns(A)
52-
R = keys_or_axes(A)
51+
function _get_keys_columns(R)
5352
R_inds = map(eachindex, R)
5453
return map(
5554
(r, d) -> vec([r[indices[d]] for indices in Iterators.product(R_inds...)]),

test/_packages.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ end
4949
@test keys(first(Tables.rows(N))) == (:a, :b, :value)
5050

5151
@test Tables.columns(N).a == [11, 12, 11, 12, 11, 12]
52+
53+
# Regression test: https://github.com/mcabbott/AxisKeys.jl/pull/123
54+
@testset "Tables.columns(::AxisKeys) type stability" begin
55+
a = randn(5)
56+
b = randn(Float32, 4)
57+
@inferred AxisKeys._get_keys_columns((a, b))
58+
X = wrapdims(randn(5, 4); a, b)
59+
@inferred Tables.columns(X)
60+
end
5261
end
5362
@testset "sink" begin
5463
A = KeyedArray(rand(24, 11, 3); time = 0:23, loc = -5:5, id = ["a", "b", "c"])

0 commit comments

Comments
 (0)