Skip to content

Fix arithmetic test folder for arrow string option #56122

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 1 commit into from
Nov 26, 2023
Merged
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
29 changes: 22 additions & 7 deletions pandas/tests/arithmetic/test_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import numpy as np
import pytest

from pandas._config import using_pyarrow_string_dtype

import pandas as pd
from pandas import (
Series,
Expand Down Expand Up @@ -172,7 +174,12 @@ def test_objarr_add_invalid(self, op, box_with_array):

obj_ser = tm.box_expected(obj_ser, box)
msg = "|".join(
["can only concatenate str", "unsupported operand type", "must be str"]
[
"can only concatenate str",
"unsupported operand type",
"must be str",
"has no kernel",
]
)
with pytest.raises(Exception, match=msg):
op(obj_ser, 1)
Expand Down Expand Up @@ -290,6 +297,7 @@ def test_iadd_string(self):
index += "_x"
assert "a_x" in index

@pytest.mark.xfail(using_pyarrow_string_dtype(), reason="add doesn't work")
def test_add(self):
index = tm.makeStringIndex(100)
expected = pd.Index(index.values * 2)
Expand All @@ -304,17 +312,24 @@ def test_add(self):
expected = pd.Index(["1a", "1b", "1c"])
tm.assert_index_equal("1" + index, expected)

def test_sub_fail(self):
def test_sub_fail(self, using_infer_string):
index = tm.makeStringIndex(100)

msg = "unsupported operand type|Cannot broadcast"
with pytest.raises(TypeError, match=msg):
if using_infer_string:
import pyarrow as pa

err = pa.lib.ArrowNotImplementedError
msg = "has no kernel"
else:
err = TypeError
msg = "unsupported operand type|Cannot broadcast"
with pytest.raises(err, match=msg):
index - "a"
with pytest.raises(TypeError, match=msg):
with pytest.raises(err, match=msg):
index - index
with pytest.raises(TypeError, match=msg):
with pytest.raises(err, match=msg):
index - index.tolist()
with pytest.raises(TypeError, match=msg):
with pytest.raises(err, match=msg):
index.tolist() - index

def test_sub_object(self):
Expand Down