-
Notifications
You must be signed in to change notification settings - Fork 37
WIP: support attribute tables #987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
tiemvanderdeure
wants to merge
2
commits into
main
Choose a base branch
from
tvd/attributetable
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,10 +40,28 @@ function _resolve_mod_eltype(::Type{T}, missingval, scale, offset) where T | |
return T3 | ||
end | ||
|
||
missingval(m::Mod) = m.missingval | ||
missingval(m::NoMod) = m.missingval | ||
# Modifies by dictionary lookup - similar to categorical array | ||
struct AttributeMod{T, Mi, Di} <: AbstractModifications{T} | ||
table::NamedTuple | ||
column::Symbol | ||
dict::Di | ||
missingval::Mi | ||
|
||
_inner_missingval(m::Mod) = _inner_missingval(m.missingval) | ||
function AttributeMod(table::NamedTuple, column::Symbol, missingval::Mi) where {Mi} | ||
keycol = identity.(first(table)) | ||
valcol = identity.(table[column]) | ||
dict = DD.OrderedCollections.LittleDict(keycol, valcol) |> DD.OrderedCollections.freeze | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💯 |
||
new{eltype(table[column]), Mi, typeof(dict)}(table, column, dict, missingval) | ||
end | ||
end | ||
|
||
## Todo in a DBFTables extension | ||
_tablemod(args...) = error() | ||
|
||
## missingval handling | ||
missingval(m::AbstractModifications) = m.missingval | ||
|
||
_inner_missingval(m::AbstractModifications) = _inner_missingval(m.missingval) | ||
_inner_missingval(mv) = mv | ||
_inner_missingval(mv::Pair) = mv[1] | ||
|
||
|
@@ -78,7 +96,7 @@ DiskArrays.haschunks(A::ModifiedDiskArray) = DiskArrays.haschunks(parent(A)) | |
DiskArrays.eachchunk(A::ModifiedDiskArray) = DiskArrays.eachchunk(parent(A)) | ||
|
||
function DiskArrays.readblock!( | ||
A::ModifiedDiskArray{<:Any,<:Any,<:Any,<:Mod}, outer_block, I::AbstractVector... | ||
A::ModifiedDiskArray{<:Any,<:Any,<:Any,<:AbstractModifications}, outer_block, I::AbstractVector... | ||
) | ||
if isdisk(parent(A)) | ||
inner_block = similar(outer_block, eltype(parent(A))) | ||
|
@@ -121,6 +139,11 @@ function DiskArrays.writeblock!( | |
parent(A)[I...] = block | ||
end | ||
end | ||
function DiskArrays.writeblock!( | ||
A::ModifiedDiskArray{<:Any,<:Any,<:Any,<:AttributeMod}, block, I::AbstractVector... | ||
) | ||
error("Writing using an Attribute Table is not supported") | ||
end | ||
|
||
Base.@assume_effects :foldable function _applymod(x, m::Mod) | ||
if _ismissing(x, _inner_missingval(m)) | ||
|
@@ -130,6 +153,13 @@ Base.@assume_effects :foldable function _applymod(x, m::Mod) | |
end | ||
end | ||
Base.@assume_effects :foldable _applymod(x, ::NoMod) = x | ||
Base.@assume_effects :foldable function _applymod(x, m::AttributeMod) | ||
if _ismissing(x, _inner_missingval(m)) | ||
_outer_missingval(m) | ||
else | ||
m.dict[x] | ||
end | ||
end | ||
|
||
_ismissing(x, mv) = ismissing(x) || x === mv | ||
_ismissing(x, ::Nothing) = ismissing(x) | ||
|
@@ -198,7 +228,7 @@ function get_scale(metadata, scaled::Bool) | |
end | ||
|
||
_mod_eltype(::AbstractArray{T}, ::NoMod) where T = T | ||
_mod_eltype(::AbstractArray, m::Mod{T}) where T = T | ||
_mod_eltype(::AbstractArray, m::AbstractModifications{T}) where T = T | ||
|
||
_mod_inverse_eltype(::AbstractArray{T}, ::NoMod) where T = T | ||
_mod_inverse_eltype(::AbstractArray{T}, m::Mod) where T = | ||
|
@@ -248,4 +278,4 @@ function _read_missingval_pair(var, metadata, missingval) | |
# Otherwise: detect missing value and convert it to `missingval` | ||
Rasters.missingval(var, metadata) => missingval | ||
end | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should make this be able to pick up ArchGDAL rats. Maybe that goes in the extension?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because those have .tif.rat or something which is a different format...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I have to think about how to check for all of that. I'm not sure if there are more formats than just those two? And if different file extensions than .tif could have a RAT or something similar?