Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix a number of Deprecated/Invalid escape sequences #7925

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 2 commits into from
Feb 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/matplotlib/axes/_axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -6718,7 +6718,7 @@ def csd(self, x, y, NFFT=None, Fs=None, Fc=None, detrend=None,
Notes
-----
For plotting, the power is plotted as
:math:`10\log_{10}(P_{xy})` for decibels, though `P_{xy}` itself
:math:`10\\log_{10}(P_{xy})` for decibels, though `P_{xy}` itself
is returned.

References
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/backends/backend_ps.py
Original file line number Diff line number Diff line change
Expand Up @@ -1568,7 +1568,7 @@ def xpdf_distill(tmpfile, eps=False, ptype='letter', bbox=None, rotated=False):
with io.open(outfile, 'rb') as fh:
if exit_status:
raise RuntimeError('ps2pdf was not able to process your \
image.\n\Here is the report generated by ghostscript:\n\n' + fh.read())
image.\nHere is the report generated by ghostscript:\n\n' + fh.read())
else:
verbose.report(fh.read(), 'debug')
os.remove(outfile)
Expand Down
10 changes: 5 additions & 5 deletions lib/matplotlib/cbook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,8 @@ def disconnect(self, cid):

def process(self, s, *args, **kwargs):
"""
process signal *s*. All of the functions registered to receive
callbacks on *s* will be called with *\*args* and *\*\*kwargs*
process signal `s`. All of the functions registered to receive
callbacks on `s` will be called with ``**args`` and ``**kwargs``
"""
if s in self.callbacks:
for cid, proxy in list(six.iteritems(self.callbacks[s])):
Expand Down Expand Up @@ -944,7 +944,7 @@ def wrap(prefix, text, cols):
# A regular expression used to determine the amount of space to
# remove. It looks for the first sequence of spaces immediately
# following the first newline, or at the beginning of the string.
_find_dedent_regex = re.compile("(?:(?:\n\r?)|^)( *)\S")
_find_dedent_regex = re.compile(r"(?:(?:\n\r?)|^)( *)\S")
# A cache to hold the regexs that actually remove the indent.
_dedent_regex = {}

Expand Down Expand Up @@ -1722,7 +1722,7 @@ def boxplot_stats(X, whis=1.5, bootstrap=None, labels=None,

.. math::

\mathrm{med} \pm 1.57 \\times \\frac{\mathrm{iqr}}{\sqrt{N}}
\\mathrm{med} \\pm 1.57 \\times \\frac{\\mathrm{iqr}}{\\sqrt{N}}

General approach from:
McGill, R., Tukey, J.W., and Larsen, W.A. (1978) "Variations of
Expand Down Expand Up @@ -2709,7 +2709,7 @@ def is_bounded_0_1(self):
def _get_key_params(self):
str_func = self._str_func
# Checking if it comes with parameters
regex = '\{(.*?)\}'
regex = r'\{(.*?)\}'
params = re.findall(regex, str_func)

for i, param in enumerate(params):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ def get_urls(self):
return self._urls

def set_hatch(self, hatch):
"""
r"""
Set the hatching pattern

*hatch* can be one of::
Expand All @@ -415,7 +415,7 @@ def set_hatch(self, hatch):
can only be specified for the collection as a whole, not separately
for each member.

ACCEPTS: [ '/' | '\\\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | '*' ]
ACCEPTS: [ '/' | '\\' | '|' | '-' | '+' | 'x' | 'o' | 'O' | '.' | '*' ]
Copy link
Member

Choose a reason for hiding this comment

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

It appears that this line is under 79 characters and this file now passes PEP8, so it needs to be removed from lib/matplotlib/tests/test_coding_standards.py because the build is failing.

Copy link
Member

Choose a reason for hiding this comment

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

Also, since you're going to have to push an update, I cancelled the OSX build which has been waiting for a while because we've got a long backlog.

"""
self._hatch = hatch
self.stale = True
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ def to_hex(c, keep_alpha=False):
### Backwards-compatible color-conversion API

cnames = CSS4_COLORS
hexColorPattern = re.compile("\A#[a-fA-F0-9]{6}\Z")
hexColorPattern = re.compile(r"\A#[a-fA-F0-9]{6}\Z")


def rgb2hex(c):
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/dviread.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ def _height_depth_of(self, char):

class Vf(Dvi):
"""
A virtual font (\*.vf file) containing subroutines for dvi files.
A virtual font (\\*.vf file) containing subroutines for dvi files.

Usage::

Expand Down Expand Up @@ -899,7 +899,7 @@ def _register(self, words):

class Encoding(object):
"""
Parses a \*.enc file referenced from a psfonts.map style file.
Parses a \\*.enc file referenced from a psfonts.map style file.
The format this class understands is a very limited subset of
PostScript.

Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/font_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def win32FontDirectory():
Return the user-specified font directory for Win32. This is
looked up from the registry key::

\\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders\Fonts
\\\\HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders\\Fonts

If the key is not found, $WINDIR/Fonts will be returned.
"""
Expand Down
38 changes: 19 additions & 19 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def get_unicode_index(symbol, math=True):
"""get_unicode_index(symbol, [bool]) -> integer

Return the integer index (from the Unicode table) of symbol. *symbol*
can be a single unicode character, a TeX command (i.e. r'\pi'), or a
can be a single unicode character, a TeX command (i.e. r'\\pi'), or a
Type1 symbol name (i.e. 'phi').
If math is False, the current symbol should be treated as a non-math symbol.
"""
Expand Down Expand Up @@ -430,7 +430,7 @@ def get_kern(self, font1, fontclass1, sym1, fontsize1,

*fontclassX*: TODO

*symX*: a symbol in raw TeX form. e.g., '1', 'x' or '\sigma'
*symX*: a symbol in raw TeX form. e.g., '1', 'x' or '\\sigma'

*fontsizeX*: the fontsize in points

Expand All @@ -446,7 +446,7 @@ def get_metrics(self, font, font_class, sym, fontsize, dpi, math=True):

*font_class*: TODO

*sym*: a symbol in raw TeX form. e.g., '1', 'x' or '\sigma'
*sym*: a symbol in raw TeX form. e.g., '1', 'x' or '\\sigma'

*fontsize*: font size in points

Expand Down Expand Up @@ -749,12 +749,12 @@ def _get_glyph(self, fontname, font_class, sym, fontsize, math=True):
r'>' : [('cal', 'i'), ('ex', 'E')]
}

for alias, target in [('\leftparen', '('),
('\rightparent', ')'),
('\leftbrace', '{'),
('\rightbrace', '}'),
('\leftbracket', '['),
('\rightbracket', ']'),
for alias, target in [(r'\leftparen', '('),
(r'\rightparent', ')'),
(r'\leftbrace', '{'),
(r'\rightbrace', '}'),
(r'\leftbracket', '['),
(r'\rightbracket', ']'),
(r'\{', '{'),
(r'\}', '}'),
(r'\[', '['),
Expand Down Expand Up @@ -1034,7 +1034,7 @@ def _map_virtual_font(self, fontname, font_class, uniindex):

_size_alternatives = {}
def get_sized_alternatives_for_symbol(self, fontname, sym):
fixes = {'\{': '{', '\}': '}', '\[': '[', '\]': ']'}
fixes = {'\\{': '{', '\\}': '}', '\\[': '[', '\\]': ']'}
sym = fixes.get(sym, sym)

alternatives = self._size_alternatives.get(sym)
Expand Down Expand Up @@ -2425,20 +2425,20 @@ def __init__(self):
Suppress(Literal(r"\sqrt"))
- ((Optional(p.lbracket + p.int_literal + p.rbracket, default=None)
+ p.required_group)
| Error("Expected \sqrt{value}"))
| Error("Expected \\sqrt{value}"))
)

p.overline <<= Group(
Suppress(Literal(r"\overline"))
- (p.required_group | Error("Expected \overline{value}"))
- (p.required_group | Error("Expected \\overline{value}"))
)

p.unknown_symbol<<= Combine(p.bslash + Regex("[A-Za-z]*"))

p.operatorname <<= Group(
Suppress(Literal(r"\operatorname"))
- ((p.lbrace + ZeroOrMore(p.simple | p.unknown_symbol) + p.rbrace)
| Error("Expected \operatorname{value}"))
| Error("Expected \\operatorname{value}"))
)

p.placeable <<= ( p.snowflake # this needs to be before accent so named symbols
Expand Down Expand Up @@ -2693,7 +2693,7 @@ def unknown_symbol(self, s, loc, toks):
# The first 2 entires in the tuple are (font, char, sizescale) for
# the two symbols under and over. The third element is the space
# (in multiples of underline height)
r'AA' : ( ('it', 'A', 1.0), (None, '\circ', 0.5), 0.0),
r'AA': (('it', 'A', 1.0), (None, '\\circ', 0.5), 0.0),
}

def c_over_c(self, s, loc, toks):
Expand Down Expand Up @@ -2918,7 +2918,7 @@ def subsuper(self, s, loc, toks):
if super is None:
super = Hlist([])
for i in range(napostrophes):
super.children.extend(self.symbol(s, loc, ['\prime']))
super.children.extend(self.symbol(s, loc, ['\\prime']))
# kern() and hpack() needed to get the metrics right after extending
super.kern()
super.hpack()
Expand Down Expand Up @@ -3291,7 +3291,7 @@ def parse(self, s, dpi = 72, prop = None):
def to_mask(self, texstr, dpi=120, fontsize=14):
"""
*texstr*
A valid mathtext string, e.g., r'IQ: $\sigma_i=15$'
A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'

*dpi*
The dots-per-inch to render the text
Expand All @@ -3317,7 +3317,7 @@ def to_mask(self, texstr, dpi=120, fontsize=14):
def to_rgba(self, texstr, color='black', dpi=120, fontsize=14):
"""
*texstr*
A valid mathtext string, e.g., r'IQ: $\sigma_i=15$'
A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'

*color*
Any matplotlib color argument
Expand Down Expand Up @@ -3357,7 +3357,7 @@ def to_png(self, filename, texstr, color='black', dpi=120, fontsize=14):
A writable filename or fileobject

*texstr*
A valid mathtext string, e.g., r'IQ: $\sigma_i=15$'
A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'

*color*
A valid matplotlib color argument
Expand All @@ -3381,7 +3381,7 @@ def get_depth(self, texstr, dpi=120, fontsize=14):
image in pixels.

*texstr*
A valid mathtext string, e.g., r'IQ: $\sigma_i=15$'
A valid mathtext string, e.g., r'IQ: $\\sigma_i=15$'

*dpi*
The dots-per-inch to render the text
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/mlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2191,7 +2191,7 @@ def identity(n, rank=2, dtype='l', typecode=None):

/ 1 if i0=i1=...=iR,
id[i0,i1,...,iR] = -|
\ 0 otherwise.
\\ 0 otherwise.

Optionally a *dtype* (or typecode) may be given (it defaults to 'l').

Expand Down Expand Up @@ -2869,7 +2869,7 @@ def get_converters(reader, comments):
break

# remove these chars
delete = set("""~!@#$%^&*()-=+~\|]}[{';: /?.>,<""")
delete = set(r"""~!@#$%^&*()-=+~\|]}[{';: /?.>,<""")
delete.add('"')

names = []
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ def set_hatch(self, hatch):
*hatch* can be one of::

/ - diagonal hatching
\ - back diagonal
\\ - back diagonal
| - vertical
- - horizontal
+ - crossed
Expand Down
3 changes: 2 additions & 1 deletion lib/matplotlib/quiver.py
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,8 @@ def _h_arrows(self, length):

quiver_doc = _quiver_doc

_barbs_doc = """

_barbs_doc = r"""
Plot a 2-D field of barbs.

Call signatures::
Expand Down
7 changes: 3 additions & 4 deletions lib/matplotlib/tests/test_backend_svg.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,14 @@ def _test_determinism_save(filename, usetex):
a, b, c = ax.errorbar(x, y, yerr=yerr, fmt='ko')
for artist in b:
artist.set_visible(False)
ax.set_title('A string $1+2+\sigma$')
ax.set_xlabel('A string $1+2+\sigma$')
ax.set_ylabel('A string $1+2+\sigma$')
ax.set_title('A string $1+2+\\sigma$')
ax.set_xlabel('A string $1+2+\\sigma$')
ax.set_ylabel('A string $1+2+\\sigma$')

FigureCanvasSVG(fig).print_svg(filename)


def _test_determinism(filename, usetex):
import os
import sys
from subprocess import check_output, STDOUT, CalledProcessError
plots = []
Expand Down
1 change: 0 additions & 1 deletion lib/matplotlib/tests/test_coding_standards.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,6 @@ def test_pep8_conformance_installed_files():
expected_bad_files = ['_cm.py',
'_mathtext_data.py',
'backend_bases.py',
'collections.py',
'font_manager.py',
'fontconfig_pattern.py',
'gridspec.py',
Expand Down
2 changes: 1 addition & 1 deletion lib/matplotlib/tests/test_subplots.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_exceptions():
# the point of this test is to ensure that this raises.
with warnings.catch_warnings():
warnings.filterwarnings('ignore',
message='.*sharex\ argument\ to\ subplots',
message='.*sharex argument to subplots',
category=UserWarning)
with pytest.raises(ValueError):
plt.subplots(2, 2, -1)
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/tests/test_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def find_matplotlib_font(**kw):
from matplotlib.font_manager import FontProperties, findfont
warnings.filterwarnings(
'ignore',
('findfont: Font family \[u?\'Foo\'\] not found. Falling back to .'),
"findfont: Font family \[u?'Foo'\] not found. Falling back to .",
UserWarning,
module='matplotlib.font_manager')

Expand Down Expand Up @@ -135,7 +135,7 @@ def test_antialiasing():
fig = plt.figure(figsize=(5.25, 0.75))
fig.text(0.5, 0.75, "antialiased", horizontalalignment='center',
verticalalignment='center')
fig.text(0.5, 0.25, "$\sqrt{x}$", horizontalalignment='center',
fig.text(0.5, 0.25, r"$\sqrt{x}$", horizontalalignment='center',
verticalalignment='center')
# NOTE: We don't need to restore the rcParams here, because the
# test cleanup will do it for us. In fact, if we do it here, it
Expand Down
6 changes: 3 additions & 3 deletions lib/matplotlib/texmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
Requirements:

* latex
* \*Agg backends: dvipng
* \\*Agg backends: dvipng
* PS backend: latex w/ psfrag, dvips, and Ghostscript 8.51
(older versions do not work properly)

Backends:

* \*Agg
* \\*Agg
* PS
* PDF

Expand All @@ -22,7 +22,7 @@

texmanager = TexManager()
s = ('\\TeX\\ is Number '
'$\\displaystyle\\sum_{n=1}^\\infty\\frac{-e^{i\pi}}{2^n}$!')
'$\\displaystyle\\sum_{n=1}^\\infty\\frac{-e^{i\\pi}}{2^n}$!')
Z = self.texmanager.get_rgba(s, size=12, dpi=80, rgb=(1,0,0))

To enable tex rendering of all text in your matplotlib figure, set
Expand Down
22 changes: 22 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,28 @@


if __name__ == '__main__':

try:
import setuptools
except ImportError:
pass

# The warnings need to be before any of matplotlib imports, but after
# setuptools (if present) which has syntax error with the warnings enabled.
# Filtering by module does not work as this will be raised by Python itself.
# so `module=matplotlib.*` is out of questions.

import warnings

# Python 3.6 deprecate invalid character-pairs \A, \* ... in non raw-strings
# and other things. Let's not re-introduce them
warnings.filterwarnings('error', '.*invalid escape sequence.*',
category=DeprecationWarning)
warnings.filterwarnings(
'default',
'.*inspect.getargspec\(\) is deprecated.*',
category=DeprecationWarning)

Copy link
Member

Choose a reason for hiding this comment

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

This only gets executed when running tests.py, and I think most tests have been migrated to pytest now. Is there a way to make pytest execute these filterwarnings calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes. It's supposed to get folded into Pytest itself at some point.

from matplotlib import test

parser = argparse.ArgumentParser(add_help=False)
Expand Down