def test_repr_unsortable(self, float_frame): # columns are not sortable warn_filters = warnings.filters warnings.filterwarnings("ignore", category=FutureWarning, module=".*format") unsortable = DataFrame( { "foo": [1] * 50, datetime.today(): [1] * 50, "bar": ["bar"] * 50, datetime.today() + timedelta(1): ["bar"] * 50, }, index=np.arange(50), ) repr(unsortable) fmt.set_option("display.precision", 3, "display.column_space", 10) 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) tm.reset_display_options() warnings.filters = warn_filters
def test_eng_float_formatter(self): df = DataFrame({"A": [1.41, 141.0, 14100, 1410000.0]}) fmt.set_eng_float_format() result = df.to_string() expected = ( " A\n" "0 1.410E+00\n" "1 141.000E+00\n" "2 14.100E+03\n" "3 1.410E+06" ) assert result == expected fmt.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) 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 test_format_sparse_config(idx): warn_filters = warnings.filters warnings.filterwarnings("ignore", category=FutureWarning, module=".*format") # GH1538 pd.set_option("display.multi_sparse", False) result = idx.format() assert result[1] == "foo two" tm.reset_display_options() warnings.filters = warn_filters
def test_nan(self): # Issue #11981 formatter = fmt.EngFormatter(accuracy=1, use_eng_prefix=True) result = formatter(np.nan) assert result == "NaN" df = pd.DataFrame({ "a": [1.5, 10.3, 20.5], "b": [50.3, 60.67, 70.12], "c": [100.2, 101.33, 120.33], }) pt = df.pivot_table(values="a", index="b", columns="c") fmt.set_eng_float_format(accuracy=1) result = pt.to_string() assert "NaN" in result tm.reset_display_options()