Skip to content

Commit

Permalink
test names subsetting
Browse files Browse the repository at this point in the history
  • Loading branch information
rafaqz committed Nov 24, 2023
1 parent 46964a1 commit 1e30894
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/methods/extract.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function extract end
function extract(x::RasterStackOrArray, data;
dims=DD.dims(x, DEFAULT_POINT_ORDER), names=_names(x), kw...
)
_extract(x, data; dims, names, kw...)
_extract(x, data; dims, names=NamedTuple{names}(names), kw...)
end

function _extract(A::RasterStackOrArray, geom::Missing; names, kw...)
Expand Down Expand Up @@ -172,5 +172,5 @@ end
end
end

_names(A::AbstractRaster) = NamedTuple{(Symbol(name(A)),)}((Symbol(name(A)),))
_names(A::AbstractRasterStack) = NamedTuple{keys(A)}(keys(A))
_names(A::AbstractRaster) = (Symbol(name(A)),)
_names(A::AbstractRasterStack) = keys(A)
7 changes: 7 additions & 0 deletions test/methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ createpoint(args...) = ArchGDAL.createpoint(args...)
(index = (1, 1), test = 1, test2 = 5)
(index = (2, 2), test = 4, test2 = 8)
]
# Subset with `names`
@test all(extract(st, [missing, (9.0, 0.1), (10.0, 0.2), (10.0, 0.3)]; names=(:test2,)) .=== [
(geometry = missing, test2 = missing)
(geometry = (9.0, 0.1), test2 = 5)
(geometry = (10.0, 0.2), test2 = 8)
(geometry = (10.0, 0.3), test2 = missing)
])
end
end

Expand Down

0 comments on commit 1e30894

Please sign in to comment.