Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

sipnet: merged segments get the literal string "NA" in `crop_code` (segments.csv)

Open Beginner friendly
#4,183 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 3 days

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
78/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
r
Domain
backend

Research direction

Start with drop_same_pft_segments() in models/sipnet/R/write_segmented_configs.R and the segment_dataframe() behavior described in the issue. Reproduce the example with the supplied tibble, then add a focused test for merging a missing crop_code with a populated one. Done means the merged segments.csv value omits the literal "NA" while preserving the real crop code.

Written by the indexing model from the issue text.

Description

Summary

Follow-up to #4122 / #4129. drop_same_pft_segments() in models/sipnet/R/write_segmented_configs.R builds the merged crop_code with paste(.data$crop_code, collapse = " "). A missing code is pasted as the text "NA".

The first segment (the period before the first planting) always has crop_code = NA (segment_dataframe()), so when it is merged with a following segment of the same PFT, segments.csv gets a value like "NA D12".

Reproduction (on develop)

seg <- tibble::tibble(
  start_date = as.Date(c("2025-01-01", "2025-01-04", "2025-01-08")),
  end_date   = as.Date(c("2025-01-03", "2025-01-07", "2025-01-10")),
  crop_code  = c(NA, "D12", "D13"),
  pft        = c("soil", "soil", "crop"),
  segment_id = c("001", "002", "003")
)
PEcAn.SIPNET:::drop_same_pft_segments(seg)
#> first row: crop_code = "NA D12", pft = soil, 2025-01-01 to 2025-01-07

Impact

Cosmetic: crop_code is only written to segments.csv and is not used elsewhere in the package, so run results are not affected. But the file then contains a code, "NA", that is not a real crop.

Possible fix

paste(stats::na.omit(.data$crop_code), collapse = " ") (an all-missing group would give "", which could be turned back into NA_character_). I'm happy to send a small PR with a test if this is wanted.

Also

It might be worth a test through write_segment_configs() showing that a merged segment's inputs still cover its full date range.

Dominant language
R
Stars
246
Forks
322
Avg merge
7d 3h
Merged PRs (30d)
17

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from PecanProject/pecan

All issues in PecanProject/pecan

Similar issues

More R issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.