Skip to content

Refactor duplicated bootstrapping logic in analysis scripts - #14

Merged
alfieprojectsdev merged 1 commit into
mainfrom
refactor-bootstrap-logic-153735260210762914
Feb 13, 2026
Merged

Refactor duplicated bootstrapping logic in analysis scripts#14
alfieprojectsdev merged 1 commit into
mainfrom
refactor-bootstrap-logic-153735260210762914

Conversation

@alfieprojectsdev

Copy link
Copy Markdown
Owner

This PR addresses the code duplication between bootstrap_v1.py and bootstrap_v2.py in the analysis/08 Bootstrapping directory.

Key Changes

  1. New Utility Module: Introduced bootstrap_utils.py containing:

    • run_bootstrap_simulation: The core loop for sampling, running MATLAB scripts, and processing results.
    • plot_histogram: The shared plotting logic.
    • Lazy imports for matlab.engine to allow the code to run/test in environments where MATLAB is not installed (graceful failure or mocking).
  2. Refactoring:

    • bootstrap_v1.py and bootstrap_v2.py now import bootstrap_utils and call run_bootstrap_simulation with their specific parameters (sample size, reference station data, etc.).
    • Preserved existing behavior, including the specific sys.path modification in v2.
  3. Modernization:

    • Replaced df.append() (deprecated) with pd.concat().
  4. Testing:

    • Added test_bootstrap.py which mocks matlab.engine and verifies that the simulation loop runs, creates expected files (PHm.txt), and processes results correctly.
    • Ensured tests pass even when matlab module is not present in the environment.

Verification

  • Ran test_bootstrap.py successfully.
  • Ran ruff to ensure code quality.
  • Verified that bootstrap_v1.py and bootstrap_v2.py can be imported and fail gracefully when input files are missing (as expected in the test environment).

PR created automatically by Jules for task 153735260210762914 started by @alfieprojectsdev

- Created `analysis/08 Bootstrapping/bootstrap_utils.py` to encapsulate shared logic for running bootstrap simulations and plotting results.
- Updated `bootstrap_v1.py` and `bootstrap_v2.py` to use `bootstrap_utils.py`, removing code duplication while preserving version-specific configurations (reference stations, sample sizes).
- Replaced deprecated `DataFrame.append` with `pd.concat` for compatibility with modern pandas versions.
- Added `test_bootstrap.py` with comprehensive unit tests mocking the MATLAB engine to verify functionality without requiring a MATLAB installation.
- Cleaned up imports and added error handling for file operations.

Co-authored-by: alfieprojectsdev <11991855+alfieprojectsdev@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown
Contributor

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

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