Skip to content

Commit

Permalink
TST (string dtype): fix IO dtype_backend tests for storage of str dty…
Browse files Browse the repository at this point in the history
…pe of columns' Index (pandas-dev#59509)

* TST (string dtype): fix failure in csv test_dtype_backend_string test

* ignore storage of Index str dtype
  • Loading branch information
jorisvandenbossche authored Aug 14, 2024
1 parent e2ed477 commit eba59fa
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 11 deletions.
4 changes: 3 additions & 1 deletion pandas/tests/io/excel/test_readers.py
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,9 @@ def test_dtype_backend_string(self, read_ext, string_storage, tmp_excel):
"b": Series(["x", None], dtype=pd.StringDtype(string_storage)),
}
)
tm.assert_frame_equal(result, expected)
# the storage of the str columns' Index is also affected by the
# string_storage setting -> ignore that for checking the result
tm.assert_frame_equal(result, expected, check_column_type=False)

@pytest.mark.parametrize("dtypes, exp_value", [({}, 1), ({"a.1": "int64"}, 1)])
def test_dtype_mangle_dup_cols(self, read_ext, dtypes, exp_value):
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/io/json/test_pandas.py
Original file line number Diff line number Diff line change
Expand Up @@ -2194,7 +2194,9 @@ def test_read_json_dtype_backend(
if orient == "values":
expected.columns = list(range(8))

tm.assert_frame_equal(result, expected)
# the storage of the str columns' Index is also affected by the
# string_storage setting -> ignore that for checking the result
tm.assert_frame_equal(result, expected, check_column_type=False)

@pytest.mark.parametrize("orient", ["split", "records", "index"])
def test_read_json_nullable_series(self, string_storage, dtype_backend, orient):
Expand Down
12 changes: 6 additions & 6 deletions pandas/tests/io/parser/dtypes/test_dtypes_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,12 +470,12 @@ def test_dtype_backend_string(all_parsers, string_storage):
"""
result = parser.read_csv(StringIO(data), dtype_backend="numpy_nullable")

expected = DataFrame(
{
"a": pd.array(["a", "b"], dtype=pd.StringDtype(string_storage)),
"b": pd.array(["x", pd.NA], dtype=pd.StringDtype(string_storage)),
}
)
expected = DataFrame(
{
"a": pd.array(["a", "b"], dtype=pd.StringDtype(string_storage)),
"b": pd.array(["x", pd.NA], dtype=pd.StringDtype(string_storage)),
},
)
tm.assert_frame_equal(result, expected)


Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/io/parser/test_read_fwf.py
Original file line number Diff line number Diff line change
Expand Up @@ -974,7 +974,9 @@ def test_dtype_backend(string_storage, dtype_backend):
)
expected["i"] = ArrowExtensionArray(pa.array([None, None]))

tm.assert_frame_equal(result, expected)
# the storage of the str columns' Index is also affected by the
# string_storage setting -> ignore that for checking the result
tm.assert_frame_equal(result, expected, check_column_type=False)


def test_invalid_dtype_backend():
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/io/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ def test_dtype_backend(self, string_storage, dtype_backend, flavor_read_html):
}
)

tm.assert_frame_equal(result, expected)
# the storage of the str columns' Index is also affected by the
# string_storage setting -> ignore that for checking the result
tm.assert_frame_equal(result, expected, check_column_type=False)

@pytest.mark.network
@pytest.mark.single_cpu
Expand Down
4 changes: 3 additions & 1 deletion pandas/tests/io/xml/test_xml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2050,7 +2050,9 @@ def test_read_xml_nullable_dtypes(
)
expected["g"] = ArrowExtensionArray(pa.array([None, None]))

tm.assert_frame_equal(result, expected)
# the storage of the str columns' Index is also affected by the
# string_storage setting -> ignore that for checking the result
tm.assert_frame_equal(result, expected, check_column_type=False)


def test_invalid_dtype_backend():
Expand Down

0 comments on commit eba59fa

Please sign in to comment.