Skip to content
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

TST: GH30999 address all bare pytest.raises in pandas/tests/arrays/boolean/test_arithmetic.py #38849

Merged
Changes from 4 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
28 changes: 23 additions & 5 deletions pandas/tests/arrays/boolean/test_arithmetic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import operator
import re

import numpy as np
import pytest
Expand Down Expand Up @@ -46,8 +47,11 @@ def test_add_mul(left_array, right_array, opname, exp):


def test_sub(left_array, right_array):
with pytest.raises(TypeError):
# numpy points to ^ operator or logical_xor function instead
msg = re.escape(
Copy link
Contributor

Choose a reason for hiding this comment

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

ok great. yeah these are expected. i don't like the external_ thing because it is not obvious what is happening.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't like it much either but it's what the guidance in the issue says to do. shrug

Copy link
Contributor

Choose a reason for hiding this comment

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

hah, that's why I look at all the PRs :->

"numpy boolean subtract, the `-` operator, is not supported, "
"use the bitwise_xor, the `^` operator, or the logical_xor function instead."
)
with pytest.raises(TypeError, match=msg):
left_array - right_array


Expand Down Expand Up @@ -92,13 +96,27 @@ def test_error_invalid_values(data, all_arithmetic_operators):
ops = getattr(s, op)

# invalid scalars
with pytest.raises(TypeError):
msg = (
"did not contain a loop with signature matching types|"
"BooleanArray cannot perform the operation|"
"not supported for the input types, and the inputs could not be safely coerced "
"to any supported types according to the casting rule ''safe''"
)
with pytest.raises(TypeError, match=msg):
ops("foo")
with pytest.raises(TypeError):
msg = (
r"unsupported operand type\(s\) for|"
"Concatenation operation is not implemented for NumPy arrays"
)
with pytest.raises(TypeError, match=msg):
ops(pd.Timestamp("20180101"))

# invalid array-likes
if op not in ("__mul__", "__rmul__"):
# TODO(extension) numpy's mul with object array sees booleans as numbers
with pytest.raises(TypeError):
msg = (
r"unsupported operand type\(s\) for|can only concatenate str|"
"not all arguments converted during string formatting"
)
with pytest.raises(TypeError, match=msg):
ops(pd.Series("foo", index=s.index))