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

Add version checking for dictionary calls #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add version checking for dictionary calls #65

wants to merge 1 commit into from

Conversation

exowanderer
Copy link

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)]

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)]`
@bpkent
Copy link
Collaborator

bpkent commented Nov 4, 2016

Hi @exowanderer, many thanks for the PR - I'm currently unable to work on DeBaCl, but I'm hoping to return to it soon.
-Brian

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

Successfully merging this pull request may close these issues.

2 participants