Skip to content

Fix deprecations in examples #10385

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 3 commits into from
Feb 9, 2018
Merged

Conversation

QuLogic
Copy link
Member

@QuLogic QuLogic commented Feb 6, 2018

PR Summary

This fixes several deprecation warnings that are triggered by the examples.

Currently, plt.plotfile calls mlab.csv2rev, which is deprecated. Because that function provides some automatic converters, I could not replace it with np.genfromtxt or np.loadtxt right away, as that would be a behaviour change. Even the examples take advantage of this behaviour.

plt.plotfile also triggers a warning about re-using an Axes spec. I have not looked too deeply into fixing that one.

PR Checklist

  • Has Pytest style unit tests
  • Code is PEP 8 compliant
  • [N/A] New features are documented, with examples if plot related
  • [N/A] Documentation is sphinx and numpydoc compliant
  • [N/A] Added an entry to doc/users/next_whats_new/ if major new feature (follow instructions in README.rst there)
  • [N/A] Documented in doc/api/api_changes.rst if API changed in a backward-incompatible way

The normal colorbar works fine if calling colorbar.set_ticks instead of
colobar.ax.set_ticks, which is noted in the deprecation warning. There
is no real benefit of showing the axes_grid1 version now.
Unfortunately, csv2rec provides some automatic converters, so it can't
be replaced entirely with np.genfromtxt or np.loadtxt.
@QuLogic QuLogic added this to the v2.2 milestone Feb 6, 2018
@QuLogic
Copy link
Member Author

QuLogic commented Feb 6, 2018

There are also a few warnings about tight_layout which I don't know how to fix; maybe @jklymak has an idea.

@QuLogic QuLogic force-pushed the example-deprecations branch from 62a7788 to c4197df Compare February 6, 2018 07:07
datafile = cbook.get_sample_data('msft.csv', asfileobj=False)
print('loading %s' % datafile)
r = csv2rec(datafile)[-40:]
r = np.genfromtxt(datafile, delimiter=',', names=True,
Copy link
Member

Choose a reason for hiding this comment

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

Maybe use a more telling name like msft_data instead of r?

@jklymak
Copy link
Member

jklymak commented Feb 6, 2018

Oh, hmmm, that should give a warning, but for constrained layout, not tight layout! Ooops..

lib/matplotlib/tests/test_constrainedlayout.py::test_constrained_layout7[png]
  /home/travis/build/matplotlib/matplotlib/lib/matplotlib/figure.py:2269: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
    warnings.warn("This figure includes Axes that are not compatible "

@QuLogic
Copy link
Member Author

QuLogic commented Feb 6, 2018

@jklymak Actually, I was referring to the examples, not the tests. For example,

generating gallery for gallery/lines_bars_and_markers... [ 97%] markevery_demo.py
/home/circleci/project/lib/matplotlib/figure.py:2269: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
  warnings.warn("This figure includes Axes that are not compatible "
generating gallery for tutorials/intermediate... [ 83%] tight_layout_guide.py
/home/circleci/project/lib/matplotlib/gridspec.py:316: UserWarning: This figure includes Axes that are not compatible with tight_layout, so results might be incorrect.
  warnings.warn("This figure includes Axes that are not compatible "
generating gallery for tutorials/intermediate... [100%] constrainedlayout_guide.py
/home/circleci/project/lib/matplotlib/figure.py:2224: UserWarning: Calling figure.constrained_layout, but figure not setup to do constrained layout.     You either called GridSpec without the fig keyword, you are using plt.subplot, or you need to call figure or subplotswith the constrained_layout=True kwarg.
  warnings.warn("Calling figure.constrained_layout, but figure "

@QuLogic QuLogic force-pushed the example-deprecations branch from c4197df to 5193922 Compare February 6, 2018 22:44
@jklymak
Copy link
Member

jklymak commented Feb 6, 2018

The last one is mine, and on purpose to show the failure in the tutorial.

The tight_layout example is similar, showing that tight_layout doesn't work and emits a warning for colorbars created outside of gridspec. Not sure about the first one.

@QuLogic QuLogic added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Feb 8, 2018
@@ -2411,8 +2411,11 @@ def plotfile(fname, cols=(0,), plotfuncs=None,

if plotfuncs is None:
plotfuncs = dict()
r = mlab.csv2rec(fname, comments=comments, skiprows=skiprows,
checkrows=checkrows, delimiter=delimiter, names=names)
from matplotlib.cbook import mplDeprecation
Copy link
Member

Choose a reason for hiding this comment

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

Should this whole method be deprecated since it depends on csv2rec?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, and point people at pandas.

Copy link
Member Author

Choose a reason for hiding this comment

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

You want to deprecate plt.plotfile for Pandas? Probably should be an independent PR.

@tacaswell tacaswell merged commit 83d614b into matplotlib:master Feb 9, 2018
@QuLogic QuLogic deleted the example-deprecations branch February 9, 2018 22:26
@QuLogic QuLogic modified the milestones: needs sorting, v2.2.0 Feb 12, 2018
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.

5 participants