Skip to content

Commit 0437fdb

Browse files
authored
CLN: Remove reset_display_options (pandas-dev#56153)
1 parent 0229225 commit 0437fdb

File tree

5 files changed

+34
-50
lines changed

5 files changed

+34
-50
lines changed

pandas/_testing/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -291,13 +291,6 @@
291291
comparison_dunder_methods = ["__eq__", "__ne__", "__le__", "__lt__", "__ge__", "__gt__"]
292292

293293

294-
def reset_display_options() -> None:
295-
"""
296-
Reset the display options for printing and representing objects.
297-
"""
298-
pd.reset_option("^display.", silent=True)
299-
300-
301294
# -----------------------------------------------------------------------------
302295
# Comparators
303296

@@ -1174,7 +1167,6 @@ def shares_memory(left, right) -> bool:
11741167
"NULL_OBJECTS",
11751168
"OBJECT_DTYPES",
11761169
"raise_assert_detail",
1177-
"reset_display_options",
11781170
"raises_chained_assignment_error",
11791171
"round_trip_localpath",
11801172
"round_trip_pathlib",

pandas/tests/frame/test_repr.py

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
)
2525
import pandas._testing as tm
2626

27-
import pandas.io.formats.format as fmt
28-
2927

3028
class TestDataFrameRepr:
3129
def test_repr_should_return_str(self):
@@ -220,16 +218,14 @@ def test_repr_unsortable(self):
220218
def test_repr_float_frame_options(self, float_frame):
221219
repr(float_frame)
222220

223-
fmt.set_option("display.precision", 3)
224-
repr(float_frame)
221+
with option_context("display.precision", 3):
222+
repr(float_frame)
225223

226-
fmt.set_option("display.max_rows", 10, "display.max_columns", 2)
227-
repr(float_frame)
228-
229-
fmt.set_option("display.max_rows", 1000, "display.max_columns", 1000)
230-
repr(float_frame)
224+
with option_context("display.max_rows", 10, "display.max_columns", 2):
225+
repr(float_frame)
231226

232-
tm.reset_display_options()
227+
with option_context("display.max_rows", 1000, "display.max_columns", 1000):
228+
repr(float_frame)
233229

234230
def test_repr_unicode(self):
235231
uval = "\u03c3\u03c3\u03c3\u03c3"

pandas/tests/io/formats/test_eng_formatting.py

Lines changed: 28 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
import numpy as np
2+
import pytest
23

3-
from pandas import DataFrame
4-
import pandas._testing as tm
4+
from pandas import (
5+
DataFrame,
6+
reset_option,
7+
set_eng_float_format,
8+
)
59

6-
import pandas.io.formats.format as fmt
10+
from pandas.io.formats.format import EngFormatter
11+
12+
13+
@pytest.fixture(autouse=True)
14+
def reset_float_format():
15+
yield
16+
reset_option("display.float_format")
717

818

919
class TestEngFormatter:
1020
def test_eng_float_formatter2(self, float_frame):
1121
df = float_frame
1222
df.loc[5] = 0
1323

14-
fmt.set_eng_float_format()
24+
set_eng_float_format()
1525
repr(df)
1626

17-
fmt.set_eng_float_format(use_eng_prefix=True)
27+
set_eng_float_format(use_eng_prefix=True)
1828
repr(df)
1929

20-
fmt.set_eng_float_format(accuracy=0)
30+
set_eng_float_format(accuracy=0)
2131
repr(df)
22-
tm.reset_display_options()
2332

2433
def test_eng_float_formatter(self):
2534
df = DataFrame({"A": [1.41, 141.0, 14100, 1410000.0]})
2635

27-
fmt.set_eng_float_format()
36+
set_eng_float_format()
2837
result = df.to_string()
2938
expected = (
3039
" A\n"
@@ -35,18 +44,16 @@ def test_eng_float_formatter(self):
3544
)
3645
assert result == expected
3746

38-
fmt.set_eng_float_format(use_eng_prefix=True)
47+
set_eng_float_format(use_eng_prefix=True)
3948
result = df.to_string()
4049
expected = " A\n0 1.410\n1 141.000\n2 14.100k\n3 1.410M"
4150
assert result == expected
4251

43-
fmt.set_eng_float_format(accuracy=0)
52+
set_eng_float_format(accuracy=0)
4453
result = df.to_string()
4554
expected = " A\n0 1E+00\n1 141E+00\n2 14E+03\n3 1E+06"
4655
assert result == expected
4756

48-
tm.reset_display_options()
49-
5057
def compare(self, formatter, input, output):
5158
formatted_input = formatter(input)
5259
assert formatted_input == output
@@ -67,7 +74,7 @@ def compare_all(self, formatter, in_out):
6774
self.compare(formatter, -input, "-" + output[1:])
6875

