Skip to content

error checking should be performed as early as possible (here: non-ASCII str's in e.g. ylabel()) #2560

Closed

Description

@hmeine

When using set_ylabel('Täst') in the ipython notebook, there will not be any plot, but also no error message visible. The real problem is that the notebook does not show exceptions that happen in draw(), but also in the console ipython, an exception raised by set_ylabel() itself would be rendered much better than the one coming asynchroneously from draw().

If possible, an exception like this one:

  File "/usr/lib/pymodules/python2.7/matplotlib/cbook.py", line 1797, in is_math_text
    "matplotlib display text must have all code points < 128 or use "
ValueError: matplotlib display text must have all code points < 128 or use Unicode strings

should already be raised in the Text() constructor (or whereever appropriate).

Activity

  1. hmeine commented on Oct 30, 2013

    @hmeine
    ContributorAuthor

    ipython/ipython#3922 is related, but I would like to see this tackled in MPL, too.

  2. mdboom commented on Oct 30, 2013

    @mdboom
    Member

    MEP13 is related to this.

  3. hmeine commented on Oct 30, 2013

    @hmeine
    ContributorAuthor

    MEP13 is about using properties; I guess you meant MEP14 ("… improving the text handling …"):
    https://github.com/matplotlib/matplotlib/wiki/Mep14

  4. mdboom commented on Oct 30, 2013

    @mdboom
    Member

    Nope -- by using properties as in MEP13, we will be performing error checking of values much earlier than we are now.

  5. hmeine commented on Oct 30, 2013

    @hmeine
    ContributorAuthor

    I considered that interpretation, too, but properties would just be a syntactic change, no? I mean - the same check could be in the setter today?!

    If you want to introduce something like traits, that'd be something different, but MEP13 did not seem to discuss traits, but just the leaving-out-the-parentheses part?

  6. mdboom commented on Oct 30, 2013

    @mdboom
    Member

    That's true -- I just meant to link this issue as one of many that we have that would benefit from more consistent use of setters/properties/traits. You're right that the underlying technology barely matters -- it's a matter of checking in a single place as early as possible.

  7. added this to the milestone on Aug 17, 2014
  8. petehuang commented on Jan 6, 2017

    @petehuang
    Contributor

    What's the exact action for MPL for this issue?

  9. WeatherGod commented on Jan 6, 2017

    @WeatherGod
    Member
  10. petehuang commented on Jan 6, 2017

    @petehuang
    Contributor

    For visitor reference, traitlets discussion/work sitting in #4762.

    Guess we can leave this open (...ugh) but need to remember to come back to this once traitlets work is complete

  11. anntzer commented on Aug 31, 2017

    @anntzer
    Contributor

    set_ylabel raises an exception now

    $ python2 -c 'from pylab import *; gca().set_ylabel("Täst")'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/usr/lib/python2.7/site-packages/matplotlib/axes/_axes.py", line 254, in set_ylabel
        return self.yaxis.set_label_text(ylabel, fontdict, **kwargs)
      File "/usr/lib/python2.7/site-packages/matplotlib/axis.py", line 1505, in set_label_text
        self.label.set_text(label)
      File "/usr/lib/python2.7/site-packages/matplotlib/text.py", line 1212, in set_text
        self._text = '%s' % (s,)
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 1: ordinal not in range(128)
    

    so closing (unless I'm mistaken?). The traitlets work is tracked in a number of other issues.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions