Repository: enthought/chaco

Issue:
Lasso selection breaks with numpy 1.13
**Problem Description**
When running the scatter select example (chaco/examples/demo/basic/scatter_select.py) with numpy 1.13.3, an exception is raised by enable's `points_in_polygon` function, which expects arrays passed to it to be C-contiguous.

```
Traceback (most recent call last):
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/qt4/base_window.py", line 229, in mouseReleaseEvent
    self.handler.mouseReleaseEvent(event)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/qt4/base_window.py", line 118, in mouseReleaseEvent
    self._enable_window._handle_mouse_event(name + "_up", event)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/abstract_window.py", line 349, in _handle_mouse_event
    self.component.dispatch(mouse_event, event_name)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/component.py", line 921, in dispatch
    self._new_dispatch(event, suffix)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/component.py", line 961, in _new_dispatch
    self._dispatch_stateful_event(event, suffix)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/container.py", line 514, in _dispatch_stateful_event
    component.dispatch(event, suffix)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/component.py", line 921, in dispatch
    self._new_dispatch(event, suffix)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/component.py", line 949, in _new_dispatch
    self._active_tool.dispatch(event, suffix)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/interactor.py", line 94, in dispatch
    self._dispatch_stateful_event(event, suffix)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/enable/interactor.py", line 110, in _dispatch_stateful_event
    handler(event)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/chaco/tools/lasso_selection.py", line 159, in selecting_left_up
    return self.selecting_mouse_up(event)
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/chaco/tools/lasso_selection.py", line 172, in selecting_mouse_up
    self._update_selection()
  File "/Users/jwiggins/.edm/envs/test_env/lib/python2.7/site-packages/chaco/tools/lasso_selection.py", line 270, in _update_selection
    data, self._active_selection, False).astype(bool, copy=False)
  File "kiva/_cython_speedups.pyx", line 68, in kiva._cython_speedups.points_in_polygon (kiva/_cython_speedups.cpp:3068)
  File "kiva/stringsource", line 644, in View.MemoryView.memoryview_cwrapper (kiva/_cython_speedups.cpp:11770)
  File "kiva/stringsource", line 345, in View.MemoryView.memoryview.__cinit__ (kiva/_cython_speedups.cpp:8005)
ValueError: ndarray is not C-contiguous
```

**Reproduction Steps:**

Run the scatter select example and make a selection:
```
$ edm install -e chaco_bug -y numpy pyqt chaco
$ edm run -e chaco_bug -- python ~/source/chaco/examples/demo/basic/scatter_select.py
```

**Expected behavior:**

An exception should not be raised when a selection is made.

**OS, Python version:**
OS X 10.13.5
Python 2.7.13

**Package versions**
appdirs            1.4.3-1
chaco              4.7.1-2
distribute_remove  1.0.0-4
enable             4.7.1-3
fonttools          3.18.0-1
freetype           2.5.3-7
kiwisolver         0.1.3-3
libjpeg            7.0-5
libopenjpeg        2.1.0-4
libpng             1.6.12-6
mkl                2017.0.3-1
numpy              1.13.3-3
packaging          16.8-2
pil_remove         1.0.0-3
pillow             4.0.0-1
pip                10.0.1-1
pyface             6.0.0-1
pygments           2.2.0-1
pyparsing          2.2.0-1
pyqt               4.12-1
qt                 4.8.7-7
setuptools         38.2.5-1
sip                4.19.2-2
six                1.10.0-1
traits             4.6.0-1
traitsui           6.0.0-1



Discussion:

Resolving patch:
diff --git a/chaco/tools/lasso_selection.py b/chaco/tools/lasso_selection.py
--- a/chaco/tools/lasso_selection.py
+++ b/chaco/tools/lasso_selection.py
@@ -2,7 +2,7 @@
 """
 # Major library imports
 import numpy
-from numpy import array, empty, sometrue, transpose, vstack, zeros
+from numpy import array, empty, sometrue, vstack, zeros, ascontiguousarray
 
 # Enthought library imports
 from traits.api import Any, Array, Enum, Event, Bool, Instance, \
@@ -308,8 +308,9 @@ def _map_data(self, point):
     def _get_data(self):
         """ Returns the datapoints in the plot, as an Nx2 array of (x,y).
         """
-        return transpose(array((self.plot.index.get_data(), self.plot.value.get_data())))
-
+        points = array((self.plot.index.get_data(),
+                        self.plot.value.get_data()))
+        return ascontiguousarray(points.T)
 
     #------------------------------------------------------------------------
     # Property getter/setters


Test patch: