BUG: Categoricals shouldn't allow non-strings when object dtype is passed (#13919)
State: closed

- [ ] closes #13919
- [ ] tests added / passed
- [x] passes `git diff upstream/master | flake8 --diff`
- [x] whatsnew entry

**Why this change is needed:** Categorical variables are by definition single types, so to allow them to take on  different types of values is misleading. Object dtypes should only be allowed when ALL strings or ALL periods are passed (due to the way there are handled internally).

**The result of this PR** will raise a `TypeError` when a categorical is created that has an object dtype but doesn't contain all `string` or all `period` values. 


Labels:
name: Dtype Conversions
description: Unexpected or buggy dtype conversions
name: API Design
name: Error Reporting
description: Incorrect or improved errors from pandas
name: Categorical
description: Categorical Data Type

Comments:
you already have #14027 you don't need a 2nd
just push to the original
ok for this one

This change will always fail to build because it conflicts with the way `MultiIndex.from_arrays`, `MultiIndex.from_tuples`, and `MultiIndex.from_product` are implemented. 

Regardless of the way I implement it, ensuring that Categoricals aren't mixed dtypes will always raise when a MultiIndex is constructed from some listlike with mixed dtypes :\

Do I disregard this and keep working/pushing to this PR?

you would have 2 show an example 

@jreback Show an ex. here? the docs? add a test and assert it raises?
If here, then

```
MultiIndex.from_arrays([[1 ,2], ['foo',  3]])
```

will raise because [this](https://github.com/pydata/pandas/blob/master/pandas/indexes/multi.py#L867)

https://github.com/pydata/pandas/pull/13854 refactors those routines

build your fix on top of this PR

The refactored routines still call `Categorical.from_array` [(here)](https://github.com/pydata/pandas/pull/13854/files#diff-d295fd3c83b52dcaabdf13701ead1a41R1990), so using mixed dtypes with `MultiIndex.from_arrays` would still raise unfortunately. 

can you rebase / update?

@jreback I don't think this will work. Even though #13854 refactored `MultiIndex.from_arrays`, it still creates categoricals, potentially of mixed types. So i will be closing this, as I can't think of a clean way to get around this :\

Categoricals should never be mixed type 
not sure why you think that the constructor creates them

if you have an example pls show it

@jreback If I call

```
MultiIndex.from_arrays([[1 ,2], ['foo',  3]])
```

`_factorize_from_iterable` will create a `Categorical` from ['foo', 3]  [here](https://github.com/pydata/pandas/blob/master/pandas/core/categorical.py#L1997)

I'm definitely misunderstanding something here. In reference to your first comment in #13919, shouldn't that raise on creation?

that should raise its not valid 

@jreback So back to my original problem. I can't think of a clean way to allow `MultiIndex.from_arrays` to exist, while simultaneously blocking the creation of `Categoricals` with mixed dtypes. 

My immediate idea is to pass in some parameter to indicate that a MultiIndex is being created, but as you said in another one of my PRs -- you can't pass in an extra parameter to determine state

@jreback from a `MultiIndex.from_arrays` point of vue, such mixed types is perfectly valid IMO

Personally, I don't think we should check this at Categorical construction, I would rather check for this in the hdf code itself.