From d030cfb3122f8a2336b1ce58462c1cb3807b57dd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fran=C3=A7ois=20Laurent?= <francois.laurent@posteo.net>
Date: Sun, 3 Sep 2023 16:14:44 +0200
Subject: [PATCH] bugfix for files with missing labels

---
 src/LarvaDatasets.jl | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/LarvaDatasets.jl b/src/LarvaDatasets.jl
index eef36fe..fdb25e8 100644
--- a/src/LarvaDatasets.jl
+++ b/src/LarvaDatasets.jl
@@ -896,7 +896,7 @@ function samplesize!(index, sample_size)
         while count < targetcount
             file = rand(keys(targetcountsperfile))
             counts = targetcountsperfile[file]
-            if counts[label] < index.maxcounts[file][label]
+            if haskey(counts, label) && counts[label] < index.maxcounts[file][label]
                 counts[label] += 1
                 count += 1
             end
@@ -904,7 +904,7 @@ function samplesize!(index, sample_size)
         while targetcount < count
             file = rand(keys(targetcountsperfile))
             counts = targetcountsperfile[file]
-            if 0 < counts[label]
+            if 0 < get(counts, label, 0)
                 counts[label] -= 1
                 count -= 1
             end
-- 
GitLab