Skip to content

Adjust tests in util folder for new string option #56181

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
Show file tree
Hide file tree
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
20 changes: 14 additions & 6 deletions pandas/tests/util/test_assert_frame_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,16 @@ def test_empty_dtypes(check_dtype):


@pytest.mark.parametrize("check_like", [True, False])
def test_frame_equal_index_mismatch(check_like, obj_fixture):
def test_frame_equal_index_mismatch(check_like, obj_fixture, using_infer_string):
if using_infer_string:
dtype = "string"
else:
dtype = "object"
msg = f"""{obj_fixture}\\.index are different

{obj_fixture}\\.index values are different \\(33\\.33333 %\\)
\\[left\\]: Index\\(\\['a', 'b', 'c'\\], dtype='object'\\)
\\[right\\]: Index\\(\\['a', 'b', 'd'\\], dtype='object'\\)
\\[left\\]: Index\\(\\['a', 'b', 'c'\\], dtype='{dtype}'\\)
\\[right\\]: Index\\(\\['a', 'b', 'd'\\], dtype='{dtype}'\\)
At positional index 2, first diff: c != d"""

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


@pytest.mark.parametrize("check_like", [True, False])
def test_frame_equal_columns_mismatch(check_like, obj_fixture):
def test_frame_equal_columns_mismatch(check_like, obj_fixture, using_infer_string):
if using_infer_string:
dtype = "string"
else:
dtype = "object"
msg = f"""{obj_fixture}\\.columns are different

{obj_fixture}\\.columns values are different \\(50\\.0 %\\)
\\[left\\]: Index\\(\\['A', 'B'\\], dtype='object'\\)
\\[right\\]: Index\\(\\['A', 'b'\\], dtype='object'\\)"""
\\[left\\]: Index\\(\\['A', 'B'\\], dtype='{dtype}'\\)
\\[right\\]: Index\\(\\['A', 'b'\\], dtype='{dtype}'\\)"""

df1 = DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]}, index=["a", "b", "c"])
df2 = DataFrame({"A": [1, 2, 3], "b": [4, 5, 6]}, index=["a", "b", "c"])
Expand Down
12 changes: 8 additions & 4 deletions pandas/tests/util/test_assert_index_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,18 @@ def test_index_equal_names(name1, name2):
tm.assert_index_equal(idx1, idx2)


def test_index_equal_category_mismatch(check_categorical):
msg = """Index are different
def test_index_equal_category_mismatch(check_categorical, using_infer_string):
if using_infer_string:
dtype = "string"
else:
dtype = "object"
msg = f"""Index are different

Attribute "dtype" are different
\\[left\\]: CategoricalDtype\\(categories=\\['a', 'b'\\], ordered=False, \
categories_dtype=object\\)
categories_dtype={dtype}\\)
\\[right\\]: CategoricalDtype\\(categories=\\['a', 'b', 'c'\\], \
ordered=False, categories_dtype=object\\)"""
ordered=False, categories_dtype={dtype}\\)"""

idx1 = Index(Categorical(["a", "b"]))
idx2 = Index(Categorical(["a", "b"], categories=["a", "b", "c"]))
Expand Down
26 changes: 20 additions & 6 deletions pandas/tests/util/test_assert_series_equal.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,18 @@ def test_series_equal_numeric_values_mismatch(rtol):
tm.assert_series_equal(s1, s2, rtol=rtol)


def test_series_equal_categorical_values_mismatch(rtol):
msg = """Series are different
def test_series_equal_categorical_values_mismatch(rtol, using_infer_string):
if using_infer_string:
msg = """Series are different

Series values are different \\(66\\.66667 %\\)
\\[index\\]: \\[0, 1, 2\\]
\\[left\\]: \\['a', 'b', 'c'\\]
Categories \\(3, string\\): \\[a, b, c\\]
\\[right\\]: \\['a', 'c', 'b'\\]
Categories \\(3, string\\): \\[a, b, c\\]"""
else:
msg = """Series are different

Series values are different \\(66\\.66667 %\\)
\\[index\\]: \\[0, 1, 2\\]
Expand Down Expand Up @@ -246,14 +256,18 @@ def test_series_equal_datetime_values_mismatch(rtol):
tm.assert_series_equal(s1, s2, rtol=rtol)


def test_series_equal_categorical_mismatch(check_categorical):
msg = """Attributes of Series are different
def test_series_equal_categorical_mismatch(check_categorical, using_infer_string):
if using_infer_string:
dtype = "string"
else:
dtype = "object"
msg = f"""Attributes of Series are different

Attribute "dtype" are different
\\[left\\]: CategoricalDtype\\(categories=\\['a', 'b'\\], ordered=False, \
categories_dtype=object\\)
categories_dtype={dtype}\\)
\\[right\\]: CategoricalDtype\\(categories=\\['a', 'b', 'c'\\], \
ordered=False, categories_dtype=object\\)"""
ordered=False, categories_dtype={dtype}\\)"""

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