Alcarney py3#61
Merged
Merged
Conversation
So far the following changes have been made:
- Adding extra dependency, `future`, this so you can still use `xrange`
in python 3 by adding `from past.builtins import xrange` wherever
needed.
- Added a `from __future__ import absolute_import` so module loading
works in both python 2 and 3
- In python 2 you could do `generator.next()`, however this has been
removed in python 3 in favour of `next(generator)`. Thankfully this
also works in python 2
- In python 2 if you did the following:
```
if 10 < 'Inf':
....
```
python would automatically convert the string to a float. However
python 3 doesn't do this. So pretty much everywhere all 'Infs' have
been converted to float('Inf').
In the case of loading parameters from a YAML file, I had to add the
following to `load_paramters` in `ciw/import_params.py`:
```
parameters['Queue_capacities'] =
list(map(lambda x: float("Inf") if x == "Inf" else x,
parameters['Queue_capacities']))
```
Which simply does the conversion as the parameters are read in and
leaving anything which doesn't need converting alone.
*NOTE:* My gut tells me that it's this change that's causing the
`no such attribute: self.servers` error. Since the if statement in
the `__init__` method of the `Node` class:
```
if self.c < float("Int"):
...
```
would no longer pass and I don't see anywhere else where `self.servers`
would be assigned.
- Finally something that you REALLY need to double check is a list
comprehension on line 136 in `import_params.py` from:
```
[len(row) for row in obs for obs in params['Transition_matrices'].values()]
```
to:
```
[len(row) for row in [obs for obs in params['Transition_matrices'].values()][0]]
```
This is due to a bug in python 2 that caused the scope from list
comprehensions to 'leak' into it's surroundings. In python 3 this was
fixed and I think that is why the variable `obs` is undefined if you
try to use the original code with python 3. However I'm not sure if my
'fix' has changed the semantics of the above expression so I'm
highlightling it here so you can check it over.
That's what I have so far and I don't think I've forgottenany other
changes I've had to make.
| language: python | ||
| python: | ||
| - 2.7 | ||
| - 3.5 |
Contributor
There was a problem hiding this comment.
Could also run py3.4? No need but no harm to actively test the two latest py3s.
Member
Author
There was a problem hiding this comment.
Yep I'll add it. everything still failing atm anyway (doctests i think though)
Member
Author
|
@alcarney random.choice has different outcomes with the same random seed in Python 3 and Python 2. Replaced with numpy.random.choice. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Adjustments to PR #60 by @alcarney
Fixing issues around "Inf" and float("Inf"):
* In the parameters dictionary use "inf" (more readable if printing out dictionary
* Everywhere else use float("inf") (creating a Network from dictionary converts string to float)
This is done so that users can type in "Inf" into a parameters file, and also error checking can check for string when seeing "Inf". Everywhere else in the code float("inf") is used, which makes comparisons easier and works with Python 3.