Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: Panel does not preserve DataFrame dtypes #14512

Closed
jzwinck opened this issue Oct 27, 2016 · 3 comments
Closed

BUG: Panel does not preserve DataFrame dtypes #14512

jzwinck opened this issue Oct 27, 2016 · 3 comments

Comments

@jzwinck
Copy link
Contributor

jzwinck commented Oct 27, 2016

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

@jorisvandenbossche
Copy link
Member

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: #13563

@jorisvandenbossche jorisvandenbossche added this to the No action milestone Oct 27, 2016
@jzwinck
Copy link
Contributor Author

jzwinck commented Oct 27, 2016

OK, thanks. If Panel weren't being deprecated I would suggest making this "just work" by default.

@jzwinck jzwinck closed this as completed Oct 27, 2016
@jorisvandenbossche
Copy link
Member

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.

@jreback jreback modified the milestones: No action, won't fix Jul 11, 2017
@TomAugspurger TomAugspurger modified the milestones: won't fix, No action Jul 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants