Skip to content

Conversation

@jdkent
Copy link
Member

@jdkent jdkent commented Dec 18, 2025

Closes #922 .

Changes proposed in this pull request:

Summary by Sourcery

Adjust FWECorrector Monte Carlo parameter handling to respect estimator defaults and add regression tests for this behavior.

Bug Fixes:

  • Prevent FWECorrector with Monte Carlo method from overriding estimator default n_iters when it is not explicitly provided.

Tests:

  • Add tests verifying FWECorrector(montecarlo) omits n_iters when not set and propagates explicit n_iters and n_cores values.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Dec 18, 2025

Reviewer's Guide

Adjusts FWECorrector’s Monte Carlo configuration to avoid overriding estimator defaults when n_iters is None, and adds tests to verify correct parameter propagation and defaults.

Class diagram for updated FWECorrector initialization

classDiagram
    class FWECorrector {
        +str method
        +dict parameters
        +__init__(method, n_iters, n_cores, kwargs)
    }

    FWECorrector : method default bonferroni
    FWECorrector : n_iters default None
    FWECorrector : n_cores default 1
    FWECorrector : parameters holds correction configuration
    FWECorrector : on init validate method
    FWECorrector : on init set parameters based on method and kwargs
    FWECorrector : for method montecarlo only set n_iters in parameters when n_iters is not None
    FWECorrector : for method montecarlo always set n_cores in parameters
Loading

Flow diagram for Monte Carlo FWECorrector parameter handling

flowchart TD
    A[start FWECorrector __init__] --> B[check method value]
    B -->|method not supported| C[raise ValueError]
    B -->|method equals montecarlo| D[handle montecarlo parameters]
    B -->|method not montecarlo| G[skip montecarlo config]

    D --> E{is n_iters not None?}
    E -->|yes| F[set kwargs n_iters to provided n_iters]
    E -->|no| H[do not set kwargs n_iters, keep estimator default]

    F --> I[set kwargs n_cores to provided n_cores]
    H --> I[set kwargs n_cores to provided n_cores]

    I --> J[store method in instance attribute]
    G --> J
    J --> K[store kwargs in parameters attribute]
    K --> L[end FWECorrector __init__]
Loading

File-Level Changes

Change Details Files
Refine FWECorrector Monte Carlo parameter handling to avoid passing None for n_iters while still forwarding n_cores.
  • Update FWECorrector init to only include n_iters in kwargs when it is explicitly provided (non-None).
  • Ensure n_cores is always propagated through kwargs for Monte Carlo correction.
nimare/correct.py
Add unit tests validating FWECorrector Monte Carlo behavior for default and custom parameters.
  • Add test ensuring that when FWECorrector(montecarlo) is called without n_iters, the parameters dict does not contain n_iters but does contain the default n_cores.
  • Add test ensuring that explicit n_iters and n_cores values are correctly stored in FWECorrector parameters.
nimare/tests/test_correct.py

Assessment against linked issues

Issue Objective Addressed Explanation
#922 Fix the TypeError raised when running FWECorrector(method='montecarlo') with MKDAChi2 (via correct_fwe_montecarlo) using default parameters, so that FWE('montecarlo') correction completes successfully.
#922 Ensure FWECorrector with method='montecarlo' respects estimator-specific defaults for n_iters when n_iters is not provided, while still propagating explicitly provided n_iters and n_cores values.

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • Consider applying the same None-aware logic to n_cores as you did for n_iters (only setting it in kwargs when not None) so that estimators can fall back to their own n_cores defaults when desired.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider applying the same `None`-aware logic to `n_cores` as you did for `n_iters` (only setting it in `kwargs` when not `None`) so that estimators can fall back to their own `n_cores` defaults when desired.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@jdkent jdkent merged commit db37ecb into neurostuff:main Dec 19, 2025
20 checks passed
@codecov
Copy link

codecov bot commented Dec 19, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.26%. Comparing base (6b3e899) to head (1c3e8b1).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #959   +/-   ##
=======================================
  Coverage   88.25%   88.26%           
=======================================
  Files          49       49           
  Lines        6924     6926    +2     
=======================================
+ Hits         6111     6113    +2     
  Misses        813      813           

☔ View full report in Codecov by Sentry.
📢 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.

@jdkent jdkent moved this to Done in Planning Dec 19, 2025
@jdkent jdkent added this to Planning Dec 19, 2025
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.

TypeError when using nimare.meta.cbma.mkda.MKDAChi2.correct_fwe_montecarlo

1 participant