BUG: Properly read Categorical msgpacks
State: closed

Patches bug in `read_msgpack` in which `Series` categoricals were accidentally being constructed with a non-categorical dtype, resulting in an error.

Closes #14901.

Labels:
name: Categorical
description: Categorical Data Type

Comments:
## [Current coverage](https://codecov.io/gh/pandas-dev/pandas/pull/14918?src=pr) is 84.64% (diff: 100%)
> Merging [#14918](https://codecov.io/gh/pandas-dev/pandas/pull/14918?src=pr) into [master](https://codecov.io/gh/pandas-dev/pandas/branch/master?src=pr) will decrease coverage by **<.01%**

```diff
@@             master     #14918   diff @@
==========================================
  Files           144        144          
  Lines         51023      51021     -2   
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
- Hits          43190      43187     -3   
- Misses         7833       7834     +1   
  Partials          0          0          
```

> Powered by [Codecov](https://codecov.io?src=pr). Last update [1678f14...b823ebe](https://codecov.io/gh/pandas-dev/pandas/compare/1678f147cfa4951022076d8a30331e1ca2b9947c...b823ebe67f01e517e3e4d26fcc0c2aa6b86ec378?src=pr)
ok looks reasonable. I haven't checked, but do we have sufficient tz-aware tests for series? if so then lgtm.
@jreback : Yes, we do.  That's why I realized we couldn't just pass in `pd_dtype` all the time.
that's fine. as a followup (*maybe*). It might be cleaner to do all of the tz stuff *in* unconvert/convert (rather than doing it in each individual method).?
Perhaps, though I'm not sure how necessary that is for now.
@jreback : Everything is green.  Ready to merge if there are no other concerns.
ok, this is an actual bug in construction, where we construct incorrectly, then compensate in other places. removing this makes this just work: https://github.com/jreback/pandas/commit/24f78cd33891fd40d1e1ab5e7ee5cfd9d66539fa

here's the bug. I'll make a separate issue, then you can rebase on top of the fix.

In master
```
In [1]: s = Series(pd.date_range('20130101',periods=3,tz='US/Eastern'))

In [2]: s
Out[2]: 
0   2013-01-01 00:00:00-05:00
1   2013-01-02 00:00:00-05:00
2   2013-01-03 00:00:00-05:00
dtype: datetime64[ns, US/Eastern]

In [3]: Series(s,dtype=s.dtype)
Out[3]: 
0   2013-01-01 00:00:00-05:00
1   2013-01-02 00:00:00-05:00
2   2013-01-03 00:00:00-05:00
dtype: datetime64[ns, US/Eastern]

In [5]: Series(s.dt.tz_convert('UTC'),dtype=s.dtype)
Out[5]: 
0   2013-01-01 00:00:00-05:00
1   2013-01-02 00:00:00-05:00
2   2013-01-03 00:00:00-05:00
dtype: datetime64[ns, US/Eastern]
In [6]: Series(s.values,dtype=s.dtype)
Out[6]: 
0   2013-01-01 05:00:00-05:00
1   2013-01-02 05:00:00-05:00
2   2013-01-03 05:00:00-05:00
dtype: datetime64[ns, US/Eastern]
```

with commit
```
In [1]: s = Series(pd.date_range('20130101',periods=3,tz='US/Eastern'))

In [2]: Series(s,dtype=s.dtype)
Out[2]: 
0   2013-01-01 00:00:00-05:00
1   2013-01-02 00:00:00-05:00
2   2013-01-03 00:00:00-05:00
dtype: datetime64[ns, US/Eastern]

In [3]: Series(s.dt.tz_convert('UTC'),dtype=s.dtype)
Out[3]: 
0   2013-01-01 00:00:00-05:00
1   2013-01-02 00:00:00-05:00
2   2013-01-03 00:00:00-05:00
dtype: datetime64[ns, US/Eastern]

In [4]: Series(s.values,dtype=s.dtype)
Out[4]: 
0   2013-01-01 00:00:00-05:00
1   2013-01-02 00:00:00-05:00
2   2013-01-03 00:00:00-05:00
dtype: datetime64[ns, US/Eastern]
```

see PR https://github.com/pandas-dev/pandas/pull/14928
ok #14928 was merged. go ahead and rebase (you need to the code mostly back to what it was)
@jreback : Change is nice and compact now and passing.  Ready to merge if there are no other concerns.
thanks!