Skip to content

Commit 97e8926

Browse files
phoflcbpygit
authored andcommitted
Adjust format tests for new string option (pandas-dev#56535)
1 parent 45cdacd commit 97e8926

File tree

6 files changed

+34
-18
lines changed

6 files changed

+34
-18
lines changed

pandas/tests/io/formats/style/test_to_latex.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from pandas import (
77
DataFrame,
88
MultiIndex,
9+
Series,
910
option_context,
1011
)
1112

@@ -22,7 +23,9 @@
2223

2324
@pytest.fixture
2425
def df():
25-
return DataFrame({"A": [0, 1], "B": [-0.61, -1.22], "C": ["ab", "cd"]})
26+
return DataFrame(
27+
{"A": [0, 1], "B": [-0.61, -1.22], "C": Series(["ab", "cd"], dtype=object)}
28+
)
2629

2730

2831
@pytest.fixture

pandas/tests/io/formats/style/test_to_string.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,20 @@
22

33
import pytest
44

5-
from pandas import DataFrame
5+
from pandas import (
6+
DataFrame,
7+
Series,
8+
)
69

710
pytest.importorskip("jinja2")
811
from pandas.io.formats.style import Styler
912

1013

1114
@pytest.fixture
1215
def df():
13-
return DataFrame({"A": [0, 1], "B": [-0.61, -1.22], "C": ["ab", "cd"]})
16+
return DataFrame(
17+
{"A": [0, 1], "B": [-0.61, -1.22], "C": Series(["ab", "cd"], dtype=object)}
18+
)
1419

1520

1621
@pytest.fixture

pandas/tests/io/formats/test_format.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import numpy as np
1212
import pytest
1313

14+
from pandas._config import using_pyarrow_string_dtype
15+
1416
import pandas as pd
1517
from pandas import (
1618
DataFrame,
@@ -892,7 +894,7 @@ def test_truncate_with_different_dtypes(self, dtype):
892894

893895
def test_truncate_with_different_dtypes2(self):
894896
# 12045
895-
df = DataFrame({"text": ["some words"] + [None] * 9})
897+
df = DataFrame({"text": ["some words"] + [None] * 9}, dtype=object)
896898

897899
with option_context("display.max_rows", 8, "display.max_columns", 3):
898900
result = str(df)
@@ -1295,9 +1297,9 @@ def test_float_trim_zeros(self):
12951297
([3.50, None, "3.50"], "0 3.5\n1 None\n2 3.50\ndtype: object"),
12961298
],
12971299
)
1298-
def test_repr_str_float_truncation(self, data, expected):
1300+
def test_repr_str_float_truncation(self, data, expected, using_infer_string):
12991301
# GH#38708
1300-
series = Series(data)
1302+
series = Series(data, dtype=object if "3.50" in data else None)
13011303
result = repr(series)
13021304
assert result == expected
13031305

@@ -1394,6 +1396,9 @@ def test_unicode_name_in_footer(self):
13941396
sf = fmt.SeriesFormatter(s, name="\u05e2\u05d1\u05e8\u05d9\u05ea")
13951397
sf._get_footer() # should not raise exception
13961398

1399+
@pytest.mark.xfail(
1400+
using_pyarrow_string_dtype(), reason="Fixup when arrow is default"
1401+
)
13971402
def test_east_asian_unicode_series(self):
13981403
# not aligned properly because of east asian width
13991404

@@ -1762,15 +1767,15 @@ def test_consistent_format(self):
17621767
assert res == exp
17631768

17641769
def chck_ncols(self, s):
1765-
with option_context("display.max_rows", 10):
1766-
res = repr(s)
1767-
lines = res.split("\n")
17681770
lines = [
17691771
line for line in repr(s).split("\n") if not re.match(r"[^\.]*\.+", line)
17701772
][:-1]
17711773
ncolsizes = len({len(line.strip()) for line in lines})
17721774
assert ncolsizes == 1
17731775

