pydata/pandas — pull request #2708 by jreback (2013-01-19 21:27:44+00:00)
Title: ENH/BUG/DOC: allow propgation and coexistance of numeric dtypes

Support for numeric dtype propogation and coexistance in DataFrames. Prior to 0.10.1, numeric dtypes passed to DataFrames were always casted to ``int64`` or ``float64``. Now, if a dtype is passed (either directly via the ``dtype`` keyword, a passed ``ndarray``, or a passed ``Series``, then it will be preserved in DataFrame operations. Furthermore, different numeric dtypes will **NOT** be combined. The following example will give you a taste. This closes GH #622

*It would be really helpful if some users could give this a test run before merging. I have put in test cases for numeric operations, combining with DataFrame and Series, but I am sure there are some corner cases that were missed*

```
In [17]: df1 = DataFrame(randn(8, 1), columns = ['A'], dtype = 'float32')

In [18]: df1
Out[18]:
A
0 -0.007220
1 -0.236432
2 2.427172
3 -0.998639
4 -1.039410
5 0.336029
6 0.832988
7 -0.413241

In [19]: df1.dtypes
Out[19]: A float32

In [20]: df2 = DataFrame(dict( A = Series(randn(8),dtype='float16'), B = Series(randn(8)), C = Series(randn(8),dtype='uint8') ))

In [22]: df2
Out[22]:
A B C
0 1.150391 -1.033296 0
1 0.123047 1.915564 0
2 0.151367 -0.489826 0
3 -0.565430 -0.734238 0
4 -0.352295 -0.451430 0
5 -0.618164 0.673102 255
6 1.554688 0.322035 0
7 0.160767 0.420718 0

In [23]: df2.dtypes
Out[23]:
A float16
B float64
C uint8

In [24]: # here you get some upcasting

In [25]: df3 = df1.reindex_like(df2).fillna(value=0.0) + df2

In [26]: df3
Out[26]:
A B C
0 1.143170 -1.033296 0
1 -0.113385 1.915564 0
2 2.578539 -0.489826 0
3 -1.564069 -0.734238 0
4 -1.391705 -0.451430 0
5 -0.282135 0.673102 255
6 2.387676 0.322035 0
7 -0.252475 0.420718 0

In [27]: df3.dtypes
Out[27]:
A float32
B float64
C float64
```