Skip to content

FIX: catch warnings from pandas in cbook._check_1d #16347

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
Jan 28, 2020

Conversation

tacaswell
Copy link
Member

@tacaswell tacaswell commented Jan 27, 2020

If we catch the warning or the exception, we need to cast to numpy
because later on in _plot_args we again use multi-dimensional
indexing to up-cast to a 2D array.

closes #16295

PR Summary

PR Checklist

  • Has Pytest style unit tests
  • Code is Flake 8 compliant

with warnings.catch_warnings() as w:
warnings.filterwarnings("ignore",
category=DeprecationWarning,
module='pandas[.*]')
Copy link
Contributor

Choose a reason for hiding this comment

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

does this mean we're just kicking the can down the road and will need yet another fix when pandas actually change this behavior?

Copy link
Member Author

Choose a reason for hiding this comment

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

The change will be to raise one of the Exceptions we already catch below so we will still be happy.

Copy link
Contributor

Choose a reason for hiding this comment

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

fair enough

If we catch the warning or the exception, we need to cast to numpy
because later on in `_plot_args` we again use multi-dimensional
indexing to up-cast to a 2D array.

closes matplotlib#16295
@tacaswell tacaswell force-pushed the fix_pandas_index_deprecation branch from ae4354c to c7eddd6 Compare January 27, 2020 23:33
@tacaswell tacaswell added this to the v2.2.5 milestone Jan 27, 2020
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Jan 28, 2020
@tacaswell
Copy link
Member Author

@bashtage However on older versions we are not getting back a numpy array

In [1]: import pandas as pd                                                                                                                                                                                                                                   

In [2]: d = pd.Series([])                                                                                                                                                                                                                                     

In [3]: d.index[:, None]                                                                                                                                                                                                                                      
Out[3]: Int64Index([], dtype='int64')

In [4]: type(d.index[:, None])                                                                                                                                                                                                                                
Out[4]: pandas.core.indexes.numeric.Int64Index

In [5]: d.index[:, None].ndim                                                                                                                                                                                                                                 
Out[5]: 1

In [6]: pd.__version__                                                                                                                                                                                                                                        
Out[6]: '0.25.1'

Comment on lines 1372 to 1373
# was an unintentional quirk of pandas the above line will raise
# an exception in the future.
Copy link
Member

Choose a reason for hiding this comment

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

since the above line is getting deleted, this comment is no longer relevant.

Copy link
Member Author

Choose a reason for hiding this comment

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

It is still relevant, the line above was moved down and put inside the context manager below.

Copy link
Member

@story645 story645 Jan 28, 2020

Choose a reason for hiding this comment

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

Ok, then it should be changed to "the line below" or moved to be next to the line it's referring to:

 ndim = x[:, None].ndim  #will raise exception in future

@tacaswell tacaswell requested a review from story645 January 28, 2020 21:07
@jklymak jklymak merged commit a7501f9 into matplotlib:master Jan 28, 2020
@lumberbot-app
Copy link

lumberbot-app bot commented Jan 28, 2020

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v2.2.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 a7501f94988b952bd97a7b382b86c924cf464f62
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #16347: FIX: catch warnings from pandas in cbook._check_1d'
  1. Push to a named branch :
git push YOURFORK v2.2.x:auto-backport-of-pr-16347-on-v2.2.x
  1. Create a PR against branch v2.2.x, I would have named this PR:

"Backport PR #16347 on branch v2.2.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

@lumberbot-app
Copy link

lumberbot-app bot commented Jan 28, 2020

Owee, I'm MrMeeseeks, Look at me.

There seem to be a conflict, please backport manually. Here are approximate instructions:

  1. Checkout backport branch and update it.
$ git checkout v3.1.x
$ git pull
  1. Cherry pick the first parent branch of the this PR on top of the older branch:
$ git cherry-pick -m1 a7501f94988b952bd97a7b382b86c924cf464f62
  1. You will likely have some merge/cherry-pick conflict here, fix them and commit:
$ git commit -am 'Backport PR #16347: FIX: catch warnings from pandas in cbook._check_1d'
  1. Push to a named branch :
git push YOURFORK v3.1.x:auto-backport-of-pr-16347-on-v3.1.x
  1. Create a PR against branch v3.1.x, I would have named this PR:

"Backport PR #16347 on branch v3.1.x"

And apply the correct labels and milestones.

Congratulation you did some good work ! Hopefully your backport PR will be tested by the continuous integration and merged soon!

If these instruction are inaccurate, feel free to suggest an improvement.

meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Jan 28, 2020
@tacaswell tacaswell deleted the fix_pandas_index_deprecation branch January 28, 2020 23:22
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Jan 28, 2020
…k._check_1d

Merge pull request matplotlib#16347 from tacaswell/fix_pandas_index_deprecation

FIX: catch warnings from pandas in cbook._check_1d
 Conflicts:
	lib/matplotlib/tests/test_axes.py
         - new test in middle of section of tests not on v2.2.x yet, only kept
           new test
tacaswell pushed a commit to tacaswell/matplotlib that referenced this pull request Jan 28, 2020
…k._check_1d

Merge pull request matplotlib#16347 from tacaswell/fix_pandas_index_deprecation

FIX: catch warnings from pandas in cbook._check_1d
tacaswell added a commit that referenced this pull request Jan 29, 2020
…347-on-v3.2.x

Backport PR #16347 on branch v3.2.x (FIX: catch warnings from pandas in cbook._check_1d)
timhoffm added a commit that referenced this pull request Jan 29, 2020
…-v3.1.x

Backport PR #16347: FIX: catch warnings from pandas in cbook._check_1d
timhoffm added a commit that referenced this pull request Jan 29, 2020
…-v2.2.x

Backport PR #16347: FIX: catch warnings from pandas in cbook._check_1d
@jklymak
Copy link
Member

jklymak commented Jan 30, 2020

So, test_bar_pandas is still failing, at least w/ #16286 which I rebased, so it should include this fix?

@jklymak
Copy link
Member

jklymak commented Jan 30, 2020

I guess because pandas 1.0 is out?

@jklymak
Copy link
Member

jklymak commented Jan 30, 2020

I actually don't understand. The warning is from pandas 1.0 (old pandas pass this test) and the result is:

E           DeprecationWarning: Support for multi-dimensional indexing (e.g. `index[:, None]`) on an Index is deprecated and will be removed in a future version.  Convert to a numpy array before indexing instead.

So somehow we are no longer capturing the warning.

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.

pyplot.plot using pandas series raises DeprecationWarning with pandas=1.0.0rc0
6 participants