Skip to content

Commit

Permalink
CLN: Remove reset_display_options (#56153)
Browse files Browse the repository at this point in the history
  • Loading branch information
mroeschke authored Nov 24, 2023
1 parent 0229225 commit 0437fdb
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 50 deletions.
8 changes: 0 additions & 8 deletions pandas/_testing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,13 +291,6 @@
comparison_dunder_methods = ["__eq__", "__ne__", "__le__", "__lt__", "__ge__", "__gt__"]


def reset_display_options() -> None:
"""
Reset the display options for printing and representing objects.
"""
pd.reset_option("^display.", silent=True)


# -----------------------------------------------------------------------------
# Comparators

Expand Down Expand Up @@ -1174,7 +1167,6 @@ def shares_memory(left, right) -> bool:
"NULL_OBJECTS",
"OBJECT_DTYPES",
"raise_assert_detail",
"reset_display_options",
"raises_chained_assignment_error",
"round_trip_localpath",
"round_trip_pathlib",
Expand Down
16 changes: 6 additions & 10 deletions pandas/tests/frame/test_repr.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
)
import pandas._testing as tm

import pandas.io.formats.format as fmt


class TestDataFrameRepr:
def test_repr_should_return_str(self):
Expand Down Expand Up @@ -220,16 +218,14 @@ def test_repr_unsortable(self):
def test_repr_float_frame_options(self, float_frame):
repr(float_frame)

fmt.set_option("display.precision", 3)
repr(float_frame)
with option_context("display.precision", 3):
repr(float_frame)

fmt.set_option("display.max_rows", 10, "display.max_columns", 2)
repr(float_frame)

fmt.set_option("display.max_rows", 1000, "display.max_columns", 1000)
repr(float_frame)
with option_context("display.max_rows", 10, "display.max_columns", 2):
repr(float_frame)

tm.reset_display_options()
with option_context("display.max_rows", 1000, "display.max_columns", 1000):
repr(float_frame)

def test_repr_unicode(self):
uval = "\u03c3\u03c3\u03c3\u03c3"
Expand Down
50 changes: 28 additions & 22 deletions pandas/tests/io/formats/test_eng_formatting.py
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
import numpy as np
import pytest

from pandas import DataFrame
import pandas._testing as tm
from pandas import (
DataFrame,
reset_option,
set_eng_float_format,
)

import pandas.io.formats.format as fmt
from pandas.io.formats.format import EngFormatter


@pytest.fixture(autouse=True)
def reset_float_format():
yield
reset_option("display.float_format")


class TestEngFormatter:
def test_eng_float_formatter2(self, float_frame):
df = float_frame
df.loc[5] = 0

fmt.set_eng_float_format()
set_eng_float_format()
repr(df)

fmt.set_eng_float_format(use_eng_prefix=True)
set_eng_float_format(use_eng_prefix=True)
repr(df)

fmt.set_eng_float_format(accuracy=0)
set_eng_float_format(accuracy=0)
repr(df)
tm.reset_display_options()

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

fmt.set_eng_float_format()
set_eng_float_format()
result = df.to_string()
expected = (
" A\n"
Expand All @@ -35,18 +44,16 @@ def test_eng_float_formatter(self):
)
assert result == expected

fmt.set_eng_float_format(use_eng_prefix=True)
set_eng_float_format(use_eng_prefix=True)
result = df.to_string()
expected = " A\n0 1.410\n1 141.000\n2 14.100k\n3 1.410M"
assert result == expected

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

tm.reset_display_options()

def compare(self, formatter, input, output):
formatted_input = formatter(input)
assert formatted_input == output
Expand All @@ -67,7 +74,7 @@ def compare_all(self, formatter, in_out):
self.compare(formatter, -input, "-" + output[1:])

