MCPcopy
hub / github.com/pandas-dev/pandas / test_error_len_mismatch

Function test_error_len_mismatch

pandas/tests/arrays/masked/test_arithmetic.py:192–225  ·  view source on GitHub ↗
(data, all_arithmetic_operators)

Source from the content-addressed store, hash-verified

190
191
192def test_error_len_mismatch(data, all_arithmetic_operators):
193 # operating with a list-like with non-matching length raises
194 data, scalar = data
195 op = tm.get_op_from_name(all_arithmetic_operators)
196
197 other = [scalar] * (len(data) - 1)
198
199 err = ValueError
200 msg = "|".join(
201 [
202 r"operands could not be broadcast together with shapes \(3,\) \(4,\)",
203 r"operands could not be broadcast together with shapes \(4,\) \(3,\)",
204 ]
205 )
206 if data.dtype.kind == "b" and all_arithmetic_operators.strip("_") in [
207 "sub",
208 "rsub",
209 ]:
210 err = TypeError
211 msg = (
212 r"numpy boolean subtract, the `\-` operator, is not supported, use "
213 r"the bitwise_xor, the `\^` operator, or the logical_xor function instead"
214 )
215 elif is_bool_not_implemented(data, all_arithmetic_operators):
216 msg = "operator '.*' not implemented for bool dtypes"
217 err = NotImplementedError
218
219 for val in [other, np.array(other)]:
220 with pytest.raises(err, match=msg):
221 op(data, val)
222
223 s = pd.Series(data)
224 with pytest.raises(err, match=msg):
225 op(s, val)
226
227
228@pytest.mark.parametrize("op", ["__neg__", "__abs__", "__invert__"])

Callers

nothing calls this directly

Calls 7

is_bool_not_implementedFunction · 0.85
opFunction · 0.85
stripMethod · 0.80
get_op_from_nameMethod · 0.45
joinMethod · 0.45
arrayMethod · 0.45
raisesMethod · 0.45

Tested by

no test coverage detected