From a289afd8fc705ff856a53562742c7631e5f258eb Mon Sep 17 00:00:00 2001 From: Michael Krabbe Borregaard Date: Sun, 17 Oct 2021 08:17:41 +0200 Subject: [PATCH] fix leftjoin row order --- Project.toml | 2 +- docs/src/examples/nodebased.md | 4 ++-- src/GetandSetdata.jl | 6 ++++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 1675ba3..c5bd961 100644 --- a/Project.toml +++ b/Project.toml @@ -20,7 +20,7 @@ Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91" [compat] -DataFrames = "~1.0, ~1.1" +DataFrames = "1.0, 1.1, 1.2" DataFramesMeta = "0.5, 0.6, 0.7, 0.8, 0.9" Distances = "0.8, 0.9, 0.10" EcoBase = "0.1" diff --git a/docs/src/examples/nodebased.md b/docs/src/examples/nodebased.md index 5ac37f1..35f8e9e 100644 --- a/docs/src/examples/nodebased.md +++ b/docs/src/examples/nodebased.md @@ -271,12 +271,12 @@ the [nodiv](https://github.com/mkborregaard/nodiv) R package ```@example nodebased using ProgressLogging function node_based_analysis(assemblage::Assemblage, tree::AbstractTree) - nodevec = collect(nodenamefilter(!isleaf, tree)) + nodevec = traversal(tree, preorder) # collect(nodenamefilter(!isleaf, tree)) SOSs = Matrix{Float64}(undef, nsites(tyrants), length(nodevec)) GNDs = Vector{Float64}(undef, length(nodevec)) @progress for (i, node) in enumerate(nodevec) println(i) - SOSs[:,i], GNDs[i] = process_node(tyrants, tree, node) + SOSs[:,i], GNDs[i] = process_node(tyrants, tree, getnodename(tree, node)) end SOSs, GNDs end diff --git a/src/GetandSetdata.jl b/src/GetandSetdata.jl index fab9f1a..f021633 100644 --- a/src/GetandSetdata.jl +++ b/src/GetandSetdata.jl @@ -67,7 +67,10 @@ function addtraits!(asm::Assemblage, newtraits::DataFrames.DataFrame, species::S nm = propertynames(newtraits) rename!(newtraits, species => :name) + asm.occ.traits.__run_number = 1:nrow(asm.occ.traits) asm.occ.traits = leftjoin(asm.occ.traits, newtraits, on = :name, makeunique = makeunique) + sort!(asm.occ.traits, :__run_number) + select!(asm.occ.traits, Not(:__run_number)) rename!(newtraits, nm) #assemblagejoin!(asm.occ.traits, newtraits, :name, species) nothing @@ -94,7 +97,10 @@ function addsitestats!(asm::Assemblage, newsites::DataFrames.DataFrame, sites::S #assemblagejoin!(asm.site.sitestats, newsites, :sites, sites) #TODO this should instead be on the sitenames of the objects and adjusted below nm = propertynames(newsites) rename!(newsites, sites => :sites) + asm.site.sitestats.__run_number = 1:nrow(asm.site.sitestats) asm.site.sitestats = leftjoin(asm.site.sitestats, newsites, on = :sites, makeunique = makeunique) + sort!(asm.site.sitestats, :__run_number) + select!(asm.site.sitestats, Not(:__run_number)) rename!(newsites, nm) nothing end