fix(PEcAn.SIPNET): return empty dataframe when date filtering removes all segments (#4007)#4048
Merged
infotroph merged 3 commits intoJul 16, 2026
Conversation
…nProject#4007) When run start is after all crop cycles, date filtering can leave zero rows. Return early instead of assigning to segments[1, ...], which created a ghost row with NA columns and caused downstream segment config errors. Signed-off-by: Gaurav Chaudhary <chaudharygaurav2004@gmail.com>
dlebauer
approved these changes
Jul 13, 2026
divine7022
approved these changes
Jul 14, 2026
divine7022
left a comment
Member
There was a problem hiding this comment.
lgtm!, one small thing and agree with david's inline
Co-authored-by: Akash B V <www.divinehome12@gmail.com>
Co-authored-by: David LeBauer <dlebauer@gmail.com>
infotroph
enabled auto-merge
July 16, 2026 16:51
Merged
via the queue into
PecanProject:develop
with commit Jul 16, 2026
513e0a0
19 of 25 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes a bug in
segment_dataframe()where date filtering could leave zero valid crop-cycle segments, but the function still continued and executedsegments[1, "start_date"] <- run_starton an empty dataframe. In R, that assignment creates a ghost 1-row frame withstart_dateset and all other columns (end_date,crop_code,site_id,pft) asNA.That ghost row was passed to
write_segment_configs(), which then tried to build segment configs with invalid dates and PFTs. The failure appeared far downstream from the actual root cause.Change: When filtering removes all segments, return the empty dataframe immediately (silent return, consistent with the existing pre-filter check at line 135). Downstream
write_segment_configs()already handlesnrow(segments) == 0by returning the unalteredjob.sh.Files changed:
models/sipnet/R/write_segmented_configs.R— early return after filteringmodels/sipnet/tests/testthat/test-write_segmented_configs.R— unit + integration testsCHANGELOG.md— Unreleased / Fixed entrymodels/sipnet/NEWS.md— package news entryMotivation and Context
Closes #4007.
This edge case was spotted by @divine7022 during review of #4006. When
run$start.datefalls after all crop-cycle dates in the schedule, no segments are relevant to the requested time range. The correct behavior is to run the existing unsegmented config — not to error downstream with NA-filled segment rows.Related: #4006
Review Time Estimate
Types of changes
Checklist
Test Result
All tests passed.

That means no broken ghost row — fix is working. (Below ScreenShot)

Ran all SIPNET tests
