Gh 36562 typeerror comparison not supported between float and str by ssche · Pull Request #37096 · pandas-dev/pandas (original) (raw)

I started off with trying to fix sort_mixed and removed nans as you suggested and would have loved to use it instead. however the structure of the array doesn't allow for that (we are talking about a 1-d array of tuples, i.e. dtype object, not an N-d array which would allow for all those vector operations to be applicable).

here's the data of values that gets passed in to sort_tuples() when running the test I added:

In[2]: values Out[2]: array([('b', 1), ('b', 2), ('c', 3), ('a', 4), ('b', 5), (nan, 6), ('a', 1), ('c', 1), ('d', 1)], dtype=object) values[0] Out[3]: ('b', 1) values.shape Out[4]: (9,)

I could convert value to a N-d array (and use sort_mixed), but that solution would come with its own overhead costs...

In[5]: 
np.asarray(list(values))
Out[5]: 
array([['b', '1'],
       ['b', '2'],
       ['c', '3'],
       ['a', '4'],
       ['b', '5'],
       ['nan', '6'],
       ['a', '1'],
       ['c', '1'],
       ['d', '1']], dtype='<U3')

your call.