From 1d6cfd5910b4274dac8f7ce9a7370e86091f1efa Mon Sep 17 00:00:00 2001 From: pszufe Date: Sun, 19 Nov 2023 06:11:45 +0100 Subject: [PATCH] bug fix --- Project.toml | 2 +- src/poi.jl | 6 +++++- test/runtests.jl | 7 +++++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Project.toml b/Project.toml index 38804be..6dc518b 100644 --- a/Project.toml +++ b/Project.toml @@ -1,7 +1,7 @@ name = "OSMToolset" uuid = "a1c25ae6-0f93-4b3a-bddf-c248cb99b9fa" authors = ["pszufe and contributors"] -version = "0.1.1" +version = "0.1.2" [deps] CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b" diff --git a/src/poi.jl b/src/poi.jl index 199c0ee..607c8ff 100644 --- a/src/poi.jl +++ b/src/poi.jl @@ -140,7 +140,11 @@ function find_poi(filename::AbstractString; scrape_config::ScrapePOIConfig{T}=__ relations_firstnode = Dict{Int, Node}() elemtype = :X elemid = -1 - df= DataFrame() + # creates an empty data frame + df = DataFrame(;elemtype=Symbol[], elemid=Int[],nodeid=Int[],lat=Float64[],lon=Float64[], + key=String[], value=String[], + (NamedTupleTools.fieldnames(T) .=> [Vector{ftype}() for ftype in NamedTupleTools.fieldtypes(T)])... ) + io = open(filename, "r") sr = EzXML.StreamReader(io) i = 0 diff --git a/test/runtests.jl b/test/runtests.jl index d834c2f..12cb327 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -43,11 +43,18 @@ end config = DataFrame(key=["parking", "amenity"], values=["*", "parking"]) df2 = find_poi(test_map; scrape_config=ScrapePOIConfig{NoneMetaPOI}(config)) +df3 = find_poi(test_map; scrape_config=ScrapePOIConfig{NoneMetaPOI}(DataFrame(key=String[], values=String[]))) +df4 = find_poi(test_map; scrape_config=ScrapePOIConfig{NoneMetaPOI}(DataFrame(key=["does not exist300, get_group=a->:parking); @testset "CustomConfig" begin @test nrow(df2) > 0 + @test nrow(df3) == 0 + @test nrow(df4) == 0 + @test df2[1:0,:] == df3 + @test df2[1:0,:] == df4 @test all(df2.key .∈ Ref(["amenity", "parking"])) att2 = attractiveness(sindex2, lla; aggregator= x -> length(x)==0 ? 0 : maximum(x), calculate_attractiveness = (a,dist) -> dist > 300 ? 0 : 300/dist ) @test fieldnames(att2) == (:parking,)