TypeError: no supported conversion for types: (dtype('float64'), dtype('O'))

2,018 views
Skip to first unread message

网易邮箱

unread,
Apr 14, 2019, 7:13:19 PM4/14/19
to openspa...@googlegroups.com
Hi all,

When I was running the code: mir = pysal.Moran(y, w, permutations = 999), I got the following error: 


  File "<ipython-input-30-f405f4662ccd>", line 1, in <module>
    mir = pysal.Moran(y, w, permutations = 999)

  File "C:\Anaconda\Anaconda3\lib\site-packages\pysal\esda\moran.py", line 151, in __init__
    self.I = self.__calc(self.z)

  File "C:\Anaconda\Anaconda3\lib\site-packages\pysal\esda\moran.py", line 216, in __calc
    zl = slag(self.w, z)

  File "C:\Anaconda\Anaconda3\lib\site-packages\pysal\weights\spatial_lag.py", line 86, in lag_spatial
    return w.sparse * y

  File "C:\Anaconda\Anaconda3\lib\site-packages\scipy\sparse\base.py", line 466, in __mul__
    return self._mul_vector(other)

  File "C:\Anaconda\Anaconda3\lib\site-packages\scipy\sparse\compressed.py", line 456, in _mul_vector
    other.dtype.char))

  File "C:\Anaconda\Anaconda3\lib\site-packages\scipy\sparse\sputils.py", line 60, in upcast_char
    t = upcast(*map(np.dtype, args))

  File "C:\Anaconda\Anaconda3\lib\site-packages\scipy\sparse\sputils.py", line 52, in upcast
    raise TypeError('no supported conversion for types: %r' % (args,))

TypeError: no supported conversion for types: (dtype('float64'), dtype('O'))


I would appreciate if anyone can help me with this. Thank you!

Jay


 

Levi John Wolf

unread,
Apr 15, 2019, 12:40:15 PM4/15/19
to openspa...@googlegroups.com
Without your data, it's impossible to tell. But, the fact that your error is a TypeError during the calculation of the spatial lag, and its message is about finding a conversion between dtype('float64') and dtype('O') (which stands for "object") suggests your y vector isn't a numerical vector. try using y.astype(float)? 
---
Levi John Wolf
Lecturer in Quantitative Human Geography | University of Bristol
Fellow | Center for Spatial Data Science, University of Chicago
Fellow | Alan Turing Institute for Data Science & Machine Learning
Director | Q-Step Program, University of Bristol
ljwolf.org


--
You received this message because you are subscribed to the Google Groups "Openspace List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openspace-lis...@googlegroups.com.
To post to this group, send email to openspa...@googlegroups.com.
Visit this group at https://groups.google.com/group/openspace-list.
For more options, visit https://groups.google.com/d/optout.

网易邮箱

unread,
Apr 19, 2019, 12:06:49 PM4/19/19
to openspa...@googlegroups.com

Thanks for your reply.Please see the attached for the y vector. I tried with y.astype(float), but it did not work. Thank you!
Y.csv

Levi John Wolf

unread,
Apr 26, 2019, 10:16:26 AM4/26/19
to openspa...@googlegroups.com
Hmm, your data can be made into a float. I had no problem doing:

pandas.read_csv('Y.csv').Y.astype(float)

In order for us to help further, you need to provide a reproducible example (code + data that someone else can run in full) for us to understand what's going on. 

---
Levi John Wolf
Lecturer in Quantitative Human Geography | University of Bristol
Fellow | Center for Spatial Data Science, University of Chicago
Fellow | Alan Turing Institute for Data Science & Machine Learning
Director | Q-Step Program, University of Bristol
ljwolf.org

Reply all
Reply to author
Forward
0 new messages