My first reaction was the same as theducks: upgrade calibre. But, as I haven't touched that area of the code for a while, I had a look and couldn't think of how you could ever get that error there. But, then I noticed the mention of the ratings column.
The error happens when the column used for the shelves is a number. It will be a fairly easy fix, but could you raise a
bug? That way I won't forget.