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 compatibility #16

Closed
sglyon opened this issue Jul 14, 2014 · 7 comments
Closed

Python 3 compatibility #16

sglyon opened this issue Jul 14, 2014 · 7 comments
Assignees

Comments

@sglyon
Copy link
Member

sglyon commented Jul 14, 2014

I think we should strive for 100% python 3 compatibility. Guido has officially announced (more than once) that the python 2 branch will only be maintained and that all new language features will only be implemented in python 3. Doing a quick 2to3 pass over the library shows that we will have to make very minor changes to the existing code for it to be python 3 compliant (mostly just swapping out print statements for a print function call).

One of the more exciting features forthcoming in the next python release (3.5) is the new syntax @ that will mean matrix multiplication. So, instead of writing np.dot(a, b) or a.dot(b), we can write the much more compact a @ b.

@sglyon sglyon self-assigned this Jul 14, 2014
@jstac
Copy link
Contributor

jstac commented Jul 14, 2014

Agreed. What is the best way to do this? Do we put from __future__ import x, y, z at the top of each module? If so exactly what should be put there?

@sglyon
Copy link
Member Author

sglyon commented Jul 14, 2014

There is a script called 2to3 that you can run on all the code. It will print out a summary of all the changes you need to make in order for the code to be python 3 compatible.

I'll run that and report back.

Also, I'll start making the changes on a branch named compat

@ChristopherShort
Copy link

If you only have python 3 installed - the pip install notes several modules with invalid syntax. Most often around print rather than print() and also on change in 3 for raising an exception.
Not sure why the list comprehension in the asset_pricing module was invalid.

Here were the warnings:

Running setup.py install for quantecon
File "/Users/ChristopherShort/anaconda/lib/python3.4/site-packages/quantecon/asset_pricing.py", line 36
self.P, self.s = [np.atleast_2d(x) for x in P, s]
^
SyntaxError: invalid syntax

  File "/Users/ChristopherShort/anaconda/lib/python3.4/site-packages/quantecon/compute_fp.py", line 34
    print "Computed iterate %d with error %f" % (iterate, error)
                                            ^
SyntaxError: invalid syntax

  File "/Users/ChristopherShort/anaconda/lib/python3.4/site-packages/quantecon/estspec.py", line 33
    raise ValueError, "Input vector length must be >= window length."
                    ^
SyntaxError: invalid syntax

  File "/Users/ChristopherShort/anaconda/lib/python3.4/site-packages/quantecon/lucastree.py", line 128
    print error
              ^
SyntaxError: invalid syntax

  File "/Users/ChristopherShort/anaconda/lib/python3.4/site-packages/quantecon/riccati.py", line 93
    print x
          ^

@cc7768
Copy link
Member

cc7768 commented Jul 25, 2014

Thanks for this. I will spend some time today starting to make things dually compatible

@ChristopherShort
Copy link

happy to help test - but new to python; pandas and Stachurski, Sargent examples pulled me over. But coding ability probably of limited value

@cc7768
Copy link
Member

cc7768 commented Jul 30, 2014

Thanks for the offer. We are almost done making the code compatible for both python 2 and python 3. We definitely appreciate you using the code and for helping point out this issue. We will hopefully close this issue in the next 24 hours, and it would be helpful if you could run through it all again and see if all is in order.

@sglyon
Copy link
Member Author

sglyon commented Jul 30, 2014

See #33 for updated issue and PR

@sglyon sglyon closed this as completed Jul 30, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants