Skip to content

Commit 762b61d

Browse files
authored
Adjust tests in util folder for new string option (pandas-dev#56181)
1 parent 09fb8e5 commit 762b61d

File tree

3 files changed

+42
-16
lines changed

3 files changed

+42
-16
lines changed

pandas/tests/util/test_assert_frame_equal.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,16 @@ def test_empty_dtypes(check_dtype):
109109

110110

111111
@pytest.mark.parametrize("check_like", [True, False])
112-
def test_frame_equal_index_mismatch(check_like, obj_fixture):
112+
def test_frame_equal_index_mismatch(check_like, obj_fixture, using_infer_string):
113+
if using_infer_string:
114+
dtype = "string"
115+
else:
116+
dtype = "object"
113117
msg = f"""{obj_fixture}\\.index are different
114118
115119
{obj_fixture}\\.index values are different \\(33\\.33333 %\\)
116-
\\[left\\]: Index\\(\\['a', 'b', 'c'\\], dtype='object'\\)
117-
\\[right\\]: Index\\(\\['a', 'b', 'd'\\], dtype='object'\\)
120+
\\[left\\]: Index\\(\\['a', 'b', 'c'\\], dtype='{dtype}'\\)
121+
\\[right\\]: Index\\(\\['a', 'b', 'd'\\], dtype='{dtype}'\\)
118122
At positional index 2, first diff: c != d"""
119123

120124
df1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "c"])
@@ -125,12 +129,16 @@ def test_frame_equal_index_mismatch(check_like, obj_fixture):
125129

126130

127131
@pytest.mark.parametrize("check_like", [True, False])
128-
def test_frame_equal_columns_mismatch(check_like, obj_fixture):
132+
def test_frame_equal_columns_mismatch(check_like, obj_fixture, using_infer_string):
133+
if using_infer_string:
134+
dtype = "string"
135+
else:
136+
dtype = "object"
129137
msg = f"""{obj_fixture}\\.columns are different
130138
131139
{obj_fixture}\\.columns values are different \\(50\\.0 %\\)
132-
\\[left\\]: Index\\(\\['A', 'B'\\], dtype='object'\\)
133-
\\[right\\]: Index\\(\\['A', 'b'\\], dtype='object'\\)"""
140+
\\[left\\]: Index\\(\\['A', 'B'\\], dtype='{dtype}'\\)
141+
\\[right\\]: Index\\(\\['A', 'b'\\], dtype='{dtype}'\\)"""
134142

135143
df1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "c"])
136144
df2 = DataFrame({"A": [1, 2, 3], "b": [4, 5, 6]}, index=["a", "b", "c"])

pandas/tests/util/test_assert_index_equal.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -205,14 +205,18 @@ def test_index_equal_names(name1, name2):
205205
tm.assert_index_equal(idx1, idx2)
206206

207207

208-
def test_index_equal_category_mismatch(check_categorical):
209-
msg = """Index are different
208+
def test_index_equal_category_mismatch(check_categorical, using_infer_string):
209+
if using_infer_string:
210+
dtype = "string"
211+
else:
212+
dtype = "object"
213+
msg = f"""Index are different
210214
211215
Attribute "dtype" are different
212216
\\[left\\]: CategoricalDtype\\(categories=\\['a', 'b'\\], ordered=False, \
213-
categories_dtype=object\\)
217+
categories_dtype={dtype}\\)
214218
\\[right\\]: CategoricalDtype\\(categories=\\['a', 'b', 'c'\\], \
215-
ordered=False, categories_dtype=object\\)"""
219+
ordered=False, categories_dtype={dtype}\\)"""
216220

217221
idx1 = Index(Categorical(["a", "b"]))
218222
idx2 = Index(Categorical(["a", "b"], categories=["a", "b", "c"]))

pandas/tests/util/test_assert_series_equal.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -214,8 +214,18 @@ def test_series_equal_numeric_values_mismatch(rtol):
214214
tm.assert_series_equal(s1, s2, rtol=rtol)
215215

216216

217-
def test_series_equal_categorical_values_mismatch(rtol):
218-
msg = """Series are different
217+
def test_series_equal_categorical_values_mismatch(rtol, using_infer_string):
218+
if using_infer_string:
219+
msg = """Series are different
220+
221+
Series values are different \\(66\\.66667 %\\)
222+
\\[index\\]: \\[0, 1, 2\\]
223+
\\[left\\]: \\['a', 'b', 'c'\\]
224+
Categories \\(3, string\\): \\[a, b, c\\]
225+
\\[right\\]: \\['a', 'c', 'b'\\]
226+
Categories \\(3, string\\): \\[a, b, c\\]"""
227+
else:
228+
msg = """Series are different
219229
220230
Series values are different \\(66\\.66667 %\\)
221231
\\[index\\]: \\[0, 1, 2\\]
@@ -246,14 +256,18 @@ def test_series_equal_datetime_values_mismatch(rtol):
246256
tm.assert_series_equal(s1, s2, rtol=rtol)
247257

248258

249-
def test_series_equal_categorical_mismatch(check_categorical):
250-
msg = """Attributes of Series are different
259+
def test_series_equal_categorical_mismatch(check_categorical, using_infer_string):
260+
if using_infer_string:
261+
dtype = "string"
262+
else:
263+
dtype = "object"
264+
msg = f"""Attributes of Series are different
251265
252266
Attribute "dtype" are different
253267
\\[left\\]: CategoricalDtype\\(categories=\\['a', 'b'\\], ordered=False, \
254-
categories_dtype=object\\)
268+
categories_dtype={dtype}\\)
255269
\\[right\\]: CategoricalDtype\\(categories=\\['a', 'b', 'c'\\], \
256-
ordered=False, categories_dtype=object\\)"""
270+
ordered=False, categories_dtype={dtype}\\)"""
257271

258272
s1 = Series(Categorical(["a", "b"]))
259273
s2 = Series(Categorical(["a", "b"], categories=list("abc")))

0 commit comments

Comments
 (0)