Skip to content

TST/CLN: reuse float_frame fixture in tests\io\formats\test_format.py #26756

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 19 additions & 27 deletions pandas/tests/io/formats/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
from shutil import get_terminal_size
import sys
import textwrap
import warnings

import dateutil
import numpy as np
Expand All @@ -31,8 +30,6 @@

use_32bit_repr = is_platform_windows() or is_platform_32bit()

_frame = DataFrame(tm.getSeriesData())


def curpath():
pth, _ = os.path.split(os.path.abspath(__file__))
Expand Down Expand Up @@ -101,18 +98,9 @@ def has_expanded_repr(df):
return False


@pytest.mark.filterwarnings('ignore::FutureWarning:.*format')
class TestDataFrameFormatting:

def setup_method(self, method):
self.warn_filters = warnings.filters
warnings.filterwarnings('ignore', category=FutureWarning,
module=".*format")

self.frame = _frame.copy()

def teardown_method(self, method):
warnings.filters = self.warn_filters

def test_repr_embedded_ndarray(self):
arr = np.empty(10, dtype=[('err', object)])
for i in range(len(arr)):
Expand All @@ -123,17 +111,18 @@ def test_repr_embedded_ndarray(self):
repr(df)
df.to_string()

def test_eng_float_formatter(self):
self.frame.loc[5] = 0
def test_eng_float_formatter(self, float_frame):
df = float_frame
df.loc[5] = 0

fmt.set_eng_float_format()
repr(self.frame)
repr(df)

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

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

def test_show_null_counts(self):
Expand Down Expand Up @@ -467,7 +456,7 @@ def test_to_string_repr_unicode(self):
finally:
sys.stdin = _stdin

def test_to_string_unicode_columns(self):
def test_to_string_unicode_columns(self, float_frame):
df = DataFrame({'\u03c3': np.arange(10.)})

buf = StringIO()
Expand All @@ -478,7 +467,7 @@ def test_to_string_unicode_columns(self):
df.info(buf=buf)
buf.getvalue()

result = self.frame.to_string()
result = float_frame.to_string()
assert isinstance(result, str)

def test_to_string_utf8_columns(self):
Expand Down Expand Up @@ -1513,14 +1502,15 @@ def test_show_dimensions(self):
assert '5 rows' not in str(df)
assert '5 rows' not in df._repr_html_()

def test_repr_html(self):
self.frame._repr_html_()
def test_repr_html(self, float_frame):
df = float_frame
df._repr_html_()

fmt.set_option('display.max_rows', 1, 'display.max_columns', 1)
self.frame._repr_html_()
df._repr_html_()

fmt.set_option('display.notebook_repr_html', False)
self.frame._repr_html_()
df._repr_html_()

tm.reset_display_options()

Expand Down Expand Up @@ -1698,16 +1688,18 @@ def test_info_repr_html(self):
'display.max_columns', max_cols):
assert '<class' in df._repr_html_()

def test_fake_qtconsole_repr_html(self):
def test_fake_qtconsole_repr_html(self, float_frame):
df = float_frame

def get_ipython():
return {'config': {'KernelApp':
{'parent_appname': 'ipython-qtconsole'}}}

repstr = self.frame._repr_html_()
repstr = df._repr_html_()
assert repstr is not None

fmt.set_option('display.max_rows', 5, 'display.max_columns', 2)
repstr = self.frame._repr_html_()
repstr = df._repr_html_()

assert 'class' in repstr # info fallback
tm.reset_display_options()
Expand Down