You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When sorting a pandas dataframe by multiple columns and one of the columns contains values of type AffineScalarFunc, the sort failes due to missing __hash__ method.
TypeError: unhashable type: 'AffineScalarFunc'
The Variable type implements a __hash__ method. Therfore it is possible to do it with this type:
As soon as we start calculating, the dataframe no longer contains values of type Variable but of type AffineScalarFunc.
Because of that, sorting multiple columns does no longer work:
I think the derivative ids must be part of the hash to make the has dependent from the derivatives.
Additionally, I think that the nominal and linear part must also be part of the hash to ensure different hashes in case the uncertainty is multiplied with a regular float:
k=ufloat(3, 0.0021)
u=k*2hash(k) !=hash(u) #this should be the case right?
The text was updated successfully, but these errors were encountered:
I thought #184 might help with this but after playing around with the ExtensionArray API I came to the conclusion that it can not. I opened pandas-dev/pandas#58182 regarding that. I feel like if the ExtensionArray subclass knows how to sort its items it should not be necessary for the items to be hashable but the current implementation relies on hashability for tracking which items are equivalent (and sorting by multiple columns only makes sense if some items are equivalent; otherwise you could just sort by a single column). There would need to be an API that sorted with equivalence, like argsort but assigning the same index to items that are equivalent instead of choosing an ordering of them (so the output is not one-to-one reordering of range(len(array))).
When sorting a pandas dataframe by multiple columns and one of the columns contains values of type
AffineScalarFunc
, the sort failes due to missing__hash__
method.The
Variable
type implements a__hash__
method. Therfore it is possible to do it with this type:As soon as we start calculating, the dataframe no longer contains values of type
Variable
but of typeAffineScalarFunc
.Because of that, sorting multiple columns does no longer work:
To enable this functionality, 'AffineScalarFunc' must be hashable.
I think this would be possible by implementing something like this:
I think the derivative ids must be part of the hash to make the has dependent from the derivatives.
Additionally, I think that the nominal and linear part must also be part of the hash to ensure different hashes in case the uncertainty is multiplied with a regular float:
The text was updated successfully, but these errors were encountered: