Skip to content

Deprecate mlab functions - #9151

Merged
tacaswell merged 5 commits into
matplotlib:masterfrom
dstansby:mlab-deprecate
Feb 5, 2018
Merged

tacaswell merged 5 commits into
matplotlib:masterfrom
dstansby:mlab-deprecate

Conversation

@dstansby

@dstansby dstansby commented Sep 2, 2017 •

Copy link
Copy Markdown
Member

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
Comment thread lib/matplotlib/mlab.py Outdated
return np.sum(np.abs(a) ** p) ** (1 / p)


@cbook.deprecated('2.1', alternative='np.linspace(xini, xfin, delta)')

Copy link
Copy Markdown
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
Copy Markdown
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'.

Comment thread lib/matplotlib/mlab.py Outdated


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

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

@afvincent afvincent Sep 4, 2017 •

Copy link
Copy Markdown
Contributor

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

@efiring efiring left a comment

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.

I think this is fine once the frange alternative is fixed.

Comment thread lib/matplotlib/mlab.py Outdated
return np.sum(np.abs(a) ** p) ** (1 / p)


@cbook.deprecated('2.1', alternative='np.linspace(xini, xfin, delta)')

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.

I think it would be worthwhile specifying 'np.linspace' as the alternative without including the arguments. Or specify both: 'np.linspace or np.arange'.

Comment thread lib/matplotlib/mlab.py Outdated


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

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? Why? Where is 'geomspace'? The alternative looks fine to me as-is.

@anntzer

anntzer commented Sep 5, 2017 •

Copy link
Copy Markdown
Contributor

(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

dstansby commented Sep 5, 2017

Copy link
Copy Markdown
Member Author

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

dstansby commented Sep 8, 2017

Copy link
Copy Markdown
Member Author

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

Comment thread lib/matplotlib/mlab.py Outdated
return np.exp(np.linspace(np.log(xmin), np.log(xmax), N))


@cbook.deprecated("2.2", alternative='np.sqrt')

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

dstansby commented Sep 9, 2017

Copy link
Copy Markdown
Member Author

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.

HAS_NATGRID = False


'''

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

anntzer commented Sep 10, 2017

Copy link
Copy Markdown
Contributor

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
Comment thread lib/matplotlib/cbook/__init__.py Outdated
return result


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

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

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

@QuLogic

QuLogic commented Nov 14, 2017

Copy link
Copy Markdown
Member

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

Comment thread lib/matplotlib/pylab.py

## We are still importing too many things from mlab; more cleanup is needed.

from matplotlib.mlab import (

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.

These should probably stay but warn?

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.

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

dstansby commented Jan 9, 2018

Copy link
Copy Markdown
Member Author

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.

@jklymak jklymak left a comment

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.

Checked that ll examples and tutorials look good, and they do.

@QuLogic

QuLogic commented Jan 13, 2018

Copy link
Copy Markdown
Member

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

@dstansby

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

@dstansby This needs a rebase.

@tacaswell

Copy link
Copy Markdown
Member

👍 in principle, will leave detailed review to others

Comment thread lib/matplotlib/contour.py
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

@story645 story645 Feb 5, 2018 •

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.

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
Copy Markdown
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

dstansby commented Feb 5, 2018

Copy link
Copy Markdown
Member Author

🎉 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