1776+
@pytest.mark.xfail(
1777+
using_pyarrow_string_dtype(), reason="change when arrow is default"
1778+
)
17741779
def test_format_explicit(self):
17751780
test_sers = gen_series_formatting()
17761781
with option_context("display.max_rows", 4, "display.show_dimensions", False):

pandas/tests/io/formats/test_to_csv.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,7 @@ def test_na_rep_truncated(self):
666666
def test_to_csv_errors(self, errors):
667667
# GH 22610
668668
data = ["\ud800foo"]
669-
ser = pd.Series(data, index=Index(data))
669+
ser = pd.Series(data, index=Index(data, dtype=object), dtype=object)
670670
with tm.ensure_clean("test.csv") as path:
671671
ser.to_csv(path, errors=errors)
672672
# 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):
682682
"""
683683
df = DataFrame(
684684
1.1 * np.arange(120).reshape((30, 4)),
685-
columns=Index(list("ABCD"), dtype=object),
686-
index=Index([f"i-{i}" for i in range(30)], dtype=object),
685+
columns=Index(list("ABCD")),
686+
index=Index([f"i-{i}" for i in range(30)]),
687687
)
688688
with tm.ensure_clean() as path:
689689
with open(path, mode="w+b") as handle:
@@ -720,8 +720,8 @@ def test_to_csv_iterative_compression_name(compression):
720720
# GH 38714
721721
df = DataFrame(
722722
1.1 * np.arange(120).reshape((30, 4)),
723-
columns=Index(list("ABCD"), dtype=object),
724-
index=Index([f"i-{i}" for i in range(30)], dtype=object),
723+
columns=Index(list("ABCD")),
724+
index=Index([f"i-{i}" for i in range(30)]),
725725
)
726726
with tm.ensure_clean() as path:
727727
df.to_csv(path, compression=compression, chunksize=1)
@@ -734,8 +734,8 @@ def test_to_csv_iterative_compression_buffer(compression):
734734
# GH 38714
735735
df = DataFrame(
736736
1.1 * np.arange(120).reshape((30, 4)),
737-
columns=Index(list("ABCD"), dtype=object),
738-
index=Index([f"i-{i}" for i in range(30)], dtype=object),
737+
columns=Index(list("ABCD")),
738+
index=Index([f"i-{i}" for i in range(30)]),
739739
)
740740
with io.BytesIO() as buffer:
741741
df.to_csv(buffer, compression=compression, chunksize=1)

pandas/tests/io/formats/test_to_html.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ def test_to_html_multiindex_odd_even_truncate(max_rows, expected, datapath):
240240
(
241241
DataFrame(
242242
[[0, 1], [2, 3], [4, 5], [6, 7]],
243-
columns=["foo", None],
243+
columns=Index(["foo", None], dtype=object),
244244
index=np.arange(4),
245245
),
246246
{"__index__": lambda x: "abcd"[x]},
@@ -771,7 +771,7 @@ def test_to_html_render_links(render_links, expected, datapath):
771771
[0, "https://pandas.pydata.org/?q1=a&q2=b", "pydata.org"],
772772
[0, "www.pydata.org", "pydata.org"],
773773
]
774-
df = DataFrame(data, columns=["foo", "bar", None])
774+
df = DataFrame(data, columns=Index(["foo", "bar", None], dtype=object))
775775

776776
result = df.to_html(render_links=render_links)
777777
expected = expected_html(datapath, expected)

pandas/tests/io/formats/test_to_string.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import numpy as np
1111
import pytest
1212

13+
from pandas._config import using_pyarrow_string_dtype
14+
1315
from pandas import (
1416
CategoricalIndex,
1517
DataFrame,
@@ -849,6 +851,7 @@ def test_to_string(self):
849851
frame.to_string()
850852

851853
# TODO: split or simplify this test?
854+
@pytest.mark.xfail(using_pyarrow_string_dtype(), reason="fix when arrow is default")
852855
def test_to_string_index_with_nan(self):
853856
# GH#2850
854857
df = DataFrame(

0 commit comments

Comments
 (0)