pydata/pandas — pull request #3162 by danbirken (2013-03-25 00:43:23+00:00)
Title: ENH: Declare a BoolBlock as a NumericBlock

BUG: GH2641 fixes "df.decribe() with boolean column"

Numpy refers to a boolean type as a "numerical type", and both Python
and numpy cast True bools into the value 1 and False bools into the
value 0, so all numpy numerical operations always work.

---------------------------

This basically is to solve this issue, which I always found a bit puzzling:

import pandas

df = pandas.DataFrame({
'int1': [1, 2, 3],
'bool1': [False, False, True],
'bool2': [True, True, False],
})

print df.corr()
# int1
# int1 1

print df[['bool1', 'bool2']].corr()
# bool1 bool2
# bool1 1 -1
# bool2 -1 1

After the change:

df.corr()
# bool1 bool2 int1
# bool1 1.000000 -1.000000 0.866025
# bool2 -1.000000 1.000000 -0.866025
# int1 0.866025 -0.866025 1.000000

This also applies to quite a few other numeric operations on dataframes, which when the dataframe is mixed type defaults to using "is_numeric" to decide which ones to perform the operation on.

I'm not sure how deep the rabbit hole goes for this change and how much stuff it might affect, but all of the tests pass (after of course editing the one that specifically tested this functionality). If there are other potential issues I'd be happy to look into them and make other related fixes.