-
Notifications
You must be signed in to change notification settings - Fork 99
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
Python 3 compatibility fixes #369
Conversation
* Mainly import problems.
* More fixes
* Preliminary commit... Several fixes were done.
# Conflicts: # chaco/api.py # chaco/axis.py # chaco/base.py # chaco/lineplot.py
# Conflicts: # chaco/jitterplot.py # chaco/text_plot_1d.py
# Conflicts: # chaco/plot.py
chaco/legend.py
Outdated
@@ -355,7 +358,7 @@ def get_preferred_size(self): | |||
if len(self.plots) == 0: | |||
return [0, 0] | |||
|
|||
plot_names, visible_plots = map(list, zip(*sorted(self.plots.items()))) | |||
plot_names, visible_plots = list(sm.map(list, sm.zip(*sorted(six.iteritems(self.plots))))) |
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.
This could probably do with some unpacking. Alternatively, can we just use the standard Python constructs here and write the RHS as list(map(list, zip(*sorted(self.plots))))
?
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.
Your approach will not work. You need to have the items() in there
x = {'b': 1, 'a': 3}
assert sorted(x) == ['a', 'b']
assert sorted(x.items()) == [('a', 3), ('b', 1)]
For standard python contructs. See my comment in enthought/traits#374
It's more or less the same issue. I would prefer to keep the iterator version whenever possible.
Let me know your decision.
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.
Ah, I misunderstood. Thanks for the clarification, and let's keep it like you had it originally.
@@ -1,4 +1,6 @@ | |||
|
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.
Can you put a from __future__ import print_function
here?
@@ -350,15 +354,19 @@ def estimate_width(self, start, end, numlabels=None, char_width=None, | |||
elif char_width: | |||
avg_size = len("%g%g" % (start, end)) / 2.0 | |||
initial_estimate = round(fill_ratio * char_width / avg_size) | |||
else: |
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.
This seems orthogonal to the cleanup, can you describe what the issue is here? If the issue is that numlabels
and char_width
should not be both None
, perhaps a ValueError("num_labels and char_width should not both be None.")
would be more appropriate.
@@ -3,8 +3,8 @@ | |||
|
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.
Also needs a from __future__ import print_function
.
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.
@jdeschenes This is looking very good already, thanks for doing this! I left some general comments here and here, pointing out similar issues as @mdickinson reported for Traits. It also looks as if there are some changes that affect functionality, if possible it would be good to submit those separately (it will making reviewing easier). If there any areas (particularly with the demos) where the rest of the conversion is problematic, please let me know!
@@ -42,7 +42,7 @@ def test_strftimeEx_04(): | |||
# The format "%(ms_)" uses floor(). |
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.
Also needs a from __future__ import print_function
at the top of the module.
@@ -2,11 +2,11 @@ | |||
from itertools import starmap |
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.
Also needs a from __future__ import print_function
at the top of the module.
chaco/tests/test_image_plot.py
Outdated
@@ -108,48 +113,56 @@ def plot_comparison(input_image, expected_image, **plot_kwargs): | |||
plt.show() | |||
|
|||
|
|||
@unittest.skipIf(six.PY3, "Bug in the image plotter in python 3") |
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.
That's unexpected, is that new?
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.
That's actually a pretty old enthought/enable#95(See also enthought/enable#283). There are probably more related issues on github. I have the same issues on Windows so it is not strictly a gcc or clang issue.
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.
I see, can you add a reference to the issue in the skip message?
chaco/tools/line_inspector.py
Outdated
@@ -78,7 +78,8 @@ def draw(self, gc, view_bounds=None): | |||
if self.is_listener: | |||
tmp = self._get_screen_pts() | |||
elif self.is_interactive: | |||
tmp = self._last_position |
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.
It looks like this (and some of the other changes in this module) changes the functionality. Can you explain why this is necessary? If this fixes a bug, it would probably be good to split it off from the current PR and submit as a separate PR.
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.
Hi, I pulled in my branch #205 as I found it helped quite a bit and it looked like it will not be implemented anytime soon. I reverted changes in latest commit.
chaco/tools/pan_tool.py
Outdated
@@ -247,6 +247,8 @@ def panning_mouse_leave(self, event): | |||
return self._end_pan(event) | |||
|
|||
def _start_pan(self, event, capture_mouse=True): | |||
if event.control_down: |
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.
Also a functionality change.
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.
Sorry about that... This has been reverted.
@@ -1,10 +1,11 @@ | |||
from cStringIO import StringIO |
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.
I think some of the bundled sphinx extensions in this folder might not be Python3 compatible... (Just a comment in passing, no need to take any action)
examples/demo/basic/image_lasso.py
Outdated
|
||
# We first map to screen because the selection is stored as coordinates | ||
# in data space | ||
screen_pts = lasso_tool.plot.map_screen(selection) | ||
|
||
# Now map each point into the grid index | ||
for x, y in screen_pts: | ||
print("\t", lasso_tool.plot.map_index((x, y))) | ||
# for x, y in screen_pts: |
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.
Can you remove the commented-out code here?
@@ -13,7 +13,7 @@ | |||
""" | |||
|
|||
# Major library imports | |||
from scipy.misc import lena | |||
from scipy.misc import face |
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.
+100
from chaco.tools.api import SelectedZoomState | ||
import numpy | ||
|
||
class CaeZoomTool(ZoomTool): |
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.
Cae?
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.
Sorry about that, this should not have been part of the commit.
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.
No worries, looked like a pretty nifty tool ;-)
Sorry about that, looks like I bundled more changes(I am using this branch) than strictly necessary. I will do a pass and remove functional changes. |
* used `from __future__ import print_function` on all files with print functions * Removed usage of `six.u`. Python 3.2 will not be supported * Fixed an error message in formatters.py * Forgot a `end=" "` in scales_test_case.py * Removed a trailing backslash in plot_maker.py * Removed integration of changes in line_inspector.py * Removed changes from pan_tool.py * traitsdoc.py had wrong import format * Uncommented code in image_lasso.py * Uncommented code in financial_plot.py * Removed changes from multiaxis_using_Plot.py * Removed changes from two_plots.py
I think I need to comment on some of the functional changes that I put there by mistake. For multiaxis_using_Plot.py:
For financial_plot.py
|
@jdeschenes Thanks for addressing the comments. Would you mind merging master in and resolving any merge conflicts? It would be good to start getting Travis test results on this. |
# Conflicts: # chaco/api.py
The merge has just been done. |
chaco/speedups.py
Outdated
except ImportError: | ||
# TO TEST | ||
raise |
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.
Do we need this explicit raise
?
docs/source/conf.py
Outdated
@@ -52,7 +52,9 @@ def get_build_docset(): | |||
# The default replacements for |version| and |release|, also used in various | |||
# other places throughout the built documents. | |||
d = {} | |||
execfile(os.path.join('..', '..', 'chaco', '_version.py'), d) | |||
exec(compile(open(os.path.join('..', '..', 'chaco', '_version.py')).read(), |
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.
Can you isolate the os.path.join('..', '..', 'chaco', '_version.py')
into a local variable for re-use?
@jdeschenes I left two tiny comments, but otherwise this looks very good to me. If you fix up those two items (and have nothing more to add), then I think this is good to go. |
@jvkersch I fixed the issues you mentionned. I think this is ready to go! |
@jdeschenes I'm following along with the Enable review, and I think it would be good here too to use |
@jvkersch I think I have corrected everything. Let me know if there is anything else! |
@jdeschenes I think this looks good to go! Thanks a lot for doing this (and for tackling the other repos, too). This will improve developer experience by a lot! |
The unit test pass in python 3.6. This has not yet been completely tested in python. I will do another pass once I have gone over enable.
The examples have not been run as well. So I may make further modifications.
There is an issue in python 3 in the image plot. This is caused by a bug in enable. I skipped those tests.