Skip to content

Commit fdf4d11

Browse files
authored
getcolumn on MatrixTable now returns views (#220)
1 parent 3154fa8 commit fdf4d11

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "Tables"
22
uuid = "bd369af6-aec1-5ad0-b16a-f7cc5008161c"
33
authors = ["quinnj <[email protected]>"]
4-
version = "1.2.1"
4+
version = "1.2.2"
55

66
[deps]
77
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"

src/matrix.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ Base.iterate(m::MatrixTable, st=1) = st > length(m) ? nothing : (MatrixRow(st, m
3737
Columns(m::T) where {T <: MatrixTable} = Columns{T}(m)
3838
columnaccess(::Type{<:MatrixTable}) = true
3939
columns(m::MatrixTable) = m
40-
getcolumn(m::MatrixTable, ::Type{T}, col::Int, nm::Symbol) where {T} = getfield(m, :matrix)[:, col]
41-
getcolumn(m::MatrixTable, nm::Symbol) = getfield(m, :matrix)[:, getfield(m, :lookup)[nm]]
42-
getcolumn(m::MatrixTable, i::Int) = getfield(m, :matrix)[:, i]
40+
getcolumn(m::MatrixTable, i::Int) = view(getfield(m, :matrix), :, i)
41+
getcolumn(m::MatrixTable, ::Type, col::Int, nm::Symbol) = getcolumn(m, col)
42+
getcolumn(m::MatrixTable, nm::Symbol) = getcolumn(m, getfield(m, :lookup)[nm])
4343
columnnames(m::MatrixTable) = names(m)
4444

4545
"""

test/runtests.jl

+8-1
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,13 @@ end
250250
@test Tables.columnnames(mattbl) == Symbol.(1:3)
251251
@test_throws ArgumentError Tables.table(mat, header=[:A, :B, :C, :D])
252252

253+
X = [1 2; 3 4; 5 6]
254+
tbl = Tables.table(X)
255+
tbl[1][1] = 100
256+
@test X[1, 1] == 100
257+
tbl[2][3] = 200
258+
@test X[3, 2] == 200
259+
253260
# #155
254261
m = hcat([1,2,3],[1,2,3])
255262
T = Tables.table(m)
@@ -647,4 +654,4 @@ end
647654
@test isequal(ct.c, [3, missing, missing, 10, 10])
648655
@test isequal(dct.d, [missing, 5, 7, missing, 11])
649656

650-
end
657+
end

0 commit comments

Comments
 (0)