Error in Resultprocessing

Dear community,

I have an energy system that can be optimized (not infeasible).
When i call:

model.resutls()

I get the error:

Traceback (most recent call last):

  File "C:\Anaconda\lib\site-packages\pandas\core\algorithms.py", line 2066, in safe_sort
    sorter = values.argsort()

TypeError: '<' not supported between instances of 'int' and 'str'


During handling of the above exception, another exception occurred:

Traceback (most recent call last):

  File "C:\Anaconda\lib\site-packages\pandas\core\arrays\categorical.py", line 343, in __init__
    codes, categories = factorize(values, sort=True)

  File "C:\Anaconda\lib\site-packages\pandas\core\algorithms.py", line 682, in factorize
    uniques, codes = safe_sort(

  File "C:\Anaconda\lib\site-packages\pandas\core\algorithms.py", line 2070, in safe_sort
    ordered = sort_mixed(values)

  File "C:\Anaconda\lib\site-packages\pandas\core\algorithms.py", line 2053, in sort_mixed
    nums = np.sort(values[~str_pos])

  File "<__array_function__ internals>", line 5, in sort

  File "C:\Anaconda\lib\site-packages\numpy\core\fromnumeric.py", line 991, in sort
    a.sort(axis=axis, kind=kind, order=order)

TypeError: '<' not supported between instances of 'int' and 'str'


The above exception was the direct cause of the following exception:

Traceback (most recent call last):

  File "<ipython-input-19-d7475e37b200>", line 1, in <module>
    saka.results()

  File "C:\Anaconda\lib\site-packages\oemof\solph\models.py", line 179, in results
    return processing.results(self)

  File "C:\Anaconda\lib\site-packages\oemof\solph\processing.py", line 125, in results
    df = create_dataframe(om)

  File "C:\Anaconda\lib\site-packages\oemof\solph\processing.py", line 107, in create_dataframe
    df = df.sort_values(["oemof_tuple", "timestep"], ascending=[True, True])

  File "C:\Anaconda\lib\site-packages\pandas\core\frame.py", line 5286, in sort_values
    indexer = lexsort_indexer(

  File "C:\Anaconda\lib\site-packages\pandas\core\sorting.py", line 229, in lexsort_indexer
    cat = Categorical(k, ordered=True)

  File "C:\Anaconda\lib\site-packages\pandas\core\arrays\categorical.py", line 349, in __init__
    raise TypeError(

TypeError: 'values' is not ordered, please explicitly specify the categories order by passing in a categories argument.

Strange is that i do net get this error everytime. So it can happen that when I run the same model twice, one time I get the error and the other time not.

Has anyone experienced a similar problem?

Best,
Matthias

Hi @mal_mat,

I understand the core problem but currently I am not sure why that TypeError occurs. Could you provide a example code that (sometimes) produces the error? That would simplify tracking it down.

(In general, that it not happens all the time means that there is some randomness in the program. At the moment, the only random thing that comes to my mind is the creation of labels if you do not provide any.)

Cheers,
Patrik

1 Like

Hi Patrik,

I have some Parameters as Upper Limits in Constraints that are set different in each timestep (stochastically). These are the differences.

I get that this must cause the different behaviour, but I do not get why the model is feasible and different constraints cause this type error.

Best,
Matthias

The error is telling you that in an array that pandas is trying to sort, you have both strings and ints and it doesn’t know how to compare them.

A guess: are you bringing some data in from a file or similar that differs between runs, perhaps based on a random selection variable? My guess is that you have a number stored as a string somewhere.