[Python-modules-commits] [python-mplexporter] 119/135: some py3k fixes

Wolfgang Borgert debacle at moszumanska.debian.org
Tue Sep 23 21:19:10 UTC 2014


This is an automated email from the git hooks/post-receive script.

debacle pushed a commit to branch master
in repository python-mplexporter.

commit f154ecf603f88d310b2288cc51a48e3ed2efbca2
Author: Jake Vanderplas <vanderplas at astro.washington.edu>
Date:   Fri Mar 28 10:00:00 2014 -0700

    some py3k fixes
---
 mplexporter/_py3k_compat.py     | 22 ++++++++++++++++++++++
 mplexporter/exporter.py         |  2 +-
 mplexporter/renderers/base.py   |  3 ++-
 mplexporter/tests/test_basic.py |  6 ++++++
 4 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/mplexporter/_py3k_compat.py b/mplexporter/_py3k_compat.py
new file mode 100644
index 0000000..9ca8455
--- /dev/null
+++ b/mplexporter/_py3k_compat.py
@@ -0,0 +1,22 @@
+"""
+Simple fixes for Python 2/3 compatibility
+"""
+import sys
+PY3K = sys.version_info[0] >= 3
+
+
+if PY3K:
+    import builtins
+    import functools
+    reduce = functools.reduce
+    zip = builtins.zip
+    xrange = builtins.range
+    map = builtins.map
+else:
+    import __builtin__
+    import itertools
+    builtins = __builtin__
+    reduce = __builtin__.reduce
+    zip = itertools.izip
+    xrange = __builtin__.xrange
+    map = itertools.imap
diff --git a/mplexporter/exporter.py b/mplexporter/exporter.py
index 3384ab7..b43e405 100644
--- a/mplexporter/exporter.py
+++ b/mplexporter/exporter.py
@@ -78,7 +78,7 @@ class Exporter(object):
             Data transformed to match the given coordinate code.
             Returned only if data is specified
         """
-        if transform.contains_branch(transforms.BlendedGenericTransform):
+        if isinstance(transform, transforms.BlendedGenericTransform):
             warnings.warn("Blended transforms not yet supported. "
                           "Zoom behavior may not work as expected.")
 
diff --git a/mplexporter/renderers/base.py b/mplexporter/renderers/base.py
index 88e6d39..0c1d2c2 100644
--- a/mplexporter/renderers/base.py
+++ b/mplexporter/renderers/base.py
@@ -6,6 +6,7 @@ import numpy as np
 from matplotlib import transforms
 
 from .. import utils
+from .. import _py3k_compat as py3k
 
 
 class Renderer(object):
@@ -202,7 +203,7 @@ class Renderer(object):
                     edgecolor, styles['linewidth'], facecolor]
 
         it = itertools
-        return it.islice(it.izip(*it.imap(it.cycle, elements)), N)
+        return it.islice(py3k.zip(*py3k.map(it.cycle, elements)), N)
 
     def draw_path_collection(self, paths, path_coordinates, path_transforms,
                              offsets, offset_coordinates, offset_order,
diff --git a/mplexporter/tests/test_basic.py b/mplexporter/tests/test_basic.py
index 72978e8..25099ae 100644
--- a/mplexporter/tests/test_basic.py
+++ b/mplexporter/tests/test_basic.py
@@ -6,6 +6,7 @@ matplotlib.use('Agg')
 import matplotlib.pyplot as plt
 
 import numpy as np
+from numpy.testing import assert_warns
 
 
 def fake_renderer_output(fig, Renderer):
@@ -199,3 +200,8 @@ def test_legend_dots():
                          closing figure
                          """)
 
+def test_blended():
+    fig, ax = plt.subplots()
+    ax.axvline(0)
+    assert_warns(UserWarning, fake_renderer_output, fig, FakeRenderer)
+    

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-mplexporter.git



More information about the Python-modules-commits mailing list