Fixed off-by-one error when trying to cast attribute to ascend

This fixes the bug described in #843