Skip to content

Commit

Permalink
Fix 'Tables.subset' implementation (#74)
Browse files Browse the repository at this point in the history
  • Loading branch information
eliascarv authored Nov 3, 2023
1 parent 9ac0156 commit 76dd489
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/api/tables.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ end
Tables.schema(geotable::AbstractGeoTable) = Tables.schema(Tables.rows(geotable))

Tables.subset(geotable::AbstractGeoTable, inds; viewhint=nothing) = SubGeoTable(geotable, inds)
Tables.subset(geotable::AbstractGeoTable, ind::Int; viewhint=nothing) = geotable[ind, :]

# wrapper type for rows of the geotable table
# so that we can easily inform the schema
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ dummymeta(domain, table) = GeoTable(domain, Dict(paramdim(domain) => table))
@test Tables.materializer(dat) <: DummyType
inds = [1, 3]
@test Tables.subset(dat, inds) == view(dat, inds)
@test Tables.subset(dat, 1) == (a=1, b=5, geometry=Quadrangle((0.0, 0.0), (1.0, 0.0), (1.0, 1.0), (0.0, 1.0)))
# viewhint keyword argument is ignored
@test Tables.subset(dat, inds, viewhint=true) isa GeoTables.SubGeoTable
@test Tables.subset(dat, inds, viewhint=false) isa GeoTables.SubGeoTable
@test Tables.subset(dat, 1, viewhint=true) isa NamedTuple
@test Tables.subset(dat, 1, viewhint=false) isa NamedTuple

# dataframe interface
grid = CartesianGrid(2, 2)
Expand Down

0 comments on commit 76dd489

Please sign in to comment.