Skip to content

Commit 4d38764

Browse files
authored
CLN: Replace confusing brackets with backticks (#54091)
* Replace confusing brackets with backticks There are some errors which read like: > only list-like objects are allowed to be passed to isin(), you > passed a [str] (note how the type `str` is enclosed in square brackets) This is potentially confusing, since some languages use notation like `[TYPE]` to denote a list of TYPE objects. So the user could read the error message saying they can't use `[str]`, but intepret `[str]` to mean "a list of str objects". This commit removes the possibility of confusion by using backticks instead of square brackets. * Fix: also update some missed tests
1 parent 0a720b6 commit 4d38764

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

pandas/core/algorithms.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -470,12 +470,12 @@ def isin(comps: ListLike, values: ListLike) -> npt.NDArray[np.bool_]:
470470
if not is_list_like(comps):
471471
raise TypeError(
472472
"only list-like objects are allowed to be passed "
473-
f"to isin(), you passed a [{type(comps).__name__}]"
473+
f"to isin(), you passed a `{type(comps).__name__}`"
474474
)
475475
if not is_list_like(values):
476476
raise TypeError(
477477
"only list-like objects are allowed to be passed "
478-
f"to isin(), you passed a [{type(values).__name__}]"
478+
f"to isin(), you passed a `{type(values).__name__}`"
479479
)
480480

481481
if not isinstance(values, (ABCIndex, ABCSeries, ABCExtensionArray, np.ndarray)):

pandas/core/arrays/categorical.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ def isin(self, values) -> npt.NDArray[np.bool_]:
25812581
values_type = type(values).__name__
25822582
raise TypeError(
25832583
"only list-like objects are allowed to be passed "
2584-
f"to isin(), you passed a [{values_type}]"
2584+
f"to isin(), you passed a `{values_type}`"
25852585
)
25862586
values = sanitize_array(values, None, None)
25872587
null_mask = np.asarray(isna(values))

pandas/tests/computation/test_eval.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def test_simple_cmp_ops(self, cmp_op, lhs, rhs, engine, parser):
158158
[
159159
r"only list-like( or dict-like)? objects are allowed to be "
160160
r"passed to (DataFrame\.)?isin\(\), you passed a "
161-
r"(\[|')bool(\]|')",
161+
r"(`|')bool(`|')",
162162
"argument of type 'bool' is not iterable",
163163
]
164164
)
@@ -203,7 +203,7 @@ def test_compound_invert_op(self, op, lhs, rhs, request, engine, parser):
203203
[
204204
r"only list-like( or dict-like)? objects are allowed to be "
205205
r"passed to (DataFrame\.)?isin\(\), you passed a "
206-
r"(\[|')float(\]|')",
206+
r"(`|')float(`|')",
207207
"argument of type 'float' is not iterable",
208208
]
209209
)

pandas/tests/series/methods/test_isin.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def test_isin_with_string_scalar(self):
3434
s = Series(["A", "B", "C", "a", "B", "B", "A", "C"])
3535
msg = (
3636
r"only list-like objects are allowed to be passed to isin\(\), "
37-
r"you passed a \[str\]"
37+
r"you passed a `str`"
3838
)
3939
with pytest.raises(TypeError, match=msg):
4040
s.isin("a")

pandas/tests/test_algos.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ class TestIsin:
888888
def test_invalid(self):
889889
msg = (
890890
r"only list-like objects are allowed to be passed to isin\(\), "
891-
r"you passed a \[int\]"
891+
r"you passed a `int`"
892892
)
893893
with pytest.raises(TypeError, match=msg):
894894
algos.isin(1, 1)

0 commit comments

Comments
 (0)