A small, complete example of the issue
>>> df = pd.DataFrame({'a':[1,2,3], 'b':[True,False,True]})
>>> df.dtypes
a int64
b bool
dtype: object
>>> pl = pd.Panel({'x':df})
>>> pl.x.dtypes
a object
b object
dtype: object
Expected Output
I expected the dtypes of df
and pl.x
to match, the latter was created directly from the former.
Output of pd.show_versions()
INSTALLED VERSIONS
commit: None python: 2.7.12.final.0 python-bits: 64 OS: Linux OS-release: 3.13.0-85-generic machine: x86_64 processor: x86_64 byteorder: little LC_ALL: None LANG: en_US.UTF-8
pandas: 0.18.1
Comment From: jorisvandenbossche
See the docs here: http://pandas.pydata.org/pandas-docs/stable/dsintro.html#from-dict-of-dataframe-objects:
Orient is especially useful for mixed-type DataFrames. If you pass a dict of DataFrame objects with mixed-type columns, all of the data will get upcasted to dtype=object unless you pass orient='minor':
So
In [38]: pl = pd.Panel.from_dict({'x':df}, orient='minor')
In [39]: pl
Out[39]:
<class 'pandas.core.panel.Panel'>
Dimensions: 2 (items) x 3 (major_axis) x 1 (minor_axis)
Items axis: a to b
Major_axis axis: 0 to 2
Minor_axis axis: x to x
In [41]: pl.dtypes
Out[41]:
a int64
b bool
dtype: object
But note what @shoyer said in the other issue, we are planning to deprecate Panels: https://github.com/pandas-dev/pandas/issues/13563
Comment From: jzwinck
OK, thanks. If Panel weren't being deprecated I would suggest making this "just work" by default.
Comment From: jorisvandenbossche
Note that there is no "just work", as using orient='minor'
gives you a different data structure (the axes are different), so it's not a drop in replacement with better dtype handling.