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
Show file tree
Hide file tree
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
implement all_arithmetic_functions fixture
  • Loading branch information
jbrockmendel committed Jul 8, 2019
commit f03bd93d21609bea4d914cb7ee390f643b803d53
30 changes: 30 additions & 0 deletions pandas/conftest.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from datetime import date, time, timedelta, timezone
from decimal import Decimal
import operator
import os

from dateutil.tz import tzlocal, tzutc
Expand All @@ -12,6 +13,7 @@
import pandas.util._test_decorators as td

import pandas as pd
from pandas.core import ops
from pandas import DataFrame
import pandas.util.testing as tm

Expand Down Expand Up @@ -163,6 +165,34 @@ def all_arithmetic_operators(request):
return request.param


@pytest.fixture(
params=[
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,
]
)
def all_arithmetic_functions(request):
"""
Fixture for operator and roperator arithmetic functions.

Note: This includes divmod and rdivmod, whereas all_arithmetic_operators
does not.
"""
return request.param


_all_numeric_reductions = [
"sum",
"max",
Expand Down
50 changes: 21 additions & 29 deletions pandas/tests/arrays/sparse/test_arithmetics.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,28 +21,6 @@ def mix(request):
return request.param


@pytest.fixture(
params=[
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,
]
)
def op(request):
return request.param


@pytest.mark.filterwarnings("ignore:Sparse:FutureWarning")
@pytest.mark.filterwarnings("ignore:Series.to_sparse:FutureWarning")
class TestSparseArrayArithmetics:
Expand Down Expand Up @@ -138,7 +116,10 @@ def _check_logical_ops(self, a, b, a_dense, b_dense):

@pytest.mark.parametrize("scalar", [0, 1, 3])
@pytest.mark.parametrize("fill_value", [None, 0, 2])
def test_float_scalar(self, kind, mix, op, fill_value, scalar):
def test_float_scalar(
self, kind, mix, all_arithmetic_functions, fill_value, scalar
):
op = all_arithmetic_functions
values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan])

a = self._klass(values, kind=kind, fill_value=fill_value)
Expand All @@ -162,8 +143,9 @@ def test_float_scalar_comparison(self, kind):
self._check_comparison_ops(a, 0, values, 0)
self._check_comparison_ops(a, 3, values, 3)

def test_float_same_index(self, kind, mix, op):
def test_float_same_index(self, kind, mix, all_arithmetic_functions):
# when sp_index are the same
op = all_arithmetic_functions
values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan])
rvalues = self._base([np.nan, 2, 3, 4, np.nan, 0, 1, 3, 2, np.nan])

Expand Down Expand Up @@ -194,7 +176,9 @@ def test_float_same_index_comparison(self, kind):
b = self._klass(rvalues, kind=kind, fill_value=0)
self._check_comparison_ops(a, b, values, rvalues)

def test_float_array(self, kind, mix, op):
def test_float_array(self, kind, mix, all_arithmetic_functions):
op = all_arithmetic_functions

values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan])
rvalues = self._base([2, np.nan, 2, 3, np.nan, 0, 1, 5, 2, np.nan])

Expand All @@ -215,7 +199,9 @@ def test_float_array(self, kind, mix, op):
b = self._klass(rvalues, kind=kind, fill_value=2)
self._check_numeric_ops(a, b, values, rvalues, mix, op)

def test_float_array_different_kind(self, mix, op):
def test_float_array_different_kind(self, mix, all_arithmetic_functions):
op = all_arithmetic_functions

values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan])
rvalues = self._base([2, np.nan, 2, 3, np.nan, 0, 1, 5, 2, np.nan])

Expand Down Expand Up @@ -257,7 +243,9 @@ def test_float_array_comparison(self, kind):
b = self._klass(rvalues, kind=kind, fill_value=2)
self._check_comparison_ops(a, b, values, rvalues)

def test_int_array(self, kind, mix, op):
def test_int_array(self, kind, mix, all_arithmetic_functions):
op = all_arithmetic_functions

# have to specify dtype explicitly until fixing GH 667
dtype = np.int64

Expand Down Expand Up @@ -337,7 +325,9 @@ def test_bool_array_logical(self, kind, fill_value):
b = self._klass(rvalues, kind=kind, dtype=np.bool, fill_value=fill_value)
self._check_logical_ops(a, b, values, rvalues)

def test_mixed_array_float_int(self, kind, mix, op):
def test_mixed_array_float_int(self, kind, mix, all_arithmetic_functions):
op = all_arithmetic_functions

rdtype = "int64"

values = self._base([np.nan, 1, 2, 0, np.nan, 0, 1, 2, 1, np.nan])
Expand Down Expand Up @@ -403,7 +393,9 @@ class TestSparseSeriesArithmetic(TestSparseArrayArithmetics):
def _assert(self, a, b):
tm.assert_series_equal(a, b)

def test_alignment(self, mix, op):
def test_alignment(self, mix, all_arithmetic_functions):
op = all_arithmetic_functions

da = pd.Series(np.arange(4))
db = pd.Series(np.arange(4), index=[1, 2, 3, 4])

Expand Down