-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Deprecate mlab functions #9151
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
Deprecate mlab functions #9151
Conversation
lib/matplotlib/mlab.py
Outdated
@@ -2115,6 +2118,7 @@ def norm_flat(a, p=2): | |||
return np.sum(np.abs(a) ** p) ** (1 / p) | |||
|
|||
|
|||
@cbook.deprecated('2.1', alternative='np.linspace(xini, xfin, delta)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually the alternative is wrong, but I don't think we really need to bother specifying one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be worthwhile specifying 'np.linspace' as the alternative without including the arguments. Or specify both: 'np.linspace or np.arange'.
lib/matplotlib/mlab.py
Outdated
@@ -186,6 +186,8 @@ | |||
long = int | |||
|
|||
|
|||
@cbook.deprecated("2.1", | |||
alternative='np.logspace(np.log(xmin), np.log(xmax), N)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or geomspace
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What? Why? Where is 'geomspace'? The alternative looks fine to me as-is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.scipy.org/doc/numpy/reference/generated/numpy.geomspace.html
TBH I don't care enough about mlab to get into a debate of whether we should recommend an old function with a different behavior, or a new function with the same behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So new I wasn't aware of it. Thank you. I guess I would say "np.logspace or np.geomspace (numpy >= 1.13)" and leave the rest to the user to figure out.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dstansby For the record (more than for another reason as the current suggestions are to avoid specifying the arguments), it should be np.logspace(np.log10(xmin), np.log10(xmax), N)
(the default base for np.logspace
is 10).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine once the frange alternative is fixed.
lib/matplotlib/mlab.py
Outdated
@@ -2115,6 +2118,7 @@ def norm_flat(a, p=2): | |||
return np.sum(np.abs(a) ** p) ** (1 / p) | |||
|
|||
|
|||
@cbook.deprecated('2.1', alternative='np.linspace(xini, xfin, delta)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would be worthwhile specifying 'np.linspace' as the alternative without including the arguments. Or specify both: 'np.linspace or np.arange'.
lib/matplotlib/mlab.py
Outdated
@@ -186,6 +186,8 @@ | |||
long = int | |||
|
|||
|
|||
@cbook.deprecated("2.1", | |||
alternative='np.logspace(np.log(xmin), np.log(xmax), N)') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What? Why? Where is 'geomspace'? The alternative looks fine to me as-is.
(I also think that trying to deprecate mlab one function at a time is a bit a waste of a time, the whole thing should just be dealt with a single shot.) |
Fair enough, I'll give it all a go once 2.1 has been released! |
9247888
to
b4a3430
Compare
Going to carry on with deprecations on this branch. Anyone can feel free to push to it |
lib/matplotlib/mlab.py
Outdated
@@ -194,6 +195,7 @@ def logspace(xmin, xmax, N): | |||
return np.exp(np.linspace(np.log(xmin), np.log(xmax), N)) | |||
|
|||
|
|||
@cbook.deprecated("2.2", alternative='np.sqrt') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just delete it, it's private
Okay, I think that's everything that isn't used elsewhere in Matplotlib. I've put a list of everything left at the top of this PR. Some of them are going to need moving somewhere else, or a bit of work to replace. |
92cc34b
to
401373d
Compare
@@ -24,12 +25,21 @@ | |||
HAS_NATGRID = False | |||
|
|||
|
|||
''' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make this a block comment
Probably needs an entry into api_changes, but otherwise lgtm. |
401373d
to
cabc4a3
Compare
lib/matplotlib/cbook/__init__.py
Outdated
@@ -1578,6 +1578,48 @@ def simple_linear_interpolation(a, steps): | |||
return result | |||
|
|||
|
|||
def less_simple_linear_interpolation(x, y, xi, extrap=False): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would https://docs.scipy.org/doc/numpy/reference/generated/numpy.interp.html not be good enough? Sorry to give you more work... :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't worry, I'm taking this in small steps anyway since it's only going to go in 2.2 anyway. I'll have a go and see if it works.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a simple drop in, so I think I'll leave it as is in this PR.
if mask[-1]: | ||
idx.append(len(mask)) | ||
|
||
return list(zip(idx[::2], idx[1::2])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I bet the fastest (not that it necessarily matters) is either to return an iterator using itertools.chain and itertools.islice, or to preallocate the result as an appropriately sized array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a function I've just directly copied across from mlab to cbook because it's used in 2 different places in Matplotlib
(sorry, I'm kind of dumping stuff as I work on it here, will remove the WIP bit of the title when I think it's all done)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no worries, I'm also just dumping my thoughts here and there :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't get my head around how to make this work so I think I'll leave it for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
np.column_stack([idxs[::2], idxs[1::2]])
should work well.
3e41f32
to
860cc4a
Compare
860cc4a
to
8b54e6b
Compare
Apart from the macOS tests not passing, and any changes reviewers request, I'm considering this PR done now. |
Hmm, you only really needed to put the |
e92a280
to
e9071ef
Compare
lib/matplotlib/pylab.py
Outdated
@@ -240,21 +236,7 @@ | |||
# bring all the symbols in so folks can import them from | |||
# pylab in one fell swoop | |||
|
|||
## We are still importing too many things from mlab; more cleanup is needed. | |||
|
|||
from matplotlib.mlab import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should probably stay but warn?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've just reverted the changes to pylab - if anyone tries to use the deprecated methods they'll be warned.
72882be
to
862ab60
Compare
I've put this as release critical, as I think it would be good to have these deprecations in 2.2 instead of waiting for 3.0. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checked that ll examples and tutorials look good, and they do.
So you're leaving the remaining unchecked ones for some other PR, right? |
Yeah, I have some code sat locally to cover the rest, but don't want to upload it as part of this PR as I think this one's big enough already. |
@dstansby This needs a rebase. |
👍 in principle, will leave detailed review to others |
862ab60
to
9bfcec0
Compare
9bfcec0
to
4c61a1d
Compare
def _is_closed_polygon(X): | ||
""" | ||
Tests whether first and last object in a sequence are the same. These are | ||
presumably coordinates on a polygonal curve, in which case this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are presumably coordinates on a polygonal curve, in which case this function tests if that curve is closed.
Sort of odd construction?
Since these objects are presumed to be coordinates on a polygonal curve, this function tests if the curve is closed.
This will need some additional documentation for the final 2.2 release, but merging now to move things along. |
🎉 thanks to everyone who left comments or reviewed this! |
Here's a catch-all deprecation PR for
mlab
. The aim is to deprecate or move everything that isn't spectral related.Non-trival deprecations that are used elsewhere in Matplotlib: