BUG: Fix TypeError raised in libreduction
This is a PITA and I'm not 100% happy with the solution here, open to suggestions.

There is a call to `util.get_value_at(labels, i)` that raises `TypeError` if `labels` is not an `ndarray`.  This fixes that by checking for non-ndarray and handling that case correctly.

There is _also_ a case in master where we get an `UnboundLocalError` by referencing `result` before it is assigned.  This patches that to raise a `ValueError` instead, _but_ AFAICT fixing the ndarray bug above made it so that the UnboundLocalError case is no longer reached in the tests.  i.e. this change is definitely more correct, but we don't have a test case specific to it.

I'm also not wild about the specific exception-catching on L297-307 in core.apply, but don't see a viable alternative.  Suggestions welcome.