wesm/pandas — Issue #377: mixed type dataframe loses type info
Author: CRP
Created: 2011-11-17 17:34:22+00:00
State: open

I have a situation where joining objects of different types creates object where info() and dtypes disagree, and generally all datatypes revert to object:

In [630]: a=DataFrame(['aa','bb','cc','dd','ee'],index=[1,2,3,4,5],columns=['a'])

In [631]: b=DataFrame(randn(5,1),index=[1,2,3,4,5],columns=['b'])

In [632]: a.dtypes
Out[632]: a object

In [633]: b.dtypes
Out[633]: b float64

In [636]: a.info()

Index: 5 entries, 1 to 5
Data columns:
a 5 non-null values
dtypes: object(1)

In [637]: b.info()

Index: 5 entries, 1 to 5
Data columns:
b 5 non-null values
dtypes: float64(1)

In [638]: b['b']
Out[638]:
1 0.182455296775
2 0.341883955748
3 -1.47860506557
4 0.227912752553
5 -0.393452694936
Name: b

In [639]: b['b'].dtype
Out[639]: dtype('float64')

In [640]: a['b']=b['b']

In [641]: a
Out[641]:
a b
1 aa 0.1825
2 bb 0.3419
3 cc -1.479
4 dd 0.2279
5 ee -0.3935

In [642]: a.dtypes
Out[642]:
a object
b object

In [643]: a.info()

Index: 5 entries, 1 to 5
Data columns:
a 5 non-null values
b 5 non-null values
dtypes: float64(1), object(1)
In [644]: