Skip to content
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

python 3 errors in imports and syntax #2

Closed
mfouesneau opened this issue Jul 7, 2016 · 2 comments
Closed

python 3 errors in imports and syntax #2

mfouesneau opened this issue Jul 7, 2016 · 2 comments

Comments

@mfouesneau
Copy link
Contributor

I was able to correct a couple issues and make simple plots.

Patch below

diff --git a/python/vaex/image.py b/python/vaex/image.py
index 70fe8a0..78f63fb 100644
--- a/python/vaex/image.py
+++ b/python/vaex/image.py
@@ -1,12 +1,15 @@
 __author__ = 'maartenbreddels'
 import PIL.Image
 import PIL.ImageDraw
-import StringIO
 import collections
 import numpy as np
 import matplotlib.colors
 import warnings
 from base64 import b64encode
+try:
+    from StringIO import StringIO
+except:
+    from io import StringIO

 def rgba_2_pil(rgba):
        with warnings.catch_warnings():
@@ -15,7 +18,7 @@ def rgba_2_pil(rgba):
        return im

 def pil_2_data(im, format="png"):
-       f = StringIO.StringIO()
+       f = StringIO()
        im.save(f, format)
        return f.getvalue()

@@ -37,7 +40,7 @@ cairo_modes["saturate"] = (lambda aA, aB: np.minimum(1, aA + aB),
 cairo_modes["add"] = (lambda aA, aB: np.minimum(1, aA + aB),
                                                   lambda aA, xA, aB, xB, aR: (aA*xA + aB*xB)/aR)

-modes = pdf_modes.keys() + cairo_modes.keys()
+modes = list(pdf_modes.keys()) + list(cairo_modes.keys())
 def background(shape, color="white", alpha=1, bit8=True):
        rgba = np.zeros(shape + (4,))
        rgba[:] = np.array(matplotlib.colors.colorConverter.to_rgba(color))
@maartenbreddels
Copy link
Member

thx for the patch, I'll make sure it's covered by the unittests and apply this.

@maartenbreddels
Copy link
Member

I added unittests that covers this, let me know if it works.

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

No branches or pull requests

2 participants