Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 5 commits into from
Feb 5, 2018
Merged

Conversation

dstansby
Copy link
Member

@dstansby dstansby commented Sep 2, 2017

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:

  • def window_hanning(x):
  • def window_none(x):
  • def apply_window(x, window, axis=0, return_window=None):
  • def detrend(x, key=None, axis=None):
  • def demean(x, axis=0):
  • def detrend_mean(x, axis=None):
  • def detrend_none(x, axis=None):
  • def detrend_linear(y):
  • def stride_windows(x, n, noverlap=None, axis=0):
  • def stride_repeat(x, n, axis=0):
  • def _spectral_helper(x, y=None, NFFT=None, Fs=None, detrend_func=None,
  • def _single_spectrum_helper(x, mode, Fs=None, window=None, pad_to=None,
  • def psd(x, NFFT=None, Fs=None, detrend=None, window=None,
  • def csd(x, y, NFFT=None, Fs=None, detrend=None, window=None,
  • def complex_spectrum(x, Fs=None, window=None, pad_to=None,
  • def magnitude_spectrum(x, Fs=None, window=None, pad_to=None,
  • def angle_spectrum(x, Fs=None, window=None, pad_to=None,
  • def phase_spectrum(x, Fs=None, window=None, pad_to=None,
  • def specgram(x, NFFT=None, Fs=None, detrend=None, window=None,
  • def cohere(x, y, NFFT=256, Fs=2, detrend=detrend_none, window=window_hanning,
  • def bivariate_normal(X, Y, sigmax=1.0, sigmay=1.0,
  • def griddata(x, y, z, xi, yi, interp='nn'):
  • def less_simple_linear_interpolation(x, y, xi, extrap=False):
  • class GaussianKDE(object):
  • def is_closed_polygon(X):
  • def contiguous_regions(mask):
  • def distances_along_curve(X):
  • def path_length(X):

@tacaswell tacaswell added this to the 2.2 (next next feature release) milestone Sep 2, 2017
@@ -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)')
Copy link
Contributor

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

Copy link
Member

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'.

@@ -186,6 +186,8 @@
long = int


@cbook.deprecated("2.1",
alternative='np.logspace(np.log(xmin), np.log(xmax), N)')
Copy link
Contributor

Choose a reason for hiding this comment

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

or geomspace

Copy link
Member

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.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor

@afvincent afvincent Sep 4, 2017

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).

efiring
efiring previously requested changes Sep 2, 2017
Copy link
Member

@efiring efiring left a 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.

@@ -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)')
Copy link
Member

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'.

@@ -186,6 +186,8 @@
long = int


@cbook.deprecated("2.1",
alternative='np.logspace(np.log(xmin), np.log(xmax), N)')
Copy link
Member

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.

@anntzer
Copy link
Contributor

anntzer commented Sep 5, 2017

(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.)

@dstansby
Copy link
Member Author

dstansby commented Sep 5, 2017

Fair enough, I'll give it all a go once 2.1 has been released!

@dstansby dstansby changed the title Deprecate some mlab functions Deprecate mlab functions Sep 8, 2017
@dstansby dstansby force-pushed the mlab-deprecate branch 2 times, most recently from 9247888 to b4a3430 Compare September 8, 2017 19:47
@dstansby
Copy link
Member Author

dstansby commented Sep 8, 2017

Going to carry on with deprecations on this branch. Anyone can feel free to push to it

@@ -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')
Copy link
Contributor

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

@anntzer anntzer dismissed efiring’s stale review September 8, 2017 20:19

comments handled

@dstansby
Copy link
Member Author

dstansby commented Sep 9, 2017

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.

@@ -24,12 +25,21 @@
HAS_NATGRID = False


'''
Copy link
Contributor

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

@anntzer
Copy link
Contributor

anntzer commented Sep 10, 2017

Probably needs an entry into api_changes, but otherwise lgtm.

@dstansby dstansby mentioned this pull request Sep 21, 2017
@dstansby dstansby changed the title Deprecate mlab functions [WIP] Deprecate mlab functions Sep 21, 2017
@@ -1578,6 +1578,48 @@ def simple_linear_interpolation(a, steps):
return result


def less_simple_linear_interpolation(x, y, xi, extrap=False):
Copy link
Contributor

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... :-)

Copy link
Member Author

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.

Copy link
Member Author

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]))
Copy link
Contributor

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.

Copy link
Member Author

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)

Copy link
Contributor

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 :)

Copy link
Member Author

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.

Copy link
Contributor

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.

@dstansby dstansby changed the title [WIP] Deprecate mlab functions Deprecate mlab functions Nov 13, 2017
@dstansby
Copy link
Member Author

Apart from the macOS tests not passing, and any changes reviewers request, I'm considering this PR done now.

@QuLogic
Copy link
Member

QuLogic commented Nov 14, 2017

Hmm, you only really needed to put the mlab calls in the warns context, which would probably cut down on the changes a bit?

@@ -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 (
Copy link
Member

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?

Copy link
Member Author

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.

@anntzer anntzer dismissed their stale review December 27, 2017 18:08

issues handled

@dstansby dstansby added status: needs review Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Jan 8, 2018
@dstansby
Copy link
Member Author

dstansby commented Jan 9, 2018

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.

Copy link
Member

@jklymak jklymak left a 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.

@QuLogic
Copy link
Member

QuLogic commented Jan 13, 2018

So you're leaving the remaining unchecked ones for some other PR, right?

@dstansby
Copy link
Member Author

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.

@tacaswell
Copy link
Member

@dstansby This needs a rebase.

@tacaswell
Copy link
Member

👍 in principle, will leave detailed review to others

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
Copy link
Member

@story645 story645 Feb 5, 2018

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.

@tacaswell tacaswell merged commit 3e37306 into matplotlib:master Feb 5, 2018
@tacaswell
Copy link
Member

This will need some additional documentation for the final 2.2 release, but merging now to move things along.

@dstansby dstansby deleted the mlab-deprecate branch February 5, 2018 21:29
@dstansby
Copy link
Member Author

dstansby commented Feb 5, 2018

🎉 thanks to everyone who left comments or reviewed this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants