Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[doc] Warning for non-matching n_parcels #2240

Merged
merged 7 commits into from
Dec 5, 2019

Conversation

emdupre
Copy link
Member

@emdupre emdupre commented Dec 3, 2019

Closes #2238.

  • Adds a warning when learned n_parcels does not match requested n_parcels

@codecov
Copy link

codecov bot commented Dec 3, 2019

Codecov Report

Merging #2240 into master will decrease coverage by 0.12%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2240      +/-   ##
==========================================
- Coverage    92.7%   92.57%   -0.13%     
==========================================
  Files         150      150              
  Lines       19019    19038      +19     
  Branches     2311     2313       +2     
==========================================
- Hits        17632    17625       -7     
- Misses        883      905      +22     
- Partials      504      508       +4
Impacted Files Coverage Δ
nilearn/regions/tests/test_parcellations.py 100% <100%> (ø) ⬆️
nilearn/regions/parcellations.py 96.36% <100%> (+0.17%) ⬆️
nilearn/reporting/rm_file.py 26.66% <0%> (-53.34%) ⬇️
nilearn/_utils/testing.py 79.57% <0%> (-4.93%) ⬇️
nilearn/plotting/__init__.py 95.65% <0%> (-4.35%) ⬇️
nilearn/plotting/tests/test_js_plotting_utils.py 97.6% <0%> (-1.6%) ⬇️
nilearn/datasets/tests/test_neurovault.py 95.84% <0%> (-0.98%) ⬇️
nilearn/image/image.py 95.37% <0%> (-0.72%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update da84a26...ab8cfad. Read the comment docs.

@kchawla-pi
Copy link
Collaborator

Nice! A test & what's new entry & this should be ready.

@emdupre
Copy link
Member Author

emdupre commented Dec 4, 2019

@GaelVaroquaux I was looking at adding another test, to confirm that the warning isn't raised when the n_parcels number matches. Here's what I had:

@pytest.mark.filterwarnings('ignore::DeprecationWarning')
def test_parcellations_no_warnings():
    data = np.zeros((10, 11, 12, 5))
    img = nibabel.Nifti1Image(data, affine=np.eye(4))
    parcellator_n7 = Parcellations(method='kmeans', n_parcels=1)
    with pytest.warns(None) as record:
        parcellator_n7.fit(img)
    assert record.list is None

The problem is that DeprecationWarning's still aren't being filtered. It looks to be related to this point.

Do you have any suggestions of how to filter appropriately and confirm there's no UserWarning, but other (deprecation) warnings are fine ?

@GaelVaroquaux
Copy link
Member

GaelVaroquaux commented Dec 4, 2019 via email

@kchawla-pi
Copy link
Collaborator

kchawla-pi commented Dec 4, 2019

Hi @emdupre
What I suggest is to simply use the match parameter in the pytest.warns(match=) to specifically match the string from your warning to ensure other UserWarnings are not caught by mistake.

Also instead of doing what you did above, you can write another test like the one you have added in the code, but engineered such that the number of parcels are the same, and mark it as expected to fail, using @pytest.mark.xfail

@GaelVaroquaux
Copy link
Member

Once CI is green, I am +1 for merge.

@emdupre
Copy link
Member Author

emdupre commented Dec 4, 2019

Thanks, @kchawla-pi and @GaelVaroquaux !

Hopefully this will pass as-is, but the different methods are good to know moving forward 😸

@kchawla-pi
Copy link
Collaborator

Totally. I particularly love pytest.warn(match=' string'). It is so much more compact & cleaner than the built in Python one.

@kchawla-pi
Copy link
Collaborator

kchawla-pi commented Dec 4, 2019

I would filter out the list manually here.

In my experience the manual parsing approach is rather fragile, and when implemented in a robust way, looks ugly. Do consider my suggestion, I think that approach is clean and robust.

Copy link
Member

@GaelVaroquaux GaelVaroquaux left a comment

Choose a reason for hiding this comment

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

LGTM. Thank you for your perseverence

@GaelVaroquaux GaelVaroquaux merged commit 7fd55ba into nilearn:master Dec 5, 2019
@kchawla-pi
Copy link
Collaborator

@emdupre I played around with Pytest to see if we can find ways to improve the testing. It seems to me my suggestion has gaps that pytest does not handle (counter-intuitive, hope they fix it), and your way is the better one.

kchawla-pi added a commit to tbng/nilearn that referenced this pull request Dec 7, 2019
…der2

* 'master' of https://github.com/nilearn/nilearn:
  BUG: NiftiLabelsMasker inverse_transform without transform (nilearn#2248)
  Details in CONTRIBUTING.rst
  Update CONTRIBUTING.rst (nilearn#2262)
  [MRG+1] Remove support for old parameters in view_connectome & view_markers (nilearn#2255)
  maint: warn upcoming deprecation for fetch_haxby_simple (nilearn#2256)
  fix: remove now duplicated report scraper (nilearn#2261)
  Region means are no longer casted to Int type for Int images in NiftLabelsMasker (nilearn#2195)
  Improve replace parameters (nilearn#2254)
  Fix tests pertaining to replace_parameters functionality (nilearn#2253)
  [doc] Warning for non-matching n_parcels (nilearn#2240)
  More clear CONTRIBUTING.rst (nilearn#2246)
  doc: remove now unecessary print statements (nilearn#2243)
  [doc] Iimprove documentation re: using index_img with slice() (nilearn#2189)
  Argument version='det' in pauli 2017 atlas now works correctly (nilearn#2235)
  Fix:  Nilearn raises Nose ImportError with no MatPlotLib (nilearn#2231)
  Non-iterable Image headers are not copied anymore (nilearn#2212)
  Add parameter "strategy" to NiftiLabelsMasker to choose function to reduce ROIs (nilearn#2221)
  Improved nifti masker documentation (nilearn#2234)
  CI: Use pkg_resources to list installed dependencies (nilearn#2228)
  CI: Test pre-release versions of dependencies (nilearn#2224)
SylvainTakerkart added a commit to SylvainTakerkart/nilearn that referenced this pull request Dec 12, 2019
…rtva_fetcher_dev

* 'master' of https://github.com/nilearn/nilearn: (30 commits)
  Remove appveyor (nilearn#2267)
  Maint: Replace nose with Pytest - 1 (Asserts, warns, raises) (nilearn#2232)
  Release 0.6.0 (nilearn#2265)
  doc: remove outdated references to multisubjs (nilearn#2264)
  typo + changes for plot_decoding_tutorial (nilearn#2260)
  [documentation] Searchlight user guide (nilearn#2257)
  BUG: NiftiLabelsMasker inverse_transform without transform (nilearn#2248)
  Details in CONTRIBUTING.rst
  Update CONTRIBUTING.rst (nilearn#2262)
  [MRG+1] Remove support for old parameters in view_connectome & view_markers (nilearn#2255)
  maint: warn upcoming deprecation for fetch_haxby_simple (nilearn#2256)
  fix: remove now duplicated report scraper (nilearn#2261)
  Region means are no longer casted to Int type for Int images in NiftLabelsMasker (nilearn#2195)
  Improve replace parameters (nilearn#2254)
  Fix tests pertaining to replace_parameters functionality (nilearn#2253)
  [doc] Warning for non-matching n_parcels (nilearn#2240)
  More clear CONTRIBUTING.rst (nilearn#2246)
  doc: remove now unecessary print statements (nilearn#2243)
  [doc] Iimprove documentation re: using index_img with slice() (nilearn#2189)
  Argument version='det' in pauli 2017 atlas now works correctly (nilearn#2235)
  ...
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.

Add warning when calculated n_parcels does not match requested n_parcels
4 participants