Skip to content

fix a warning when the aspect is a number #6279

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

Closed
wants to merge 2 commits into from
Closed

Conversation

kkdd
Copy link

@kkdd kkdd commented Apr 7, 2016

This PR fixes the following warning when using plt.axes().set_aspect(1):

/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.py:1215: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  if aspect == 'normal':
/usr/local/lib/python2.7/site-packages/matplotlib/axes/_base.py:1220: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
  elif aspect in ('equal', 'auto'):

@mdboom mdboom changed the title fix a warning when the aspect is a number fix a warning when the aspect is a number Apr 7, 2016
'1.2', name='normal', alternative='auto', obj_type='aspect')
self._aspect = 'auto'
else:
raise ValueError("error in aspect")
Copy link
Member

Choose a reason for hiding this comment

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

Needs a better error message, but otherwise, this makes sense to me.

@jenshnielsen
Copy link
Member

We don't see that warning in the tests. That probably means that there is no tests with aspect as a number. It would be good to add such a test

@QuLogic
Copy link
Member

QuLogic commented Apr 7, 2016

Please reword your commit messages so that they indicate what you're actually doing instead of a generic "Update filename".

@tacaswell
Copy link
Member

I can not get this warning locally

In [47]: import matplotlib.pyplot as plt

In [48]: plt.axes().set_aspect(1)

In [49]: 

@tacaswell
Copy link
Member

It looks like this is a python2 only issue and just a warning.

@tacaswell tacaswell added this to the unassigned milestone Apr 8, 2016
@tacaswell
Copy link
Member

I am 👎 on merging this.

@WeatherGod
Copy link
Member

how about a warning filter instead?

On Fri, Apr 8, 2016 at 12:10 AM, Thomas A Caswell notifications@github.com
wrote:

I am [image: 👎] on merging this.


You are receiving this because you commented.
Reply to this email directly or view it on GitHub
#6279 (comment)

@kkdd
Copy link
Author

kkdd commented Apr 9, 2016

Sorry. plt.axes().set_aspect(1) doesn't raise the unicodewarnings, but plt.axes().set_aspect(np.float64(1)) and plt.axes().set_aspect(scipy.sqrt(1)) do.

@kkdd
Copy link
Author

kkdd commented Apr 9, 2016

It seems to be a side effect of from __future__ import unicode_literals, observed as follows:

$ python -c "from __future__ import unicode_literals;import numpy;print numpy.float64(1) == 'normal'"
-c:1: UnicodeWarning: Unicode equal comparison failed to convert both arguments to Unicode - interpreting them as being unequal
False
$ python
Python 2.7.11 (default, Dec  5 2015, 22:44:43) 
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

@jenshnielsen
Copy link
Member

It will happen when ever you try to compare a numpy type to a unicode string. I.e. import numpy;print numpy.float64(1) == u'normal' also produces the warning.
One possbile way around it could be to verify that the aspect is a string before doing the comparison i.e. replace:
if aspect == 'normal':
with:
if isinstance(aspect, six.string_types) and aspect == 'normal':

it's not the cleanest and goes breaks normal python ducktypeing but gets the python2 behaviour closer to the python3 one.

@anntzer
Copy link
Contributor

anntzer commented Mar 1, 2017

Closed by #7658.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants