pydata/pandas — pull request #3739 by jtratner (2013-06-02 17:17:07+00:00)
Title: Make div use truediv instead of div

This changes the `div()` method in pandas on Python 2.x to always do
`truediv` rather than integer division. Currently, pandas doesn't
respect `from __future__ import division` (it's defined in a file that
doesn't start with the import, so it always does integer division).
`__div__`, `__rdiv__`, and `__idiv__` remain the same, so that the `/`
operator still works as expected. This PR also adds `truediv()` and
`floordiv()` methods to series, panel and frame, plus a test utility
to generate integer series.

This change makes `div()` behave the same way in Python 2 and in
Python 3. It also limits the surprise that comes from using the
future import with pandas in Python 2.

You can see the difference between Python 2 and 3 with the following
snippet:

```

from __future__ import division
import pandas
from pandas.util.testing import assert_frame_equal
df = pandas.DataFrame({"A": range(4)})
result = df.div(4)
expected = df / 4
assert_frame_equal(result, expected)

```

It's not easy (or particularly useful) to detect which division setting
is currently active. Plus, if you were to check it, the actual behavior
would depend on [which file imports `pandas`
first](http://stackoverflow.com/questions/16880552/dynamically-detecting-division-future-import).

There might be too many tests associated with this, so if you'd like me
to slim them down, I'd be happy to do so.

Another alternative would to this patch would be to follow the python
`operator` convention and remove `div()` altogether from Python 3, while
leaving `div()` as it previously was in Python 2; however, I think that
will continue to suprise users.