File tree Expand file tree Collapse file tree 2 files changed +13
-2
lines changed
Expand file tree Collapse file tree 2 files changed +13
-2
lines changed Original file line number Diff line number Diff line change @@ -108,7 +108,9 @@ def __init__(
108108 self .cell_context : DefaultDict [tuple [int , int ], str ] = defaultdict (str )
109109 self ._todo : list [tuple [Callable , tuple , dict ]] = []
110110 self .tooltips : Tooltips | None = None
111- precision = precision or get_option ("styler.format.precision" )
111+ precision = (
112+ get_option ("styler.format.precision" ) if precision is None else precision
113+ )
112114 self ._display_funcs : DefaultDict [ # maps (row, col) -> formatting function
113115 tuple [int , int ], Callable [[Any ], str ]
114116 ] = defaultdict (lambda : partial (_default_formatter , precision = precision ))
@@ -1032,7 +1034,9 @@ def _maybe_wrap_formatter(
10321034 elif callable (formatter ):
10331035 func_0 = formatter
10341036 elif formatter is None :
1035- precision = precision or get_option ("styler.format.precision" )
1037+ precision = (
1038+ get_option ("styler.format.precision" ) if precision is None else precision
1039+ )
10361040 func_0 = partial (
10371041 _default_formatter , precision = precision , thousands = (thousands is not None )
10381042 )
Original file line number Diff line number Diff line change @@ -298,3 +298,10 @@ def test_format_options():
298298 with option_context ("styler.format.formatter" , {"int" : "{:,.2f}" }):
299299 ctx_with_op = df .style ._translate (True , True )
300300 assert ctx_with_op ["body" ][0 ][1 ]["display_value" ] == "2,000.00"
301+
302+
303+ def test_precision_zero (df ):
304+ styler = Styler (df , precision = 0 )
305+ ctx = styler ._translate (True , True )
306+ assert ctx ["body" ][0 ][2 ]["display_value" ] == "-1"
307+ assert ctx ["body" ][1 ][2 ]["display_value" ] == "-1"
You can’t perform that action at this time.
0 commit comments