diff --git a/pandas/tests/io/formats/style/test_to_latex.py b/pandas/tests/io/formats/style/test_to_latex.py index 7f5b6b305f12d..7f1443c3ee66b 100644 --- a/pandas/tests/io/formats/style/test_to_latex.py +++ b/pandas/tests/io/formats/style/test_to_latex.py @@ -6,6 +6,7 @@ from pandas import ( DataFrame, MultiIndex, + Series, option_context, ) @@ -22,7 +23,9 @@ @pytest.fixture def df(): - return DataFrame({"A": [0, 1], "B": [-0.61, -1.22], "C": ["ab", "cd"]}) + return DataFrame( + {"A": [0, 1], "B": [-0.61, -1.22], "C": Series(["ab", "cd"], dtype=object)} + ) @pytest.fixture diff --git a/pandas/tests/io/formats/style/test_to_string.py b/pandas/tests/io/formats/style/test_to_string.py index 913857396446c..e6f84cc9e9cd8 100644 --- a/pandas/tests/io/formats/style/test_to_string.py +++ b/pandas/tests/io/formats/style/test_to_string.py @@ -2,7 +2,10 @@ import pytest -from pandas import DataFrame +from pandas import ( + DataFrame, + Series, +) pytest.importorskip("jinja2") from pandas.io.formats.style import Styler @@ -10,7 +13,9 @@ @pytest.fixture def df(): - return DataFrame({"A": [0, 1], "B": [-0.61, -1.22], "C": ["ab", "cd"]}) + return DataFrame( + {"A": [0, 1], "B": [-0.61, -1.22], "C": Series(["ab", "cd"], dtype=object)} + ) @pytest.fixture diff --git a/pandas/tests/io/formats/test_format.py b/pandas/tests/io/formats/test_format.py index 4748a2a4aa00e..0ca29c219b55b 100644 --- a/pandas/tests/io/formats/test_format.py +++ b/pandas/tests/io/formats/test_format.py @@ -11,6 +11,8 @@ import numpy as np import pytest +from pandas._config import using_pyarrow_string_dtype + import pandas as pd from pandas import ( DataFrame, @@ -892,7 +894,7 @@ def test_truncate_with_different_dtypes(self, dtype): def test_truncate_with_different_dtypes2(self): # 12045 - df = DataFrame({"text": ["some words"] + [None] * 9}) + df = DataFrame({"text": ["some words"] + [None] * 9}, dtype=object) with option_context("display.max_rows", 8, "display.max_columns", 3): result = str(df) @@ -1295,9 +1297,9 @@ def test_float_trim_zeros(self): ([3.50, None, "3.50"], "0 3.5\n1 None\n2 3.50\ndtype: object"), ], ) - def test_repr_str_float_truncation(self, data, expected): + def test_repr_str_float_truncation(self, data, expected, using_infer_string): # GH#38708 - series = Series(data) + series = Series(data, dtype=object if "3.50" in data else None) result = repr(series) assert result == expected @@ -1394,6 +1396,9 @@ def test_unicode_name_in_footer(self): sf = fmt.SeriesFormatter(s, name="\u05e2\u05d1\u05e8\u05d9\u05ea") sf._get_footer() # should not raise exception + @pytest.mark.xfail( + using_pyarrow_string_dtype(), reason="Fixup when arrow is default" + ) def test_east_asian_unicode_series(self): # not aligned properly because of east asian width @@ -1762,15 +1767,15 @@ def test_consistent_format(self): assert res == exp def chck_ncols(self, s): - with option_context("display.max_rows", 10): - res = repr(s) - lines = res.split("\n") lines = [ line for line in repr(s).split("\n") if not re.match(r"[^\.]*\.+", line) ][:-1] ncolsizes = len({len(line.strip()) for line in lines}) assert ncolsizes == 1 + @pytest.mark.xfail( + using_pyarrow_string_dtype(), reason="change when arrow is default" + ) def test_format_explicit(self): test_sers = gen_series_formatting() with option_context("display.max_rows", 4, "display.show_dimensions", False): diff --git a/pandas/tests/io/formats/test_to_csv.py b/pandas/tests/io/formats/test_to_csv.py index 33b9fe9b665f3..0db49a73621ea 100644 --- a/pandas/tests/io/formats/test_to_csv.py +++ b/pandas/tests/io/formats/test_to_csv.py @@ -666,7 +666,7 @@ def test_na_rep_truncated(self): def test_to_csv_errors(self, errors): # GH 22610 data = ["\ud800foo"] - ser = pd.Series(data, index=Index(data)) + ser = pd.Series(data, index=Index(data, dtype=object), dtype=object) with tm.ensure_clean("test.csv") as path: ser.to_csv(path, errors=errors) # No use in reading back the data as it is not the same anymore @@ -682,8 +682,8 @@ def test_to_csv_binary_handle(self, mode): """ df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) with tm.ensure_clean() as path: with open(path, mode="w+b") as handle: @@ -720,8 +720,8 @@ def test_to_csv_iterative_compression_name(compression): # GH 38714 df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) with tm.ensure_clean() as path: df.to_csv(path, compression=compression, chunksize=1) @@ -734,8 +734,8 @@ def test_to_csv_iterative_compression_buffer(compression): # GH 38714 df = DataFrame( 1.1 * np.arange(120).reshape((30, 4)), - columns=Index(list("ABCD"), dtype=object), - index=Index([f"i-{i}" for i in range(30)], dtype=object), + columns=Index(list("ABCD")), + index=Index([f"i-{i}" for i in range(30)]), ) with io.BytesIO() as buffer: df.to_csv(buffer, compression=compression, chunksize=1) diff --git a/pandas/tests/io/formats/test_to_html.py b/pandas/tests/io/formats/test_to_html.py index 605e5e182d8cc..0a30039815485 100644 --- a/pandas/tests/io/formats/test_to_html.py +++ b/pandas/tests/io/formats/test_to_html.py @@ -240,7 +240,7 @@ def test_to_html_multiindex_odd_even_truncate(max_rows, expected, datapath): ( DataFrame( [[0, 1], [2, 3], [4, 5], [6, 7]], - columns=["foo", None], + columns=Index(["foo", None], dtype=object), index=np.arange(4), ), {"__index__": lambda x: "abcd"[x]}, @@ -771,7 +771,7 @@ def test_to_html_render_links(render_links, expected, datapath): [0, "https://pandas.pydata.org/?q1=a&q2=b", "pydata.org"], [0, "www.pydata.org", "pydata.org"], ] - df = DataFrame(data, columns=["foo", "bar", None]) + df = DataFrame(data, columns=Index(["foo", "bar", None], dtype=object)) result = df.to_html(render_links=render_links) expected = expected_html(datapath, expected) diff --git a/pandas/tests/io/formats/test_to_string.py b/pandas/tests/io/formats/test_to_string.py index 7cb7cbd223ac4..2e5a5005cb076 100644 --- a/pandas/tests/io/formats/test_to_string.py +++ b/pandas/tests/io/formats/test_to_string.py @@ -10,6 +10,8 @@ import numpy as np import pytest +from pandas._config import using_pyarrow_string_dtype + from pandas import ( CategoricalIndex, DataFrame, @@ -849,6 +851,7 @@ def test_to_string(self): frame.to_string() # TODO: split or simplify this test? + @pytest.mark.xfail(using_pyarrow_string_dtype(), reason="fix when arrow is default") def test_to_string_index_with_nan(self): # GH#2850 df = DataFrame(