Add version checking for dictionary calls#65
Open
exowanderer wants to merge 1 commit intoCoAxLab:masterfrom
exowanderer:Check-for-Python3/Python2-mismatches
Open
Add version checking for dictionary calls#65exowanderer wants to merge 1 commit intoCoAxLab:masterfrom exowanderer:Check-for-Python3/Python2-mismatches
exowanderer wants to merge 1 commit intoCoAxLab:masterfrom
exowanderer:Check-for-Python3/Python2-mismatches
Conversation
Main Issue
---
Using the DeBaCl example Jupyter notebok with Python3 failed at several places -- all but one of which dealt with dictionary calls such as itervalues(), iteritems(), iterkeys() -- because the syntax for dictionary calls changed between Python2 and Python3.
There were 12 such cases in the file `level_set_tree.py`.
After adding code snippets (listed below) that checked for python2 vs python3, I was able to fully run the `example/getting_started.ipynb` to completion with reasonable results (vs expectations).
A second issue was found while investigating any python3 versioning dictionary call issues. The line `n_bigkid = sum(_np.array(kid_size.values()) >= threshold)` was changed to
`n_bigkid = sum([len(tree.nodes[k].members) for k in parent.children])` (line 665 in this PR code)
The above error occurred because python (maybe only python3) cannot compare dictionary values with integers: "dict_values >= int".
Using the one line for-loop inside a summation above fixed the issue. Please confirm that the two lines fulfill the same function.
---
Example Snippets
---
This PR adds an import at the top of the package: `from sys import version` and 24 if-statements (12 places x 2 versions) to check the version. Such as:
```
if version[0] == '2':
nodes_items = self.nodes.iteritems()
if version[0] == '3':
nodes_items = self.nodes.items()
```
```
if version[0] == '2':
nodes_values = self.nodes.itervalues()
if version[0] == '3':
nodes_values = self.nodes.values()
```
```
if version[0] == '2':
root_tree_nodes_keys = root_tree.nodes.nodes()
if version[0] == '3':
root_tree_nodes_keys = root_tree.nodes.keys()
```
---
Necessary Version Information:
---
`Darwin local 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64`
`Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:52:12) \n[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)]`
Collaborator
|
Hi @exowanderer, many thanks for the PR - I'm currently unable to work on DeBaCl, but I'm hoping to return to it soon. |
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.
Main Issue
Using the DeBaCl example Jupyter notebok with Python3 failed at several places -- all but one of which dealt with dictionary calls such as itervalues(), iteritems(), iterkeys() -- because the syntax for dictionary calls changed between Python2 and Python3.
There were 12 such cases in the file
level_set_tree.py.After adding code snippets (listed below) that checked for python2 vs python3, I was able to fully run the
example/getting_started.ipynbto completion with reasonable results (vs expectations).A second issue was found while investigating any python3 versioning dictionary call issues. The line
n_bigkid = sum(_np.array(kid_size.values()) >= threshold)was changed ton_bigkid = sum([len(tree.nodes[k].members) for k in parent.children])(line 665 in this PR code)The above error occurred because python (maybe only python3) cannot compare dictionary values with integers: "dict_values >= int".
Using the one line for-loop inside a summation above fixed the issue. Please confirm that the two lines fulfill the same function.
Example Snippets
This PR adds an import at the top of the package:
from sys import versionand 24 if-statements (12 places x 2 versions) to check the version. Such as:Necessary Version Information:
Darwin local 15.6.0 Darwin Kernel Version 15.6.0: Mon Aug 29 20:21:34 PDT 2016; root:xnu-3248.60.11~1/RELEASE_X86_64 x86_64Python 3.5.2 |Anaconda custom (x86_64)| (default, Jul 2 2016, 17:52:12) \n[GCC 4.2.1 Compatible Apple LLVM 4.2 (clang-425.0.28)]