Skip to content

Commit

Permalink
Support setproperty! (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
omus authored Aug 5, 2020
1 parent 60bbb4a commit e2b9867
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/KeyedFrames.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
6 changes: 6 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e2b9867

Please sign in to comment.