6976
def test_exponents_with_eng_prefix(self):
70-
formatter = fmt.EngFormatter(accuracy=3, use_eng_prefix=True)
77+
formatter = EngFormatter(accuracy=3, use_eng_prefix=True)
7178
f = np.sqrt(2)
7279
in_out = [
7380
(f * 10**-24, " 1.414y"),
@@ -125,7 +132,7 @@ def test_exponents_with_eng_prefix(self):
125132
self.compare_all(formatter, in_out)
126133

127134
def test_exponents_without_eng_prefix(self):
128-
formatter = fmt.EngFormatter(accuracy=4, use_eng_prefix=False)
135+
formatter = EngFormatter(accuracy=4, use_eng_prefix=False)
129136
f = np.pi
130137
in_out = [
131138
(f * 10**-24, " 3.1416E-24"),
@@ -183,7 +190,7 @@ def test_exponents_without_eng_prefix(self):
183190
self.compare_all(formatter, in_out)
184191

185192
def test_rounding(self):
186-
formatter = fmt.EngFormatter(accuracy=3, use_eng_prefix=True)
193+
formatter = EngFormatter(accuracy=3, use_eng_prefix=True)
187194
in_out = [
188195
(5.55555, " 5.556"),
189196
(55.5555, " 55.556"),
@@ -194,7 +201,7 @@ def test_rounding(self):
194201
]
195202
self.compare_all(formatter, in_out)
196203

197-
formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
204+
formatter = EngFormatter(accuracy=1, use_eng_prefix=True)
198205
in_out = [
199206
(5.55555, " 5.6"),
200207
(55.5555, " 55.6"),
@@ -205,7 +212,7 @@ def test_rounding(self):
205212
]
206213
self.compare_all(formatter, in_out)
207214

208-
formatter = fmt.EngFormatter(accuracy=0, use_eng_prefix=True)
215+
formatter = EngFormatter(accuracy=0, use_eng_prefix=True)
209216
in_out = [
210217
(5.55555, " 6"),
211218
(55.5555, " 56"),
@@ -216,14 +223,14 @@ def test_rounding(self):
216223
]
217224
self.compare_all(formatter, in_out)
218225

219-
formatter = fmt.EngFormatter(accuracy=3, use_eng_prefix=True)
226+
formatter = EngFormatter(accuracy=3, use_eng_prefix=True)
220227
result = formatter(0)
221228
assert result == " 0.000"
222229

223230
def test_nan(self):
224231
# Issue #11981
225232

226-
formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
233+
formatter = EngFormatter(accuracy=1, use_eng_prefix=True)
227234
result = formatter(np.nan)
228235
assert result == "NaN"
229236

@@ -235,14 +242,13 @@ def test_nan(self):
235242
}
236243
)
237244
pt = df.pivot_table(values="a", index="b", columns="c")
238-
fmt.set_eng_float_format(accuracy=1)
245+
set_eng_float_format(accuracy=1)
239246
result = pt.to_string()
240247
assert "NaN" in result
241-
tm.reset_display_options()
242248

243249
def test_inf(self):
244250
# Issue #11981
245251

246-
formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
252+
formatter = EngFormatter(accuracy=1, use_eng_prefix=True)
247253
result = formatter(np.inf)
248254
assert result == "inf"

pandas/tests/io/formats/test_to_html.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -914,7 +914,6 @@ def get_ipython():
914914
repstr = df._repr_html_()
915915

916916
assert "class" in repstr # info fallback
917-
tm.reset_display_options()
918917

919918
def test_repr_html(self, float_frame):
920919
df = float_frame
@@ -926,16 +925,12 @@ def test_repr_html(self, float_frame):
926925
with option_context("display.notebook_repr_html", False):
927926
df._repr_html_()
928927

929-
tm.reset_display_options()
930-
931928
df = DataFrame([[1, 2], [3, 4]])
932929
with option_context("display.show_dimensions", True):
933930
assert "2 rows" in df._repr_html_()
934931
with option_context("display.show_dimensions", False):
935932
assert "2 rows" not in df._repr_html_()
936933

937-
tm.reset_display_options()
938-
939934
def test_repr_html_mathjax(self):
940935
df = DataFrame([[1, 2], [3, 4]])
941936
assert "tex2jax_ignore" not in df._repr_html_()

pandas/tests/io/formats/test_to_string.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ def test_to_string_complex_float_formatting(self):
412412

413413
def test_to_string_format_inf(self):
414414
# GH#24861
415-
tm.reset_display_options()
416415
df = DataFrame(
417416
{
418417
"A": [-np.inf, np.inf, -1, -2.1234, 3, 4],
@@ -460,7 +459,6 @@ def test_to_string_int_formatting(self):
460459
assert output == expected
461460

462461
def test_to_string_float_formatting(self):
463-
tm.reset_display_options()
464462
with option_context(
465463
"display.precision",
466464
5,
@@ -495,7 +493,6 @@ def test_to_string_float_formatting(self):
495493
expected = " x\n0 3234.000\n1 0.253"
496494
assert df_s == expected
497495

498-
tm.reset_display_options()
499496
assert get_option("display.precision") == 6
500497

501498
df = DataFrame({"x": [1e9, 0.2512]})
@@ -516,14 +513,12 @@ def test_to_string_decimal(self):
516513
assert df.to_string(decimal=",") == expected
517514

518515
def test_to_string_left_justify_cols(self):
519-
tm.reset_display_options()
520516
df = DataFrame({"x": [3234, 0.253]})
521517
df_s = df.to_string(justify="left")
522518
expected = " x \n0 3234.000\n1 0.253"
523519
assert df_s == expected
524520

525521
def test_to_string_format_na(self):
526-
tm.reset_display_options()
527522
df = DataFrame(
528523
{
529524
"A": [np.nan, -1, -2.1234, 3, 4],

0 commit comments

Comments
 (0)