Repository: yt-project/yt

Issue:
Potential Python 3 bug in insert_image_yt and proposed fix
When I try and use the "Publication-ready Figures" examples I get the following error:

>   File "/turquoise/users/jsmidt/my_conda/lib/python3.6/site-> 
> packages/yt/visualization/eps_writer.py", line 521, in insert_image_yt
>    self.field = plot.plots.keys()[0]
> TypeError: 'dict_keys' object does not support indexing

Which seems related to this issue where in Python 3 dictionary keys are not lists: https://stackoverflow.com/questions/17322668/typeerror-dict-keys-object-does-not-support-indexing

However, if you change change 

`self.field = plot.plots.keys()[0]`

to 

`self.field = list(plot.plots.keys())[0]`

in line 520 of yt/visualization/eps_writer.py, the problem seems to go away in my Python 3.6.
Potential Python 3 bug in insert_image_yt and proposed fix
When I try and use the "Publication-ready Figures" examples I get the following error:

>   File "/turquoise/users/jsmidt/my_conda/lib/python3.6/site-> 
> packages/yt/visualization/eps_writer.py", line 521, in insert_image_yt
>    self.field = plot.plots.keys()[0]
> TypeError: 'dict_keys' object does not support indexing

Which seems related to this issue where in Python 3 dictionary keys are not lists: https://stackoverflow.com/questions/17322668/typeerror-dict-keys-object-does-not-support-indexing

However, if you change change 

`self.field = plot.plots.keys()[0]`

to 

`self.field = list(plot.plots.keys())[0]`

in line 520 of yt/visualization/eps_writer.py, the problem seems to go away in my Python 3.6.


Discussion:
The EPS writer is unfortunately not very well tested. Your suggested change sounds good. Would you like to make a pull request?
The EPS writer is unfortunately not very well tested. Your suggested change sounds good. Would you like to make a pull request?

Resolving patch:
diff --git a/yt/visualization/eps_writer.py b/yt/visualization/eps_writer.py
--- a/yt/visualization/eps_writer.py
+++ b/yt/visualization/eps_writer.py
@@ -86,7 +86,7 @@ def hello_world(self):
 
     def return_field(self, plot):
         if isinstance(plot, (PlotWindow, PhasePlot)):
-            return plot.plots.keys()[0]
+            return list(plot.plots.keys())[0]
         else:
             return None
 
@@ -382,7 +382,7 @@ def axis_box_yt(self, plot, units=None, bare_axes=False,
                  _ylog = False
             _tickcolor = None 
         elif isinstance(plot, PhasePlot):
-            k = plot.plots.keys()[0]
+            k = list(plot.plots.keys())[0]
             _xrange = plot[k].axes.get_xlim()
             _yrange = plot[k].axes.get_ylim()
             _xlog = plot.profile.x_log
@@ -517,7 +517,7 @@ def insert_image_yt(self, plot, field=None, pos=(0,0), scale=1.0):
             self.canvas = pyx.canvas.canvas()
         if isinstance(plot, (PlotWindow, PhasePlot)):
             if field is None:
-                self.field = plot.plots.keys()[0]
+                self.field = list(plot.plots.keys())[0]
                 mylog.warning("No field specified.  Choosing first field (%s)" % \
                               str(self.field))
             else:


Test patch: