Skip to content

Commit e3073b5

Browse files
authored
Adjust tests in extension folder for new string option (#56191)
* Adjust tests in extension folder for new string option * Fix typing * Update setitem.py
1 parent a3626f2 commit e3073b5

File tree

7 files changed

+39
-13
lines changed

7 files changed

+39
-13
lines changed

pandas/tests/extension/base/dtype.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,12 @@ def test_check_dtype(self, data):
5959

6060
# check equivalency for using .dtypes
6161
df = pd.DataFrame(
62-
{"A": pd.Series(data, dtype=dtype), "B": data, "C": "foo", "D": 1}
62+
{
63+
"A": pd.Series(data, dtype=dtype),
64+
"B": data,
65+
"C": pd.Series(["foo"] * len(data), dtype=object),
66+
"D": 1,
67+
}
6368
)
6469
result = df.dtypes == str(dtype)
6570
assert np.dtype("int64") != "Int64"

pandas/tests/extension/base/groupby.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@ class BaseGroupbyTests:
2121

2222
def test_grouping_grouper(self, data_for_grouping):
2323
df = pd.DataFrame(
24-
{"A": ["B", "B", None, None, "A", "A", "B", "C"], "B": data_for_grouping}
24+
{
25+
"A": pd.Series(
26+
["B", "B", None, None, "A", "A", "B", "C"], dtype=object
27+
),
28+
"B": data_for_grouping,
29+
}
2530
)
2631
gr1 = df.groupby("A").grouper.groupings[0]
2732
gr2 = df.groupby("B").grouper.groupings[0]

pandas/tests/extension/base/missing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def test_dropna_series(self, data_missing):
4444
tm.assert_series_equal(result, expected)
4545

4646
def test_dropna_frame(self, data_missing):
47-
df = pd.DataFrame({"A": data_missing})
47+
df = pd.DataFrame({"A": data_missing}, columns=pd.Index(["A"], dtype=object))
4848

4949
# defaults
5050
result = df.dropna()

pandas/tests/extension/base/ops.py

+17-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import numpy as np
66
import pytest
77

8+
from pandas._config import using_pyarrow_string_dtype
9+
810
from pandas.core.dtypes.common import is_string_dtype
911

1012
import pandas as pd
@@ -27,13 +29,23 @@ def _get_expected_exception(
2729
# The self.obj_bar_exc pattern isn't great in part because it can depend
2830
# on op_name or dtypes, but we use it here for backward-compatibility.
2931
if op_name in ["__divmod__", "__rdivmod__"]:
30-
return self.divmod_exc
31-
if isinstance(obj, pd.Series) and isinstance(other, pd.Series):
32-
return self.series_array_exc
32+
result = self.divmod_exc
33+
elif isinstance(obj, pd.Series) and isinstance(other, pd.Series):
34+
result = self.series_array_exc
3335
elif isinstance(obj, pd.Series):
34-
return self.series_scalar_exc
36+
result = self.series_scalar_exc
3537
else:
36-
return self.frame_scalar_exc
38+
result = self.frame_scalar_exc
39+
40+
if using_pyarrow_string_dtype() and result is not None:
41+
import pyarrow as pa
42+
43+
result = ( # type: ignore[assignment]
44+
result,
45+
pa.lib.ArrowNotImplementedError,
46+
NotImplementedError,
47+
)
48+
return result
3749

3850
def _cast_pointwise_result(self, op_name: str, obj, other, pointwise_result):
3951
# In _check_op we check that the result of a pointwise operation

pandas/tests/extension/base/setitem.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -351,11 +351,11 @@ def test_setitem_preserves_views(self, data):
351351

352352
def test_setitem_with_expansion_dataframe_column(self, data, full_indexer):
353353
# https://github.com/pandas-dev/pandas/issues/32395
354-
df = expected = pd.DataFrame({"data": pd.Series(data)})
354+
df = expected = pd.DataFrame({0: pd.Series(data)})
355355
result = pd.DataFrame(index=df.index)
356356

357357
key = full_indexer(df)
358-
result.loc[key, "data"] = df["data"]
358+
result.loc[key, 0] = df[0]
359359

360360
tm.assert_frame_equal(result, expected)
361361

pandas/tests/extension/test_categorical.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
import numpy as np
1919
import pytest
2020

21+
from pandas._config import using_pyarrow_string_dtype
22+
2123
import pandas as pd
2224
from pandas import Categorical
2325
import pandas._testing as tm
@@ -100,7 +102,9 @@ def test_contains(self, data, data_missing):
100102
if na_value_obj is na_value:
101103
continue
102104
assert na_value_obj not in data
103-
assert na_value_obj in data_missing # this line differs from super method
105+
# this section suffers from super method
106+
if not using_pyarrow_string_dtype():
107+
assert na_value_obj in data_missing
104108

105109
def test_empty(self, dtype):
106110
cls = dtype.construct_array_type()

pandas/tests/extension/test_numpy.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ def test_series_constructor_scalar_with_index(self, data, dtype):
196196

197197

198198
class TestDtype(BaseNumPyTests, base.BaseDtypeTests):
199-
def test_check_dtype(self, data, request):
199+
def test_check_dtype(self, data, request, using_infer_string):
200200
if data.dtype.numpy_dtype == "object":
201201
request.applymarker(
202202
pytest.mark.xfail(
@@ -429,7 +429,7 @@ def test_setitem_with_expansion_dataframe_column(self, data, full_indexer):
429429
if data.dtype.numpy_dtype != object:
430430
if not isinstance(key, slice) or key != slice(None):
431431
expected = pd.DataFrame({"data": data.to_numpy()})
432-
tm.assert_frame_equal(result, expected)
432+
tm.assert_frame_equal(result, expected, check_column_type=False)
433433

434434

435435
@skip_nested

0 commit comments

Comments
 (0)