write.config.PEPRMT() errors when the event file has no supported events for the site

Aperta Adatta ai principianti
#4,255 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
r
Ambito
backend

Direzione di ricerca

Inizia da write.config.PEPRMT() e segui come vengono filtrati e ordinati gli eventi supportati; l’issue indica questa funzione, ma non specifica alcun file sorgente né percorso di test. Riproduci il problema con un elenco di eventi contenente solo planting, poi aggiungi un test di regressione mirato e conferma che l’esecuzione produce lo stesso run_data.csv di un’esecuzione senza eventi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

write.config.PEPRMT() keeps only the supported event types (salinity, elevation) and then sorts the remaining events by date:

evt_order <- sapply(evts, \(x) x$date) |> as.Date() |> order()

If no supported event remains, evts is an empty list, sapply() returns list(), and as.Date(list()) stops with an error.

When this happens

  • the site's events array is empty, or
  • every event is of a type PEPRMT does not use (for example only planting). The events JSON is shared between models, so a file with only other models' events is a realistic input.

Reproduction (on develop)

Run write.config.PEPRMT() with run$inputs$event_json pointing at

[{"site_id": "S1", "events": [{"event_type": "planting", "date": "2020-01-02"}]}]
INFO Ignoring unsupported event types 'planting'. Supported event types are: 'salinity', 'elevation'
Error in as.Date.default(sapply(evts, function(x) x$date)) :
  do not know how to convert 'sapply(evts, function(x) x$date)' to class "Date"

With no event input at all, or with a mix of supported and unsupported events, it works.

Proposed fix

Only sort when length(evts) > 0. The run then produces the same run_data.csv as a run with no events. I have a branch with a small test that fails on develop and passes with the fix; happy to send a PR if wanted

Lingua principale
R
Stelle
246
Fork
322
Merge medio
4g 15h
PR unite (30g)
15

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di PecanProject/pecan

Tutte le issue di PecanProject/pecan

Issue simili

Altre issue su R

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.