Skip to content

Commit

Permalink
fix error (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericphanson authored Oct 21, 2023
1 parent 1f79db0 commit 175e431
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/dicts.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,14 +126,14 @@ end

function subset(x::DictRowTable, inds; viewhint::Union{Bool,Nothing}=nothing, view::Union{Bool,Nothing}=nothing)
if view !== nothing
@warn "`view` keyword argument is deprecated for `Tables.subset`, use `viewhint` instead"
@warn "`view` keyword argument is deprecated for `Tables.subset`, use `viewhint` instead" maxlog=10
viewhint = view
end
values = viewhint === true ? Base.view(getfield(x, :values), inds) : getfield(x, :values)[inds]
if inds isa Integer
return DictRow(getfield(x, :names), values)
else
values isa AbstractVector || throw(ArgumentError("`Tables.subset`: invalid `inds` argument, expected `RowTable` output, got $(typeof(ret))"))
values isa AbstractVector || throw(ArgumentError("`Tables.subset`: invalid `inds` argument, expected `RowTable` output, got $(typeof(values))"))
return DictRowTable(getfield(x, :names), getfield(x, :types), values)
end
end
Expand Down
3 changes: 2 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ end
@test Tables.subset(nt, 1:2, viewhint=false) == (a=[1,2], b=[4.0, 5.0], c=["7","8"])
@test Tables.subset(nt, 1:2, viewhint=nothing) == (a=[1,2], b=[4.0, 5.0], c=["7","8"])
@test_throws ArgumentError Tables.subset(nt, [1:2 1:2])
@test_throws ArgumentError Tables.subset(Tables.dictrowtable(nt), [1:2 1:2])

@test Tables.subset(nt, 1, viewhint=true) == (a=1, b=4.0, c="7")
rs = Tables.subset(nt, 1:2, viewhint=true)
Expand Down Expand Up @@ -1038,4 +1039,4 @@ end
@test DataAPI.ncol(Tables.dictrowtable(NamedTuple[])) == 0
@test DataAPI.nrow(Tables.dictrowtable([(a=1, b=2), (a=3, b=4), (a=5, b=6)])) == 3
@test DataAPI.ncol(Tables.dictrowtable([(a=1, b=2), (a=3, b=4), (a=5, b=6)])) == 2
end
end

0 comments on commit 175e431

Please sign in to comment.