Skip to content

BUG: Consistent division by zero behavior for Index/Series #27321

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 29 commits into from
Jul 11, 2019
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
6bd4fb1
TST: parametrize tests
jbrockmendel Jul 7, 2019
d9943be
for loop, preparing to parametrize
jbrockmendel Jul 7, 2019
eb8b6d7
parametrize/fixturize mix
jbrockmendel Jul 7, 2019
3edebac
fixture for op
jbrockmendel Jul 7, 2019
eb60fc3
blackify
jbrockmendel Jul 7, 2019
3cf8b1e
parametrize more
jbrockmendel Jul 7, 2019
c34a9cc
param scalar
jbrockmendel Jul 7, 2019
158b003
Merge branch 'master' of https://github.com/pandas-dev/pandas into sp…
jbrockmendel Jul 7, 2019
b59b81a
docstring, xfail
jbrockmendel Jul 7, 2019
f085d6b
remove defunct comment
jbrockmendel Jul 7, 2019
339ed84
Merge branch 'master' of https://github.com/pandas-dev/pandas into sp…
jbrockmendel Jul 8, 2019
f03bd93
implement all_arithmetic_functions fixture
jbrockmendel Jul 8, 2019
cd2f564
isort fixup
jbrockmendel Jul 9, 2019
e362a08
check early for non-scalar default_fill_value
jbrockmendel Jul 9, 2019
7c6e127
try to bring dispatch_fill_zeros, dispatch_mnissing in sync, remove u…
jbrockmendel Jul 8, 2019
97611c3
standardize calls
jbrockmendel Jul 8, 2019
c30b40c
use pandas convention for divmod
jbrockmendel Jul 9, 2019
1ed12b8
remove comment
jbrockmendel Jul 9, 2019
45ffbc2
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Jul 10, 2019
591eaaa
patch sparse and IntegerArray tests
jbrockmendel Jul 10, 2019
2841be0
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Jul 10, 2019
518e2e9
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Jul 10, 2019
2580048
fixup for docs
jbrockmendel Jul 10, 2019
f440c59
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Jul 10, 2019
188ac99
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Jul 11, 2019
6b411c4
requested comments
jbrockmendel Jul 11, 2019
77c2383
whatsnew
jbrockmendel Jul 11, 2019
7b8880c
Merge branch 'master' of https://github.com/pandas-dev/pandas into di…
jbrockmendel Jul 11, 2019
14010c8
dummy commit to force ci
jbrockmendel Jul 11, 2019
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
Prev Previous commit
Next Next commit
for loop, preparing to parametrize
  • Loading branch information
jbrockmendel committed Jul 7, 2019
commit d9943be389e412f93ed3cb35f5766430174cda32
80 changes: 31 additions & 49 deletions pandas/tests/arrays/sparse/test_arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import pytest

import pandas as pd
from pandas.core import ops
from pandas.core.sparse.api import SparseDtype
import pandas.util.testing as tm

Expand All @@ -28,55 +29,36 @@ def _check_numeric_ops(self, a, b, a_dense, b_dense):
# Unfortunately, trying to wrap the computation of each expected
# value is with np.errstate() is too tedious.

# sparse & sparse
self._assert((a + b).to_dense(), a_dense + b_dense)
self._assert((b + a).to_dense(), b_dense + a_dense)

self._assert((a - b).to_dense(), a_dense - b_dense)
self._assert((b - a).to_dense(), b_dense - a_dense)

self._assert((a * b).to_dense(), a_dense * b_dense)
self._assert((b * a).to_dense(), b_dense * a_dense)

# pandas uses future division
self._assert((a / b).to_dense(), a_dense * 1.0 / b_dense)
self._assert((b / a).to_dense(), b_dense * 1.0 / a_dense)

# ToDo: FIXME in GH 13843
if not (self._base == pd.Series and a.dtype.subtype == np.dtype("int64")):
self._assert((a // b).to_dense(), a_dense // b_dense)
self._assert((b // a).to_dense(), b_dense // a_dense)

self._assert((a % b).to_dense(), a_dense % b_dense)
self._assert((b % a).to_dense(), b_dense % a_dense)

self._assert((a ** b).to_dense(), a_dense ** b_dense)
self._assert((b ** a).to_dense(), b_dense ** a_dense)

# sparse & dense
self._assert((a + b_dense).to_dense(), a_dense + b_dense)
self._assert((b_dense + a).to_dense(), b_dense + a_dense)

self._assert((a - b_dense).to_dense(), a_dense - b_dense)
self._assert((b_dense - a).to_dense(), b_dense - a_dense)

self._assert((a * b_dense).to_dense(), a_dense * b_dense)
self._assert((b_dense * a).to_dense(), b_dense * a_dense)

# pandas uses future division
self._assert((a / b_dense).to_dense(), a_dense * 1.0 / b_dense)
self._assert((b_dense / a).to_dense(), b_dense * 1.0 / a_dense)

# ToDo: FIXME in GH 13843
if not (self._base == pd.Series and a.dtype.subtype == np.dtype("int64")):
self._assert((a // b_dense).to_dense(), a_dense // b_dense)
self._assert((b_dense // a).to_dense(), b_dense // a_dense)

self._assert((a % b_dense).to_dense(), a_dense % b_dense)
self._assert((b_dense % a).to_dense(), b_dense % a_dense)

self._assert((a ** b_dense).to_dense(), a_dense ** b_dense)
self._assert((b_dense ** a).to_dense(), b_dense ** a_dense)
for mix in [True, False]:
# True --> sparse & dense
# False --> sparse & sparse

# sparse & sparse
for op in [operator.add, ops.radd,
operator.sub, ops.rsub,
operator.mul, ops.rmul,
operator.truediv, ops.rtruediv,
operator.floordiv, ops.rfloordiv,
operator.mod, ops.rmod,
operator.pow, ops.rpow]:

if op in [operator.floordiv, ops.rfloordiv]:
# FIXME: GH#13843
if (self._base == pd.Series and a.dtype.subtype == np.dtype("int64")):
continue

if mix:
result = op(a, b_dense).to_dense()
else:
result = op(a, b).to_dense()

if op in [operator.truediv, ops.rtruediv]:
# pandas uses future division
expected = op(a_dense * 1.0, b_dense)
else:
expected = op(a_dense, b_dense)

self._assert(result, expected)

def _check_bool_result(self, res):
assert isinstance(res, self._klass)
Expand Down