Skip to content

numpy: Handle multidimentional indexing in 1.15#3238

Merged
soupault merged 4 commits intoscikit-image:masterfrom
hmaarrfk:numpy_1_15
Jul 25, 2018
Merged

numpy: Handle multidimentional indexing in 1.15#3238
soupault merged 4 commits intoscikit-image:masterfrom
hmaarrfk:numpy_1_15

Conversation

@hmaarrfk
Copy link
Copy Markdown
Member

@hmaarrfk hmaarrfk commented Jul 1, 2018

Future me notes: use

git checkout master
git pull upstream master
git rebase -i master

to pull it out and edit it to whatever the final solution is chosen to be.

Checklist

[It's fine to submit PRs which are a work in progress! But before they are merged, all PRs should provide:]

[For detailed information on these and other aspects see scikit-image contribution guidelines]

References

[If this is a bug-fix or enhancement, it closes issue # ]
[If this is a new feature, it implements the following paper: ]

For reviewers

(Don't remove the checklist below.)

  • Check that the PR title is short, concise, and will make sense 1 year
    later.
  • Check that new functions are imported in corresponding __init__.py.
  • Check that new features, API changes, and deprecations are mentioned in
    doc/release/release_dev.rst.
  • Consider backporting the PR with @meeseeksdev backport to v0.14.x

@pep8speaks
Copy link
Copy Markdown

pep8speaks commented Jul 1, 2018

Hello @hmaarrfk! Thanks for updating the PR.

Line 35:80: E501 line too long (131 > 79 characters)

Comment last updated on July 22, 2018 at 03:24 Hours UTC

@hmaarrfk hmaarrfk changed the title Handle numpy 1.15 deprecations pytest: Handle numpy 1.15 deprecations to pass tests Jul 1, 2018
@hmaarrfk
Copy link
Copy Markdown
Member Author

hmaarrfk commented Jul 2, 2018

Maybe a better way to handle scipy's use of the matrix subclass for sparse matricies is to use https://github.com/pydata/sparse internally.

Copy link
Copy Markdown
Member

@soupault soupault left a comment

Choose a reason for hiding this comment

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

Thanks for the PR! I think many of the changes could be simplified to lower the visual complexity of the code. Also, the warnings conditional on package versions should be considered for further refactoring.

futures = [dask.delayed(_run_one_shift)(s) for s in all_shifts]
mean = sum(futures) / len(futures)
mean = mean.compute(get=dask.threaded.get, num_workers=num_workers)
mean = mean.compute(scheduler='threading', num_workers=num_workers)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To be fixed via #3205

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Ok. That was easy to remove using rebasing :D

label_img_expanded = np.zeros([(2 * s - 1) for s in label_img.shape],
label_img.dtype)
pixels = [slice(None, None, 2)] * ndim
pixels = tuple([slice(None, None, 2)] * ndim)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is just pixels = (slice(None, None, 2), ) * ndim

space_size = float(np.prod(ar_shape))
if space_size <= n_points:
return [slice(None)] * ndim
return tuple([slice(None)] * ndim)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same :)

slices = [slice(start, None, step) for
start, step in zip(starts, stepsizes)]
slices = [slices[i] for i in unsort_dim_idxs]
slices = tuple([slices[i] for i in unsort_dim_idxs])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not tuple(slices[i] for i in unsort_dim_idxs)?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

You know, I thought you needed the square brackets to make it a list comprehension. I guess you don't :D

Copy link
Copy Markdown
Member

@soupault soupault Jul 3, 2018

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

nice one! Yeah, I still don't know generator expressions.

ar = np.array(ar, copy=False)
crops = _validate_lengths(ar, crop_width)
slices = [slice(a, ar.shape[i] - b) for i, (a, b) in enumerate(crops)]
slices = tuple([slice(a, ar.shape[i] - b)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same

arr_in = np.ascontiguousarray(arr_in)

slices = [slice(None, None, st) for st in step]
slices = tuple([slice(None, None, st) for st in step])
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Same

Finally, you can use `|\A\Z` in a pattern to signify it as optional.

"""
if isinstance(matching, str):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is nice!

"""
start = (np.array(x.shape) - np.array(oshape)) // 2 + 1
out = x[[slice(s, s + n) for s, n in zip(start, oshape)]]
out = x[tuple([slice(s, s + n) for s, n in zip(start, oshape)])]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also here, and below

from skimage._shared._warnings import expected_warnings


if Version(np.__version__) >= '1.15' and Version(scipy.__version__) <= '1.1.0':
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Are there any plans on removing this check in future? If yes, please, add a note to TODO file


# SNR is improved less with 1 wavelet level than with the default.
denoised_1 = restoration.denoise_wavelet(noisy,
with expected_warnings([None]):
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the benefit of using None?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The benefit of using none is that under certain build conditions, where we don't expect warnings, None can be passed in.

@soupault soupault added the 🔧 type: Maintenance Refactoring and maintenance of internals label Jul 3, 2018
@soupault soupault added this to the 0.14.1 milestone Jul 3, 2018
@hmaarrfk
Copy link
Copy Markdown
Member Author

hmaarrfk commented Jul 3, 2018

@soupault plans for deprecacting the logic behind the conditional warnings:

Well, the plan for removing it is so long term that I didn't know if it makes sense. I'll add some words about it.

I assume that scipy (and pywavelets) will eventually fix these warnings on their side too. at which point, some version of scipy, higher than 1.1.6, will eventually not have these warnings by default. But until then, this is just a very explicit way ensuring warning are

@codecov-io
Copy link
Copy Markdown

codecov-io commented Jul 3, 2018

Codecov Report

Merging #3238 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #3238   +/-   ##
=======================================
  Coverage   81.98%   81.98%           
=======================================
  Files         339      339           
  Lines       27313    27313           
=======================================
  Hits        22392    22392           
  Misses       4921     4921
Impacted Files Coverage Δ
skimage/morphology/greyreconstruct.py 96.42% <100%> (ø) ⬆️
skimage/restoration/_denoise.py 96.87% <100%> (ø) ⬆️
skimage/filters/lpi_filter.py 97.33% <100%> (ø) ⬆️
skimage/data/_binary_blobs.py 100% <100%> (ø) ⬆️
skimage/restoration/uft.py 100% <100%> (ø) ⬆️
skimage/feature/template.py 100% <100%> (ø) ⬆️
skimage/util/_regular_grid.py 100% <100%> (ø) ⬆️
skimage/restoration/tests/test_denoise.py 99.71% <100%> (ø) ⬆️
skimage/morphology/extrema.py 94.89% <100%> (ø) ⬆️
skimage/util/arraycrop.py 100% <100%> (ø) ⬆️
... and 4 more

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 034f505...ad93f97. Read the comment docs.

@hmaarrfk
Copy link
Copy Markdown
Member Author

hmaarrfk commented Jul 3, 2018

Finally, I was testing out avoiding the use of |\A\Z since it isn't really explicit as to what conditions might trigger the warning.

Even without instructions, somebody 10 years from now would be able to go through the code, find that a certain combinations of packages can't exist in their supported versions, and rip out the logic if they want to.

That said, I don't know when pywavelets and scipy will address their warnings, maybe it is for us to send in the PR, and the tests might fail once or twice until they get around to fixing their codebase. We would require version bumps on the logic at that point.

The matrix subclass warning should definitely be broadened, as that would require a major change on scipy's end.

@hmaarrfk
Copy link
Copy Markdown
Member Author

hmaarrfk commented Jul 3, 2018

I just updated the scipy dependency to not depend on the minor version number for the sparse matrix warning.

@hmaarrfk hmaarrfk mentioned this pull request Jul 3, 2018
4 tasks
@hmaarrfk hmaarrfk changed the title pytest: Handle numpy 1.15 deprecations to pass tests numpy: Handle multidimentional indexing in 1.15 Jul 3, 2018
Copy link
Copy Markdown
Member

@soupault soupault left a comment

Choose a reason for hiding this comment

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

Couple of remarks are still pending, but they aren't blocking :). Otherwise, lgtm.

@hmaarrfk hmaarrfk force-pushed the numpy_1_15 branch 2 times, most recently from 7b65ff0 to 91a641d Compare July 4, 2018 02:09
@jni
Copy link
Copy Markdown
Member

jni commented Jul 5, 2018

Before anyone merges, I suggested in #3235 (comment) that changing the return type of rectangular_grid should be done over a deprecation cycle.

@hmaarrfk
Copy link
Copy Markdown
Member Author

@jni I finally got around to removing the keyword argument and added your suggested Notes section.

Copy link
Copy Markdown
Member

@jni jni left a comment

Choose a reason for hiding this comment

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

@hmaarrfk I've tweaked it a little but otherwise LVGTM. ;) Can someone more familiar with Sphinx check my formatting? CC @stefanv

(For some reason I can't build the docs on my machine; make html inside the doc directory gives me the following error:

 ~/projects/scikit-image/doc (numpy_1_15)
 $ make
python tools/build_modref_templates.py
/home/jni/projects/scikit-image/skimage/novice/__init__.py:103: UserWarning: The `skimage.novice` module was deprecated in version 0.14. It will be removed in 0.16.
  warnings.warn("The `skimage.novice` module was deprecated in version 0.14. "
WARNING: Empty - skimage.scripts
outdir:  
27 files written
Build API docs...done.
Copying release notes
python  -b html -d build/doctrees  -j 1 source build/html
python: can't open file 'html': [Errno 2] No such file or directory
Makefile:53: recipe for target 'html' failed
make: *** [html] Error 2

)

@hmaarrfk
Copy link
Copy Markdown
Member Author

@jni I tried:

conda install sphinx-gallery scikit-learn sphinx numpydocs
sudo apt-get install texlive texlive-latex-extra dvipng  # big download

I got pretty far in the building process, but still no cigar. Something about a db mismatch.

@soupault
Copy link
Copy Markdown
Member

@jni Looks good to me:
image

@soupault soupault merged commit 3ffd326 into scikit-image:master Jul 25, 2018
@soupault
Copy link
Copy Markdown
Member

Thanks a lot @hmaarrfk !

@soupault
Copy link
Copy Markdown
Member

@meeseeksdev backport to v0.14.x

@lumberbot-app
Copy link
Copy Markdown

lumberbot-app bot commented Jul 25, 2018

There seem to be a conflict, please backport manually

@lumberbot-app lumberbot-app bot added the Still Needs Manual Backport MrMeeseeks-managed label label Jul 25, 2018
soupault added a commit to soupault/scikit-image that referenced this pull request Jul 25, 2018
Handle multidimentional indexing in numpy 1.15
soupault added a commit to soupault/scikit-image that referenced this pull request Jul 25, 2018
Handle multidimentional indexing in numpy 1.15
soupault added a commit to soupault/scikit-image that referenced this pull request Jul 25, 2018
Handle multidimentional indexing in numpy 1.15
@soupault
Copy link
Copy Markdown
Member

Apparently, I have 0 knowledge on the manual backporting of merge commits... Could someone try to handle this, please?

@soupault
Copy link
Copy Markdown
Member

(For some reason I can't build the docs on my machine; make html inside the doc directory gives me the following error:

@jni Try to update Sphinx and other docs requirements. Worked for me.

@Carreau
Copy link
Copy Markdown
Contributor

Carreau commented Aug 13, 2018

Apparently, I have 0 knowledge on the manual backporting of merge commits... Could someone try to handle this, please?

That's the kind of issue you can raise on MrMeeseeks repo. The "there seem to be a conflict" comments should now have instruction on which git commands to issue to backport a merge commit

soupault added a commit that referenced this pull request Aug 14, 2018
@soupault
Copy link
Copy Markdown
Member

@Carreau Very nice addition, thanks!

@hmaarrfk
Copy link
Copy Markdown
Member Author

I just learned where MrMeeseeks is from....

@jni
Copy link
Copy Markdown
Member

jni commented Aug 23, 2018

@hmaarrfk

I just learned where MrMeeseeks is from....

Time for some Netflix binge-watching. =D

@hmaarrfk hmaarrfk deleted the numpy_1_15 branch November 4, 2018 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Still Needs Manual Backport MrMeeseeks-managed label 🔧 type: Maintenance Refactoring and maintenance of internals

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants