FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Warning treated as error while generating docs · Issue #8145 · matplotlib/matplotlib · GitHub

Repository navigation

Warning treated as error while generating docs #8145

Closed

Description

Bug report

Bug summary

I get the following WARNING while generating docs.

Warning, treated as error:
/home/aashil/github/matplotlib/doc/api/_as_gen/matplotlib.axes.Axes.clabel.rst:83: WARNING: Exception occurred in plotting contour_demo
 from /home/aashil/github/matplotlib/doc/mpl_examples/pylab_examples/contour_demo.py:
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-2.0.0+3486.g8c57dae-py2.7-linux-x86_64.egg/matplotlib/sphinxext/plot_directive.py", line 525, in run_code
    six.exec_(code, ns)
  File "/usr/local/lib/python2.7/dist-packages/six.py", line 699, in exec_
    exec("""exec _code_ in _globs_, _locs_""")
  File "<string>", line 1, in <module>
  File "<string>", line 55, in <module>
  File "/usr/local/lib/python2.7/dist-packages/matplotlib-2.0.0+3486.g8c57dae-py2.7-linux-x86_64.egg/matplotlib/__init__.py", line 916, in __setitem__
    raise ValueError("Key %s: %s" % (key, str(ve)))
ValueError: Key contour.negative_linestyle: linestyle must be a string or an even-length sequence of floats.

Building HTML failed.

The command from contour_demo.py which throws the warning is:

CS = plt.contour(Z, levels,
                 origin='lower',
                 linewidths=2,
                 extent=(-3, 3, -2, 2))

I think it's expecting positive values for extent.

Code for reproduction

  • A minimum code snippet required to reproduce the bug, also minimizing the number of dependencies required
python make.py html

Matplotlib version

  • Matplotlib version 2.0.0+3486.g8c57dae, Python version 2.7.12 and Platform (Ubuntu 16.04)
  • I built Matplotlib from sources and python came pre-installed with Ubuntu 16.04

