8000 BUG: Fix __truediv__ numexpr error by jtratner · Pull Request #3764 · pandas-dev/pandas · GitHub
[go: up one dir, main page]

Skip to content

BUG: Fix __truediv__ numexpr error #3764

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

Merged
merged 5 commits into from
Jun 18, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
TST: Add numexpr arithmetic tests.
Only add 'div' if not python 3

Also checks dtype in test cases for series
  • Loading branch information
jtratner committed Jun 18, 2013
commit 273946af6e5b0a8a091fd855144c9d885538bd6a
3 changes: 3 additions & 0 deletions RELEASE.rst
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ pandas 0.11.1
not converting dtypes (GH3911_)
- Fixed a bug where ``DataFrame.replace`` with a compiled regular expression
in the ``to_replace`` argument wasn't working (GH3907_)
- Fixed ``__truediv__`` in Python 2.7 with ``numexpr`` installed to actually do true division when dividing
two integer arrays with at least 10000 cells total (GH3764_)

.. _GH3164: https://github.com/pydata/pandas/issues/3164
.. _GH2786: https://github.com/pydata/pandas/issues/2786
Expand Down Expand Up @@ -351,6 +353,7 @@ pandas 0.11.1
.. _GH3907: https://github.com/pydata/pandas/issues/3907
.. _GH3911: https://github.com/pydata/pandas/issues/3911
.. _GH3912: https://github.com/pydata/pandas/issues/3912
.. _GH3764: https://github.com/pydata/pandas/issues/3764

pandas 0.11.0
=============
Expand Down
50 changes: 49 additions & 1 deletion pandas/tests/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
_frame2 = DataFrame(np.random.randn(100, 4), columns = list('ABCD'), dtype='float64')
_mixed = DataFrame({ 'A' : _frame['A'].copy(), 'B' : _frame['B'].astype('float32'), 'C' : _frame['C'].astype('int64'), 'D' : _frame['D'].astype('int32') })
_mixed2 = DataFrame({ 'A' : _frame2['A'].copy(), 'B' : _frame2['B'].astype('float32'), 'C' : _frame2['C'].astype('int64'), 'D' : _frame2['D'].astype('int32') })
_integer = DataFrame(np.random.randint(1, 100, size=(10001, 4)), columns = list('ABCD'), dtype='int64')

class TestExpressions(unittest.TestCase):

Expand All @@ -41,7 +42,54 @@ def setUp(self):
self.frame2 = _frame2.copy()
self.mixed = _mixed.copy()
self.mixed2 = _mixed2.copy()

self.integer = _integer.copy()
self._MIN_ELEMENTS = expr._MIN_ELEMENTS

def tearDown(self):
expr._MIN_ELEMENTS = self._MIN_ELEMENTS

@nose.tools.nottest
def run_arithmetic_test(self, df, assert_func, check_dtype=False):
expr._MIN_ELEMENTS = 0
operations = ['add', 'sub', 'mul', 'truediv']
if not py3compat.PY3:
operations.append('div')
for arith in operations:
op = getattr(operator, arith)
expr.set_use_numexpr(False)
expected = op(df, df)
expr.set_use_numexpr(True)
result = op(df, df)
try:
if check_dtype:
if arith == 'div':
assert expected.dtype.kind == df.dtype.kind
if arith == 'truediv':
assert expected.dtype.kind == 'f'
assert_func(expected, result)
except Exception:
print("Failed test with operator %r" % op.__name__)
raise

def test_integer_arithmetic(self):
self.run_arithmetic_test(self.integer, assert_frame_equal)
self.run_arithmetic_test(self.integer.icol(0), assert_series_equal,
check_dtype=True)

def test_float_arithemtic(self):
self.run_arithmetic_test(self.frame, assert_frame_equal)
self.run_arithmetic_test(self.frame.icol(0), assert_series_equal,
check_dtype=True)

def test_mixed_arithmetic(self):
self.run_arithmetic_test(self.mixed, assert_frame_equal)
for col in self.mixed.columns:
self.run_arithmetic_test(self.mixed[col], assert_series_equal)

def test_integer_with_zeros(self):
self.integer *= np.random.randint(0, 2, size=np.shape(self.integer))
self.run_arithmetic_test(self.integer, assert_frame_equal)
self.run_arithmetic_test(self.integer.icol(0), assert_series_equal)

def test_invalid(self):

Expand Down
0