Add version checking for dictionary calls #65
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.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 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 version
and 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_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)]