Skip to content

TST: Add tests for num-bool coercion #28966

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
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
20 changes: 20 additions & 0 deletions pandas/tests/arithmetic/test_numeric.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import pandas as pd
from pandas import Index, Series, Timedelta, TimedeltaIndex
from pandas.conftest import all_arithmetic_functions
from pandas.core import ops
import pandas.util.testing as tm

Expand Down Expand Up @@ -72,6 +73,25 @@ def test_compare_invalid(self):
tm.assert_series_equal(a / b, 1 / (b / a))


class TestNumericArraylikeArithmeticWithBool:
@pytest.mark.parametrize("num", [1.0, 1])
def test_array_like_bool_and_num_op_coerce(
self, num, all_arithmetic_functions, box_with_array
):
# GH 18549
op = all_arithmetic_functions
expected = [op(num, num)]
expected = tm.box_expected(expected, box_with_array)
bool_box = tm.box_expected([True], box_with_array)
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rather than catching you should return on the operators that we don't want to test, making this more explicit

tm.assert_equal(expected, op(bool_box, num))
tm.assert_equal(expected, op(num, bool_box))
except TypeError:
# Some operators may not be supported and that's okay. If supported
# we should should see the operation coerce to a numeric value.
pass


# ------------------------------------------------------------------
# Numeric dtypes Arithmetic with Datetime/Timedelta Scalar

Expand Down