-
Notifications
You must be signed in to change notification settings - Fork 301
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
KDtree type mismatch in knnW #771
Comments
The error actually occurs right at the It used to accept numpy arrays and silently build the KDTree behind the scenes. Now, it will fail immediately if the user passes a previously-valid input. Potential issues with this practice.
But, I see nothing wrong with @jlaura's commit itself. It's just an API change that was not smoothed by a deprecation warning. I'd mark this as notabug+wontfix, but perspective is needed. |
The OP's code was copy/pasted from the user guide: http://pysal.readthedocs.org/en/latest/users/tutorials/weights.html#k-nearest-neighbor-weights (Larger issue, are the examples the user guide no longer tested?) |
Did they used to get tested? I'm unaware of any tests that run aside from the unittests. I think even doctests & coveralls are currently turned off. |
Further complicating things, we do a check in every constructor in While it's reasonable to assume that 1]> import scipy.spatial as spat; import pysal as ps
2]> df = ps.pdio.read_files(ps.examples.get_path('columbus.shp'))
3]> data = df[['X', 'Y']].values
4]> print(type(ps.cg.KDTree(data)))
4| ckdtree.cKDTree
5]> issubclass(type(spat.cKDTree), spat.KDTree)
5| False
6]> issubclass(type(spat.KDTree), spat.cKDTree)
6| False which means that we've now got this class of errors: ps.Kernel(ps.cg.KDTree(data))
TypeError Traceback (most recent call last)
<ipython-input-13-8e6cf2c300ce> in <module>()
----> 1 ps.Kernel(ps.cg.KDTree(data))
/home/ljw/.local/lib/python2.7/site-packages/pysal/weights/Distance.pyc in __init__(self, data, bandwidth, fixed, k, function, eps, ids, diagonal)
271 else:
272 self.data = data
--> 273 self.kdt = KDTree(self.data)
274 self.k = k + 1
275 self.function = function.lower()
/home/ljw/.local/lib/python2.7/site-packages/pysal/cg/kdtree.pyc in KDTree(data, leafsize, distance_metric, radius)
242 return scipy.spatial.KDTree(data, leafsize)
243 else:
--> 244 return scipy.spatial.cKDTree(data, leafsize)
245 elif distance_metric == 'Arc':
246 return Arc_KDTree(data, leafsize, radius)
ckdtree.pyx in ckdtree.cKDTree.__init__ (scipy/spatial/ckdtree/ckdtree.cxx:7474)()
/home/ljw/.local/lib/python2.7/site-packages/numpy/core/numeric.pyc in ascontiguousarray(a, dtype)
559
560 """
--> 561 return array(a, dtype, copy=False, order='C', ndmin=1)
562
563 def asfortranarray(a, dtype=None):
TypeError: float() argument must be a string or a number AFAICT, this hits every constructor in Again, the main issue here is that the inheritance diagram is forked: |
At some point the tests in the documentation were turned off. I think the trail links to #593 |
This was resolved in #786 I believe. |
Indeed: 1]> import pysal as ps, numpy as np
2]> x,y = np.indices((5,5))
3]> x.shape = y.shape = (25,1)
4]> data = np.hstack((x,y))
5]> wknn3 = ps.knnW(data, k=3)
6]> ps.version
6| '1.11.2dev' proceeds without a hitch. |
From pysal-dev:
The text was updated successfully, but these errors were encountered: