libpysal
libpysal copied to clipboard
numpy overrides cg.Point dtype?
It appears that numpy is overriding libpysal.cg.Point objects and converting directly into arrays when storing the points in a numpy.array. I came across this issue (pysal/spaghetti#378) when implementing improved support for libpysal.cg geometries. Has anyone else seen this?
In [1]: %load_ext watermark
In [2]: %watermark
2020-01-12T15:31:01-05:00
CPython 3.7.3
IPython 7.10.2
compiler : Clang 9.0.0 (tags/RELEASE_900/final)
system : Darwin
release : 19.2.0
machine : x86_64
processor : i386
CPU cores : 4
interpreter: 64bit
In [3]: import libpysal
In [4]: import numpy
In [5]: import scipy
In [6]: %watermark -iv
numpy 1.17.3
scipy 1.3.3
libpysal 4.2.0
In [7]: points_in_list = [libpysal.cg.Point((1,1)), libpysal.cg.Point((2,2))]
In [8]: print(type(points_in_list), type(points_in_list[0]))
<class 'list'> <class 'libpysal.cg.shapes.Point'>
In [9]: for dtype in (tuple, numpy.array):
...: pts_containers = dtype(points_in_list)
...: print(type(pts_containers), type(pts_containers[0]), type(pts_containers[0][0]))
<class 'tuple'> <class 'libpysal.cg.shapes.Point'> <class 'float'>
<class 'numpy.ndarray'> <class 'numpy.ndarray'> <class 'numpy.float64'>