From e2b9867a50a31a929bb51fc5d1f050c9b61cd4ad Mon Sep 17 00:00:00 2001 From: Curtis Vogt Date: Wed, 5 Aug 2020 12:34:57 -0500 Subject: [PATCH] Support setproperty! (#23) --- src/KeyedFrames.jl | 1 + test/runtests.jl | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/src/KeyedFrames.jl b/src/KeyedFrames.jl index 1daf556..697cfbd 100644 --- a/src/KeyedFrames.jl +++ b/src/KeyedFrames.jl @@ -101,6 +101,7 @@ const ColumnIndex = Union{Real, Symbol} frame(kf::KeyedFrame) = getfield(kf, :frame) Base.keys(kf::KeyedFrame) = getfield(kf, :key) Base.setindex!(kf::KeyedFrame, value, ind...) = setindex!(frame(kf), value, ind...) +Base.setproperty!(kf::KeyedFrame, field::Symbol, value) = setproperty!(frame(kf), field, value) # I don't want to have to write the same function body several times, so... function _kf_getindex(kf::KeyedFrame, index...) diff --git a/test/runtests.jl b/test/runtests.jl index 1a94561..2f36af3 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -157,6 +157,12 @@ using Test @test isequal(cp, KeyedFrame(DataFrame(;a=[10, 2, 3, 4, 5],d=[10, 5, 6, 7, 8]), :a)) end + @testset "setproperty!" begin + cp = deepcopy(kf1) + cp.b = 10:-1:1 + @test isequal(cp, KeyedFrame(DataFrame(; a=1:10, b=10:-1:1, c=3:12), [:a, :b])) + end + @testset "first/last" begin # Don't assume that n will always equal 6 @test first(kf1) isa KeyedFrame