-
Notifications
You must be signed in to change notification settings - Fork 509
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
making it python 3 compatible #188
Conversation
…python 2 compatibility, adding the future imports to keep others clean and behavior particularly division consistent
…, adding a new notebook for simple tests, fixing typo in safe_xrange, most tests pass now, but still differences, probably because SimpleITK, numpy, and PyWavelets have changed.
@kmader Thank you for your work on making PyRadiomics compatible with Python3! I'm currently reviewing your changes. Could you also enable CircleCI testing? I don't see the results. Travis and Appveyor show failing tests, but this is due to the fact that it is not yet set up correctly (see also #183). Additionally, I'm seeing an error in shape._calculate2DMaxDiameter, which has to be addressed before we can merge. |
In python 3, the zip function returns a 'zip' object, similar to python generators. This does not change it's implementation in python for loops, but it is not evaluated if it is used to generate a numpy array. Therefore, add a cast to list, which evaluates the object, before assigning it to the numpy array. Also, use relative imports in tests. Finally, fix some print-function bugs in the 'bin' and 'batchexamples' folder and rerun the python notebooks, so the output reflects the changes made.
@kmader, In python 3, the implementation of the Also, there were some python 2-style print calls left in the bin folder, so I also corrected those. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, but I'd like to test it using CircleCI before I approve.
Any ideas why CircleCI build is not being triggered for this PR? I have problems with this PR on mac:
The current master works fine. |
@jcfr FYI I disabled Appveyor build when no appveyor.yml is present in the org settings Also did the same for TravisCI |
@JoostJM thanks, that zip problem I had just ignored because it worked mostly fine without it (I calculate shape features on my own). Why did you change
To this
The python3 style AFAIK is to just use the top way |
@kmader if I undo the change by @JoostJM I get the following errors on mac:
|
@fedorov maybe try adding absolute_import
|
This does not help :-( |
@kmader can you confirm you tested this with Python 2? |
@kmader, @fedorov, I used the relative import as my IDE wasn't recognizing the modules. However, if you want to use relative imports in python 2.7, it must be a package (i.e. has an |
@fedorov, @kmader, I have nose running locally for both python 2.7 and 3.5, but we haven't caught all issues yet. Currently I am working on a bug (filter function does not work properly in python 3.5 and as such deletes several diagonals in glrlm, causing large enough errors to fail the tests). Moreover, some other functions, mainly in glcm are also differing slightly from python 2.7 generated baseline, but these errors are fairly small. |
Some functions expect string types (such as in nose-testing), but python 3.5 by default provides unicode strings. Add forced casts where necessary. Also, 'wb' mode requires strings to be encoded as bytes, not string in python 3.5. The fix did not work in this case. Change mode to 'w', which accepts regular strings. Additionally, safe_cmp produced errors for dictionary comparison in python 3.5, replace by `==` comparison. Finally, update layout in testing files (such as replace `!=` by `is not` in comparisons to `None`). Update feature name in testing output to also reflect the feature class.
In python 3.5 GLRLM results differed from baseline. This due to the different implementation of the `filter()` function, which returns an iterator instead of a list. In GLRLM calculation, there where 2 iterations over this iter-object (one for flat-angle check, one for matrix calculation), causing it to break in python 3.5. Fix by merging the 2 iterations into one loop. Additionally, simplify the filter function.
This is due to the fact that this PR is based out of @kmader's repository, and if it doesn't have a webhook defined for CircleCI, no tests are run. I ran CircleCI tests for both python 2.7 and python 3.5 locally (Windows) and received no errors after my last commit. If I look at the diff-file generated, there are some functions with diff != 0, but the difference is always in the order of e-16, so most likely computer precision or epsilon difference... As far as I can see, this PR is now ready for merging, with PyRadiomics running both on python 2.7 and python 3.5 |
It works for me as well now. About CircleCI - I still don't understand why it doesn't work. Webhooks should only affect builds of the branches for @kmader repository, but I thought incoming PRs for pyradiomics should always be built, and rely on pyradiomics webhooks setup. |
Not in it's current form, but let me take a look at the webhooks of this repository |
@fedorov, I found the problem, the webhook is configured to also send a notification on PRs from forked repos, but in CircleCI, the building of PRs from forked repos was turned off. It should work now. |
Redelivered webhook after last commit. CircleCI now testing... |
Makes sense now, thanks! |
# Conflicts: # radiomics/__init__.py # radiomics/featureextractor.py # tests/test_docstrings.py
Merged the new master to resolve conflicts. Rebase impossible, as this requires a force push (not allowed on master branch). |
I was wondering why this PR comes from the master branch. How do you guys plan to sync it with pyradiomics master? |
Just like any other PR, as this is 4Quant:master branch, not pyradiomics:master. However, for future PRs, it is still advisable to do so on a non-master branch, as thing such as rebasing are easier. |
I suggest you disable force-push on 4Quant master, force 4Quant master to be identical to the current master, make a branch for this PR, and make a new PR off that branch. I would recommend against merging the commit history as it shows up at the moment for this PR. |
@kmader, I will rebase this branch onto the new master, but I can't push it to your repository, so I'll push it to the central repo and create a new PR. |
@JoostJM that sounds fine, thanks! |
superseded by #194 |
without breaking the python 2 compatibility (#178), adding the future imports to keep others clean and behavior particularly division consistent.
The current changes should change or break nothing with python 2 execution and only make the code itself runnable on 3.