type mismatch causes chaco examples to fail

Bug #425957 reported by Evan Jeffrey
32
This bug affects 6 people
Affects Status Importance Assigned to Milestone
python-chaco (Ubuntu)
Confirmed
Undecided
Unassigned
python-enable (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

Binary package hint: python-enable

Running the chaco examples, such as /usr/share/doc/python-chaco/examples/basic/traits_editor.py fails to display properly and produces error messages:

Traceback (most recent call last):
  File "/usr/lib/python2.6/dist-packages/enthought/enable/abstract_window.py", line 340, in _paint
    self.component.draw(gc, view_bounds=(0, 0, size[0], size[1]))
  File "/usr/lib/python2.6/dist-packages/enthought/enable/component.py", line 416, in draw
    self._draw(gc, view_bounds, mode)
  File "/usr/lib/python2.6/dist-packages/enthought/enable/component.py", line 718, in _draw
    self._dispatch_draw(layer, bb, view_bounds, mode)
  File "/usr/lib/python2.6/dist-packages/enthought/enable/container.py", line 326, in _dispatch_draw
    component._dispatch_draw(layer, gc, new_bounds, mode)
  File "/usr/lib/python2.6/dist-packages/enthought/enable/component.py", line 747, in _dispatch_draw
    handler(gc, view_bounds, mode)
  File "/usr/lib/python2.6/dist-packages/enthought/enable/component.py", line 844, in _draw_underlay
    underlay.overlay(self, gc, view_bounds, mode)
  File "/usr/lib/python2.6/dist-packages/enthought/chaco/axis.py", line 204, in overlay
    self._draw_component(gc, view_bounds, mode, component)
  File "/usr/lib/python2.6/dist-packages/enthought/chaco/axis.py", line 241, in _draw_component
    self._draw_axis_line(gc, self._origin_point, self._end_axis_point)
  File "/usr/lib/python2.6/dist-packages/enthought/chaco/axis.py", line 291, in _draw_axis_line
    gc.move_to(*around(startpoint))
  File "/usr/lib/python2.6/dist-packages/enthought/kiva/agg/agg.py", line 864, in move_to
    def move_to(*args): return _agg.GraphicsContextArray_move_to(*args)
TypeError: in method 'GraphicsContextArray_move_to', argument 2 of type 'double'

According to some other bug reports I found, this is due to a bug in code generated by swig, and some confusion between C 'float' and 'double' types. It shows up when python-enable is built under python2.6.

Here is the upstream bug report:

https://svn.enthought.com/enthought/ticket/1776

That report suggests a work-around by editing /usr/lib/python2.6/dist-packages/enthought/kiva/agg/agg.py which appears to work correctly for me.

Changed in python-enable (Ubuntu):
status: New → Confirmed
Revision history for this message
Guy K. Kloss (guy.kloss) wrote :

Almost all Chaco examples that open a window show the same type of error.

Further indication of this effect can be found on the enthought-dev mailing list:

https://mail.enthought.com/pipermail/enthought-dev/2009-January/019549.html
https://mail.enthought.com/pipermail/enthought-dev/2009-June/021965.html

Changed in python-chaco (Ubuntu):
status: New → Confirmed
Revision history for this message
Václav Šmilauer (eudoxos) wrote :

This can be used as workaround. Suggested by https://mail.enthought.com/pipermail/enthought-dev/2009-June/021965.html.

--- /usr/share/pyshared/enthought/kiva/agg/agg.py 2009-12-06 14:36:02.363707987 +0100
+++ /usr/share/pyshared/enthought/kiva/agg/agg.py~ 2009-12-06 14:33:21.273733592 +0100
@@ -861,7 +861,7 @@
     def begin_page(*args): return _agg.GraphicsContextArray_begin_page(*args)
     def end_page(*args): return _agg.GraphicsContextArray_end_page(*args)
     def begin_path(*args): return _agg.GraphicsContextArray_begin_path(*args)
- def move_to(*args): return _agg.GraphicsContextArray_move_to(args[0],float(args[1]),float(args[2]))
+ def move_to(*args): return _agg.GraphicsContextArray_move_to(*args)
     def line_to(*args): return _agg.GraphicsContextArray_line_to(*args)
     def curve_to(*args): return _agg.GraphicsContextArray_curve_to(*args)
     def quad_curve_to(*args): return _agg.GraphicsContextArray_quad_curve_to(*args)

Changed in ezvisage:
status: Unknown → New
Revision history for this message
Toby Collett (thjc) wrote :

The bug appears to relate to type of the array returned by the 'around' function from numpy. around preserves the type of arrays that are passed to it, which in the cases above leads to an int array being fed via *args into a method expecting a double. There seems to be several approaches to fixing this:
- Pass the args individually as suggested in earlier posts
- Make the source array to around be floating point.
- Provide a floating point destination array for around (it will cast the input to the correct output type I believe)
- Do some other type manipulations

Option 2 is reasonably straight forward, but would only fix Chaco, not any other applications using python-enable in this way. A two liner patch made the examples I tried run, although looking at the code there could well be other places this issue exists.
--- enthought/chaco/axis.py 2009-03-20 22:52:07.000000000 +0000
+++ /usr/lib/python2.6/dist-packages/enthought/chaco/axis.py 2009-12-10 08:07:54.000000000 +0000
@@ -139,11 +139,11 @@
     _major_axis = Array
     _title_orientation = Array
     _title_angle = Float
- _origin_point = Array
+ _origin_point = Array(dtype=float64)
     _inside_vector = Array
     _axis_vector = Array
     _axis_pixel_vector = Array
- _end_axis_point = Array
+ _end_axis_point = Array(dtype=float64)

     ticklabel_cache = List

Revision history for this message
Toby Collett (thjc) wrote :

Here is a simple python-enable program that will fail with python 2.6, succeeds with python 2.5. Tested on Karmic.

# -*- coding: utf-8 -*-
import enthought.kiva.agg
from numpy import array, int64, float64
gca=enthought.kiva.agg.GraphicsContextArray((2,2))

a1 = array([1,2],float64)
a2 = array([1,2],int64)

gca.move_to(*a1)
#The next call will fail
gca.move_to(*a2)

Revision history for this message
Gael Varoquaux (gael-varoquaux) wrote : Re: [Bug 425957] Re: type mismatch causes chaco examples to fail

Hey,

I am sorry, I had not realized that this bug was lying around. AFAIK, it
is the same as:
https://bugs.launchpad.net/ubuntu/+source/python-enable/+bug/491120

The patch is given in the other bug: it involves a small fix to the swig
file generating the enable bindings.

If you confirm that the fix in the bug 491120 fixes your problem too,
could you mark this bug as a duplicate.

Cheers,

Gaël

Revision history for this message
Toby Collett (thjc) wrote :

Fix in that bug fixes the problem for me.

Changed in ezvisage:
status: New → Fix Released
Revision history for this message
abheri (pentheseleia) wrote :

Yep. The fix suggested in #491120 fixes the issues above with Python 2.6.4 on Karmic.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.