Content-Length: 4793 | pFad | http://github.com/yeesian/ArchGDAL.jl/commit/d8849e4685ea0a9b2882dff9269a020ecfa93492.patch
9C
From d8849e4685ea0a9b2882dff9269a020ecfa93492 Mon Sep 17 00:00:00 2001
From: mathieu17g
Date: Tue, 12 Oct 2021 05:26:40 +0200
Subject: [PATCH] Handling of `Tables.schema` returning `nothing` or
`Schema{names, nothing}`
---
src/tables.jl | 51 ++++++++++++++++++++++++++++++++-------------
test/test_tables.jl | 19 ++++++++++++++---
2 files changed, 53 insertions(+), 17 deletions(-)
diff --git a/src/tables.jl b/src/tables.jl
index 61b99a2f..0cc328c7 100644
--- a/src/tables.jl
+++ b/src/tables.jl
@@ -101,29 +101,25 @@ function _convert_coltype_to_AGtype(
end
end
-function IFeatureLayer(table::T)::IFeatureLayer where {T}
- # Check tables interface's conformance
- !Tables.istable(table) &&
- throw(DomainError(table, "$table has not a Table interface"))
- # Extract table data
- rows = Tables.rows(table)
- schema = Tables.schema(table)
- schema === nothing && error("$table has no Schema")
- names = string.(schema.names)
- types = schema.types
- # TODO consider the case where names == nothing or types == nothing
+function _fromtable(
+ sch::Tables.Schema{names,types},
+ rows,
+)::IFeatureLayer where {names,types}
+ # TODO maybe constrain `names` and `types` types
+ strnames = string.(sch.names)
# Convert types and split types/names between geometries and fields
- AG_types = collect(_convert_coltype_to_AGtype.(types, names))
+ AG_types = collect(_convert_coltype_to_AGtype.(sch.types, strnames))
+ # Split names and types: between geometry type columns and field type columns
geomindices = isa.(AG_types, OGRwkbGeometryType)
!any(geomindices) && error("No column convertible to geometry")
geomtypes = AG_types[geomindices] # TODO consider to use a view
- geomnames = names[geomindices]
+ geomnames = strnames[geomindices]
fieldindices = isa.(AG_types, Tuple{OGRFieldType,OGRFieldSubType})
fieldtypes = AG_types[fieldindices] # TODO consider to use a view
- fieldnames = names[fieldindices]
+ fieldnames = strnames[fieldindices]
# Create layer
layer = createlayer(geom = first(geomtypes))
@@ -173,3 +169,30 @@ function IFeatureLayer(table::T)::IFeatureLayer where {T}
return layer
end
+
+function _fromtable(
+ ::Tables.Schema{names,nothing},
+ rows,
+)::IFeatureLayer where {names}
+ cols = Tables.columns(rows)
+ types = (eltype(collect(col)) for col in cols)
+ return _fromtable(Tables.Schema(names, types), rows)
+end
+
+function _fromtable(::Nothing, rows)::IFeatureLayer
+ state = iterate(rows)
+ state === nothing && return IFeatureLayer()
+ row, _ = state
+ names = Tables.columnnames(row)
+ return _fromtable(Tables.Schema(names, nothing), rows)
+end
+
+function IFeatureLayer(table)::IFeatureLayer
+ # Check tables interface's conformance
+ !Tables.istable(table) &&
+ throw(DomainError(table, "$table has not a Table interface"))
+ # Extract table data
+ rows = Tables.rows(table)
+ schema = Tables.schema(table)
+ return _fromtable(schema, rows)
+end
diff --git a/test/test_tables.jl b/test/test_tables.jl
index fe3af773..d08d43b4 100644
--- a/test/test_tables.jl
+++ b/test/test_tables.jl
@@ -810,9 +810,20 @@ using Tables
function columntablevalues_toWKT(x)
return Tuple(toWKT_withmissings.(x[i]) for i in 1:length(x))
end
- function nt2layer2nt_equals_nt(nt::NamedTuple)::Bool
- (ct_in, ct_out) =
- Tables.columntable.((nt, AG.IFeatureLayer(nt)))
+ function nt2layer2nt_equals_nt(
+ nt::NamedTuple;
+ force_no_schema::Bool = false,
+ )::Bool
+ if force_no_schema
+ (ct_in, ct_out) =
+ Tables.columntable.((
+ nt,
+ AG._fromtable(nothing, Tables.rows(nt)),
+ ))
+ else
+ (ct_in, ct_out) =
+ Tables.columntable.((nt, AG.IFeatureLayer(nt)))
+ end
(ctv_in, ctv_out) =
columntablevalues_toWKT.(values.((ct_in, ct_out)))
(spidx_in, spidx_out) =
@@ -908,6 +919,7 @@ using Tables
]),
],
])
+ @test_skip nt2layer2nt_equals_nt(nt; force_no_schema = true)
@test_skip nt2layer2nt_equals_nt(nt)
# Test with `missing` values
@@ -955,6 +967,7 @@ using Tables
]),
],
])
+ @test nt2layer2nt_equals_nt(nt; force_no_schema = true)
@test nt2layer2nt_equals_nt(nt)
end
end
--- a PPN by Garber Painting Akron. With Image Size Reduction included!Fetched URL: http://github.com/yeesian/ArchGDAL.jl/commit/d8849e4685ea0a9b2882dff9269a020ecfa93492.patch
Alternative Proxies:
Alternative Proxy
pFad Proxy
pFad v3 Proxy
pFad v4 Proxy