BUG: stats: Refactor argument validation to avoid a unicode issue.

Fixes the handling of a unicode argument to the binned statistics
functions.

Closes gh-4026.