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

Handle warnings about upcoming deprecations #1303

Open
2 tasks done
EricThomson opened this issue Mar 22, 2024 · 5 comments
Open
2 tasks done

Handle warnings about upcoming deprecations #1303

EricThomson opened this issue Mar 22, 2024 · 5 comments

Comments

@EricThomson
Copy link
Contributor

EricThomson commented Mar 22, 2024

Turned off warnings and checked for upcoming deprecations. Most of these are repeated many times in the different notebooks, just noting the warnings not where they are occurring in the code base:

  • caiman\utils\visualization.py:783: MatplotlibDeprecationWarning: The get_cmap function was deprecated in Matplotlib 3.7 and will be removed two minor releases later. Use matplotlib.colormaps[name] or matplotlib.colormaps.get_cmap(obj) instead. (colormap = matplotlib.cm.get_cmap(cmap) # choose any matplotlib colormap here)

  • caiman\source_extraction\cnmf\spatial.py:844: DeprecationWarning: Please use grey_dilation from the scipy.ndimage namespace, the scipy.ndimage.morphology namespace is deprecated. from scipy.ndimage.morphology import grey_dilation. (evaluate_components)

A couple to not handle now, or not our problem:

  • random.py:370: DeprecationWarning: non-integer arguments to randrange() have been deprecated since Python 3.10 and will be removed in a subsequent version return self.randrange(a, b+1) (nb_view_components) [not our direct problem other than Python versioning, which is our problem -- for Windows users Python 3.10 is currently the main successful build, so ... 😬 ]

  • caiman\base\rois.py:56: PendingDeprecationWarning: the matrix subclass is not the recommended way to represent matrices or deal with linear algebra (see https://docs.scipy.org/doc/numpy/user/numpy-for-matlab-users.html). Please adjust your code to use regular ndarray. Coor = np.matrix([np.outer(np.ones(d2), np.arange(d1)).ravel(), [Handle later -- see note below in first comment]

@EricThomson
Copy link
Contributor Author

EricThomson commented Mar 22, 2024

Couple of things: most of these are very simple. randrange() deprecation is out of our control I just dumped stuff in here without thinking too much that's a Python standard library thing with v 3.10. The only one that will take some thinking/time is the np.matrix() one, and that is still not deprecated (it's not even very concrete it's just pending). Maybe better to handle that with the push to Numpy 2+ definitely don't want to rush it, it is used in about 20 places in the code base, in important places. The others were all simple syntax changes. Testing them now.

@ethanbb
Copy link
Contributor

ethanbb commented Sep 10, 2024

caiman\source_extraction\cnmf\spatial.py:844: DeprecationWarning: Please use grey_dilation from the scipy.ndimage namespace, the scipy.ndimage.morphology namespace is deprecated. from scipy.ndimage.morphology import grey_dilation. (evaluate_components)

I'm getting the same warning (repeated many many times) from line 955 of spatial.py (construct_dilate_parallel):

from scipy.ndimage.morphology import generate_binary_structure, iterate_structure, grey_dilation

Since these are now imported at the top level, this line can just be removed, right?

@pgunn
Copy link
Member

pgunn commented Sep 10, 2024

@ethanbb Ah, yes. Good spot. I've been trying to remove non-toplevel imports when I find them.

You want to do it or shall I?

@ethanbb
Copy link
Contributor

ethanbb commented Sep 10, 2024

I can do it no problem! I'll do a quick search for any other similar cases first.

@ethanbb
Copy link
Contributor

ethanbb commented Sep 11, 2024

So actually there is this comment in the same file:

# /!\ need to import since it is run from within the server
import numpy as np
import sys
import gc
from sklearn import linear_model

which seems to imply that the local imports are needed for ipyparallel or multiprocessing workers. But I don't think that's true; anything defined at the module level, including imports, should be accessible to the workers regardless of how they are launched, right?

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

No branches or pull requests

3 participants