Skip to content

BUG: skip blank lines when counting the loaded simulations - #1256

Open
pranjalbhatia710 wants to merge 1 commit into
RocketPy-Team:developfrom
pranjalbhatia710:fix/1255-blank-log-lines
Open

pranjalbhatia710 wants to merge 1 commit into
RocketPy-Team:developfrom
pranjalbhatia710:fix/1255-blank-log-lines

Conversation

@pranjalbhatia710

Copy link
Copy Markdown

Pull request type

  • Code changes (bugfix, features)

Checklist

  • Tests for the changes have been added (if needed)
  • Lint has passed locally (ruff check, ruff format --check, pylint on the changed files)
  • All tests (pytest tests -m slow --runslow) have passed locally (only the Monte Carlo unit and integration tests were run, see below)
  • CHANGELOG.md — no action needed; an LLM workflow auto-updates it after merge

Current behavior

MonteCarlo.set_num_of_loaded_sims counts every line of a .txt (JSONL) outputs log, and every line after the header of a .csv one, blank lines included. _read_log_file (and _checkpoint_rows) skip blank lines, so for a log containing one, num_of_loaded_sims is larger than len(outputs_log).

simulate_convergence uses that count as the number of simulations already run, so with the log from #1255 (2 rows, 2 blank lines, max_simulations=4) it reports "A total of 4 simulation results were loaded" and returns [] without simulating. A .csv log with a blank line between two rows counts 3.

New behavior

num_of_loaded_sims matches the rows the readers return:

  • JSONL: only non-blank lines are counted (line.strip(), the same test _read_log_file uses).
  • CSV: rows are counted with csv.DictReader, the reader _read_log_file uses. It consumes the header and skips blank rows, so the manual "minus one for the header" goes away.
  • JSON: unchanged.

New unit tests in tests/unit/simulation/test_monte_carlo.py:

  • test_set_num_of_loaded_sims_skips_blank_lines[jsonl|csv]: a log with two rows and blank lines gives len(outputs_log) == num_of_loaded_sims == 2.
  • test_simulate_convergence_runs_after_a_log_with_blank_lines: the reproduction from num_of_loaded_sims counts the blank lines of an outputs log #1255. simulate_convergence now reaches simulate (a stub that raises) instead of returning early.

All three fail on develop (assert 4 == 2, DID NOT RAISE RuntimeError) and pass with the fix.

Breaking change

  • No

Additional information

Tested on macOS arm64, Python 3.12.12:

  • pytest tests/unit/simulation/test_monte_carlo*.py tests/unit/simulation/test_append_lineage.py: 213 passed, 15 skipped, 1 failed. The failure (test_ellipses_reports_an_image_path_that_does_not_exist) is the optional imageio dependency not being installed and is the same without this change.
  • pytest tests/integration/simulation/test_monte_carlo.py: 6 passed, 5 skipped.

Fixes #1255

This PR was prepared with AI assistance (Claude Code).

🤖 Generated with Claude Code

set_num_of_loaded_sims counted every line of a .txt (JSONL) outputs log
and every line after the header of a .csv one, blank lines included,
while _read_log_file skips them. num_of_loaded_sims could then exceed
len(outputs_log), and simulate_convergence returned without simulating
because it took the extra count as simulations already run.

Count only non-blank lines of a JSONL log, and count the rows of a CSV
log with csv.DictReader, as _read_log_file does.

Fixes RocketPy-Team#1255

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@pranjalbhatia710
pranjalbhatia710 requested a review from a team as a code owner December 6, 2026 06:05
@codecov

codecov Bot commented Dec 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.84%. Comparing base (7701e4f) to head (0bdf49d).

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #1256   +/-   ##
========================================
  Coverage    87.84%   87.84%           
========================================
  Files          130      130           
  Lines        18185    18185           
========================================
  Hits         15975    15975           
  Misses        2210     2210           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant