Skip to content

Commit 2641235

Browse files
authored
REF: misplaced formatting tests (#55740)
* misplaced tests * move info tests * misplaced info tests * rename * rename * misplaced repr_html tests * Comment
1 parent 4490da7 commit 2641235

File tree

9 files changed

+385
-381
lines changed

9 files changed

+385
-381
lines changed

pandas/tests/io/formats/test_info.py renamed to pandas/tests/frame/methods/test_info.py

+14
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def test_info_categorical_column_smoke_test():
7171
"float_frame",
7272
"datetime_frame",
7373
"duplicate_columns_frame",
74+
"float_string_frame",
7475
],
7576
)
7677
def test_info_smoke_test(fixture_func_name, request):
@@ -80,6 +81,19 @@ def test_info_smoke_test(fixture_func_name, request):
8081
result = buf.getvalue().splitlines()
8182
assert len(result) > 10
8283

84+
buf = StringIO()
85+
frame.info(buf=buf, verbose=False)
86+
87+
88+
def test_info_smoke_test2(float_frame):
89+
# pretty useless test, used to be mixed into the repr tests
90+
buf = StringIO()
91+
float_frame.reindex(columns=["A"]).info(verbose=False, buf=buf)
92+
float_frame.reindex(columns=["A", "B"]).info(verbose=False, buf=buf)
93+
94+
# no columns or index
95+
DataFrame().info(buf=buf)
96+
8397

8498
@pytest.mark.parametrize(
8599
"num_columns, max_info_columns, verbose",

pandas/tests/frame/test_repr_info.py renamed to pandas/tests/frame/test_repr.py

+7-22
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import pandas.io.formats.format as fmt
2626

2727

28-
class TestDataFrameReprInfoEtc:
28+
class TestDataFrameRepr:
2929
def test_repr_bytes_61_lines(self):
3030
# GH#12857
3131
lets = list("ACDEFGHIJKLMNOP")
@@ -141,11 +141,8 @@ def test_repr_empty(self):
141141
repr(frame)
142142

143143
def test_repr_mixed(self, float_string_frame):
144-
buf = StringIO()
145-
146144
# mixed
147145
repr(float_string_frame)
148-
float_string_frame.info(verbose=False, buf=buf)
149146

150147
@pytest.mark.slow
151148
def test_repr_mixed_big(self):
@@ -162,26 +159,11 @@ def test_repr_mixed_big(self):
162159

163160
repr(biggie)
164161

165-
def test_repr(self, float_frame):
166-
buf = StringIO()
167-
168-
# small one
169-
repr(float_frame)
170-
float_frame.info(verbose=False, buf=buf)
171-
172-
# even smaller
173-
float_frame.reindex(columns=["A"]).info(verbose=False, buf=buf)
174-
float_frame.reindex(columns=["A", "B"]).info(verbose=False, buf=buf)
175-
176-
# exhausting cases in DataFrame.info
177-
162+
def test_repr(self):
178163
# columns but no index
179164
no_index = DataFrame(columns=[0, 1, 3])
180165
repr(no_index)
181166

182-
# no columns or index
183-
DataFrame().info(buf=buf)
184-
185167
df = DataFrame(["a\n\r\tb"], columns=["a\n\r\td"], index=["a\n\r\tf"])
186168
assert "\t" not in repr(df)
187169
assert "\r" not in repr(df)
@@ -204,7 +186,7 @@ def test_repr_big(self):
204186
biggie = DataFrame(np.zeros((200, 4)), columns=range(4), index=range(200))
205187
repr(biggie)
206188

207-
def test_repr_unsortable(self, float_frame):
189+
def test_repr_unsortable(self):
208190
# columns are not sortable
209191

210192
unsortable = DataFrame(
@@ -218,6 +200,9 @@ def test_repr_unsortable(self, float_frame):
218200
)
219201
repr(unsortable)
220202

203+
def test_repr_float_frame_options(self, float_frame):
204+
repr(float_frame)
205+
221206
fmt.set_option("display.precision", 3)
222207
repr(float_frame)
223208

@@ -257,7 +242,7 @@ def test_str_to_bytes_raises(self):
257242
with pytest.raises(TypeError, match=msg):
258243
bytes(df)
259244

260-
def test_very_wide_info_repr(self):
245+
def test_very_wide_repr(self):
261246
df = DataFrame(
262247
np.random.default_rng(2).standard_normal((10, 20)),
263248
columns=np.array(["a" * 10] * 20, dtype=object),

pandas/tests/indexes/multi/test_formats.py

+10
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,13 @@ def test_tuple_width(self, wide_multi_index):
229229
('abc', 10, '2000-01-01 00:33:19', '2000-01-01 00:33:19', ...)],
230230
names=['a', 'b', 'dti_1', 'dti_2', 'dti_3'], length=2000)"""
231231
assert result == expected
232+
233+
def test_multiindex_long_element(self):
234+
# Non-regression test towards GH#52960
235+
data = MultiIndex.from_tuples([("c" * 62,)])
236+
237+
expected = (
238+
"MultiIndex([('cccccccccccccccccccccccccccccccccccccccc"
239+
"cccccccccccccccccccccc',)],\n )"
240+
)
241+
assert str(data) == expected

pandas/tests/io/formats/test_eng_formatting.py

+14
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@
77

88

99
class TestEngFormatter:
10+
def test_eng_float_formatter2(self, float_frame):
11+
df = float_frame
12+
df.loc[5] = 0
13+
14+
fmt.set_eng_float_format()
15+
repr(df)
16+
17+
fmt.set_eng_float_format(use_eng_prefix=True)
18+
repr(df)
19+
20+
fmt.set_eng_float_format(accuracy=0)
21+
repr(df)
22+
tm.reset_display_options()
23+
1024
def test_eng_float_formatter(self):
1125
df = DataFrame({"A": [1.41, 141.0, 14100, 1410000.0]})
1226

0 commit comments

Comments
 (0)