def test_exponents_with_eng_prefix(self):
formatter = fmt.EngFormatter(accuracy=3, use_eng_prefix=True)
formatter = EngFormatter(accuracy=3, use_eng_prefix=True)
f = np.sqrt(2)
in_out = [
(f * 10**-24, " 1.414y"),
Expand Down Expand Up @@ -125,7 +132,7 @@ def test_exponents_with_eng_prefix(self):
self.compare_all(formatter, in_out)

def test_exponents_without_eng_prefix(self):
formatter = fmt.EngFormatter(accuracy=4, use_eng_prefix=False)
formatter = EngFormatter(accuracy=4, use_eng_prefix=False)
f = np.pi
in_out = [
(f * 10**-24, " 3.1416E-24"),
Expand Down Expand Up @@ -183,7 +190,7 @@ def test_exponents_without_eng_prefix(self):
self.compare_all(formatter, in_out)

def test_rounding(self):
formatter = fmt.EngFormatter(accuracy=3, use_eng_prefix=True)
formatter = EngFormatter(accuracy=3, use_eng_prefix=True)
in_out = [
(5.55555, " 5.556"),
(55.5555, " 55.556"),
Expand All @@ -194,7 +201,7 @@ def test_rounding(self):
]
self.compare_all(formatter, in_out)

formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
formatter = EngFormatter(accuracy=1, use_eng_prefix=True)
in_out = [
(5.55555, " 5.6"),
(55.5555, " 55.6"),
Expand All @@ -205,7 +212,7 @@ def test_rounding(self):
]
self.compare_all(formatter, in_out)

formatter = fmt.EngFormatter(accuracy=0, use_eng_prefix=True)
formatter = EngFormatter(accuracy=0, use_eng_prefix=True)
in_out = [
(5.55555, " 6"),
(55.5555, " 56"),
Expand All @@ -216,14 +223,14 @@ def test_rounding(self):
]
self.compare_all(formatter, in_out)

formatter = fmt.EngFormatter(accuracy=3, use_eng_prefix=True)
formatter = EngFormatter(accuracy=3, use_eng_prefix=True)
result = formatter(0)
assert result == " 0.000"

def test_nan(self):
# Issue #11981

formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
formatter = EngFormatter(accuracy=1, use_eng_prefix=True)
result = formatter(np.nan)
assert result == "NaN"

Expand All @@ -235,14 +242,13 @@ def test_nan(self):
}
)
pt = df.pivot_table(values="a", index="b", columns="c")
fmt.set_eng_float_format(accuracy=1)
set_eng_float_format(accuracy=1)
result = pt.to_string()
assert "NaN" in result
tm.reset_display_options()

def test_inf(self):
# Issue #11981

formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True)
formatter = EngFormatter(accuracy=1, use_eng_prefix=True)
result = formatter(np.inf)
assert result == "inf"
5 changes: 0 additions & 5 deletions pandas/tests/io/formats/test_to_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,6 @@ def get_ipython():
repstr = df._repr_html_()

assert "class" in repstr # info fallback
tm.reset_display_options()

def test_repr_html(self, float_frame):
df = float_frame
Expand All @@ -926,16 +925,12 @@ def test_repr_html(self, float_frame):
with option_context("display.notebook_repr_html", False):
df._repr_html_()

tm.reset_display_options()

df = DataFrame([[1, 2], [3, 4]])
with option_context("display.show_dimensions", True):
assert "2 rows" in df._repr_html_()
with option_context("display.show_dimensions", False):
assert "2 rows" not in df._repr_html_()

tm.reset_display_options()

def test_repr_html_mathjax(self):
df = DataFrame([[1, 2], [3, 4]])
assert "tex2jax_ignore" not in df._repr_html_()
Expand Down
5 changes: 0 additions & 5 deletions pandas/tests/io/formats/test_to_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,6 @@ def test_to_string_complex_float_formatting(self):

def test_to_string_format_inf(self):
# GH#24861
tm.reset_display_options()
df = DataFrame(
{
"A": [-np.inf, np.inf, -1, -2.1234, 3, 4],
Expand Down Expand Up @@ -460,7 +459,6 @@ def test_to_string_int_formatting(self):
assert output == expected

def test_to_string_float_formatting(self):
tm.reset_display_options()
with option_context(
"display.precision",
5,
Expand Down Expand Up @@ -495,7 +493,6 @@ def test_to_string_float_formatting(self):
expected = " x\n0 3234.000\n1 0.253"
assert df_s == expected

tm.reset_display_options()
assert get_option("display.precision") == 6

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

def test_to_string_left_justify_cols(self):
tm.reset_display_options()
df = DataFrame({"x": [3234, 0.253]})
df_s = df.to_string(justify="left")
expected = " x \n0 3234.000\n1 0.253"
assert df_s == expected

def test_to_string_format_na(self):
tm.reset_display_options()
df = DataFrame(
{
"A": [np.nan, -1, -2.1234, 3, 4],
Expand Down

0 comments on commit 0437fdb

Please sign in to comment.