Fix NDHistogram iteration bug in DpEngine (.items() → .iteritems() / _hist_array) and add Python 3 conda environment file #76
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.
Description
When running the Cluster module on the python3 branch, the following error occurs:
AttributeError: 'NDHistogram' object has no attribute 'items'
This happens because the code in Cluster/DpEngine.py assumed the input histogram was a Python dict and called .items(). In reality, on the Python 3 branch, the object is a data.Patient.NDHistogram, which exposes .iteritems() (a custom method retained from Python 2 style) and _hist_array.
Fix
Updated DpEngine.init to handle both dict-like inputs and NDHistogram objects.
Added a fallback using .iteritems() to maintain compatibility.
This ensures clustering runs correctly on the Python 3 branch.
Environment
To simplify setup for Python 3 users, I’ve added a conda environment file (phylogicndt_py3.yml) with tested dependencies. This avoids ABI conflicts by using conda for the scientific stack and pip only where required.