Activity

  1. afvincent commented on Feb 25, 2017

    Contributor

    Thank you @aashil for reporting this issue.

    With the vanilla line 55 in contour.py (i.e. matplotlib.rcParams['contour.negative_linestyle'] = 'solid'), the same ValueError exception is raised when executing the script outside of building the documentation. This exception is related to the new validation scheme for line styles, see #8040. Using u'solid' instead of 'solid' makes the exception to disappear.

    @tacaswell Is it expected for such an exception to be uncaught during the CI tests?

  2. added this to the milestone on Feb 25, 2017
  3. tacaswell commented on Feb 26, 2017

    Member

    We build the docs on py3 so it reasonable that we missed this.

    I think this is a unicode bug in the recently merged dash-pattern validator.

  4. afvincent commented on Feb 26, 2017

    Contributor

    @tacaswell It looks like you are right. With Python 2.7:

    In [1]: from matplotlib.rcsetup import _validate_linestyle
    
    In [2]: _validate_linestyle(u'solid')
    Out[2]: u'solid'
    
    In [3]: _validate_linestyle('solid')
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-3-9192256a512f> in <module>()
    ----> 1 _validate_linestyle('solid')
    
    /home/adrien/matplotlib-git/lib/matplotlib/rcsetup.pyc in _validate_linestyle(ls)
        928 
        929     raise ValueError("linestyle must be a string or " +
    --> 930                      "an even-length sequence of floats.")
        931 
        932 
    
    ValueError: linestyle must be a string or an even-length sequence of floats.
  5. afvincent commented on Feb 26, 2017

    Contributor

    In _validate_linestyle(ls), should I use something like:

        ...
        if isinstance(ls, six.text_type):
            return _validate_named_linestyle(ls.decode())
        ...

    to make sure that we pass a unicode (string) argument? Or should this kind of conversion be handled differently?

  6. tacaswell commented on Feb 26, 2017

    Member

    calling decode like that is not safe as if you are getting in a byte string you don't know what encoding it has. Further, in python 3 that will error because str has no method 'decode' (that is a bytes method).

    I do not fully understand what is going on here though.

    Python 2.7.13 (default, Dec 21 2016, 07:16:46) 
    Type "copyright", "credits" or "license" for more information.
    
    IPython 5.1.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.
    
    In [1]: d = {'foo': 1, u'foo': 2}
    
    In [2]: d
    Out[2]: {'foo': 2}
    
    In [3]: d = {u'foo': 5}
    
    In [4]: 'foo' in d
    Out[4]: True
    
    In [5]: 
    
    
  7. self-assigned this
    on Feb 27, 2017
  8. afvincent commented on Feb 27, 2017

    Contributor

    @tacaswell If one trusts SO, it is the expected behavior with Python 2, which “handles translation between str and unicode keys transparently for you, provided the text can be encoded to ASCII.” See for example here and there.

    About the reported issue here, I think the problem may be due to the test

    if isinstance(ls, six.text_type):

    in the _validate_linestyle function:

    Python 2.7.11 |Continuum Analytics, Inc.| (default, Dec  6 2015, 18:08:32) 
    [...]
    
    In [1]: from matplotlib.rcsetup import _validate_named_linestyle, _validate_linestyle
    
    In [2]: import six
    
    In [3]: _validate_named_linestyle('solid')  # No problem with a valid ASCII string
    Out[3]: u'solid'
    
    In [4]: _validate_linestyle('solid')  # Error with a valid ASCII string
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    <ipython-input-4-9192256a512f> in <module>()
    ----> 1 _validate_linestyle('solid')
    
    /home/adrien/matplotlib-git/matplotlib/lib/matplotlib/rcsetup.pyc in _validate_linestyle(ls)
        928 
        929     raise ValueError("linestyle must be a string or " +
    --> 930                      "an even-length sequence of floats.")
        931 
        932 
    
    ValueError: linestyle must be a string or an even-length sequence of floats.
    
    In [5]: isinstance('solid', six.text_type)  # => issue w/ the aforementioned test...
    Out[5]: False
    
    In [6]: isinstance(u'solid', six.text_type)  # => expected behavior
    Out[6]: True

    I used six.text_type in the current version of _validate_linestyle because it was what was used for what seemed to be similar comparisons to me in rcsetup.py, but maybe the if isinstance(ls, …) should test against six.string_types instead of six.text_type:

    from __future__ import print_function
    
    import six
    from matplotlib.rcsetup import _validate_named_linestyle
    
    
    def _validate_linestyle(ls):
        """
        A validator for all possible line styles, the named ones *and*
        the on-off ink sequences.
        """
        # Named line style, like u'--' or u'solid'
        if isinstance(ls, six.string_types):  # <= Here is the change!
            return _validate_named_linestyle(ls)
    
        # On-off ink (in points) sequence *of even length*.
        # Offset is set to None.
        try:
            if len(ls) % 2 != 0:
                # Expecting a sequence of even length
                raise ValueError
            return (None, validate_nseq_float()(ls))
        except (ValueError, TypeError):
            # TypeError can be raised by wrong types passed to float()
            # (called inside the instance of validate_nseq_float).
            pass
    
        raise ValueError("linestyle must be a string or " +
                         "an even-length sequence of floats.")
    
    # Testing different types of strings for the same valid name of line style.
    validated_strings = []
    
    for ls in ['solid', u'solid', bytes('solid')]:
        validated_strings.append(_validate_linestyle(ls))
    
    print(validated_strings)  # => [u'solid', u'solid', u'solid']
  9. tacaswell commented on Feb 27, 2017

    Member

    Or skip the type checking and just do

    try:
        return _validate_named_linestyle(ls)
    except KeyError:
        pass
  10. afvincent commented on Feb 27, 2017

    Contributor

    Indeed ^^. I am going to open a PR to fix the issue as you suggest.

  11. afvincent commented on Feb 27, 2017

    Contributor

    With the PR #8165, I was able to locally build the documentation under Python 2.7.

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


    Back | FazBrowse Home | New Git URL