BUG: unstack fails in PeriodIndex

Closes #4342.

Also changed `Categorical` and `PeriodIndex.factorize` to make index sorted like other indexes do.