Skip to content

Commit d210938

Browse files
committed
Format flots to avoid issue with py2.7 / py3.5 compta.
1 parent b22f639 commit d210938

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

pandas/formats/style.py

+12-16
Original file line numberDiff line numberDiff line change
@@ -854,7 +854,6 @@ def set_properties(self, subset=None, **kwargs):
854854
def _bar_left(s, color, width, base):
855855
"""
856856
The minimum value is aligned at the left of the cell
857-
.. versionadded:: 0.17.1
858857
859858
Parameters
860859
----------
@@ -872,8 +871,7 @@ def _bar_left(s, color, width, base):
872871
"""
873872
normed = width * (s - s.min()) / (s.max() - s.min())
874873
zero_normed = width * (0 - s.min()) / (s.max() - s.min())
875-
base = 'width: 10em; height: 80%;'
876-
attrs = (base + 'background: linear-gradient(90deg,{c} {w}%, '
874+
attrs = (base + 'background: linear-gradient(90deg,{c} {w:.1f}%, '
877875
'transparent 0%)')
878876

879877
return [base if x == 0 else attrs.format(c=color[0], w=x)
@@ -885,7 +883,6 @@ def _bar_left(s, color, width, base):
885883
def _bar_center_zero(s, color, width, base):
886884
"""
887885
Creates a bar chart where the zero is centered in the cell
888-
.. versionadded:: 0.19.2
889886
890887
Parameters
891888
----------
@@ -906,15 +903,15 @@ def _bar_center_zero(s, color, width, base):
906903
# (50%, centered on zero)
907904
m = max(abs(s.min()), abs(s.max()))
908905

909-
normed = s * 50 * width / (100 * m)
906+
normed = s * 50 * width / (100.0 * m)
910907

911908
attrs_neg = (base + 'background: linear-gradient(90deg, transparent 0%'
912-
', transparent {w}%, {c} {w}%, '
909+
', transparent {w:.1f}%, {c} {w:.1f}%, '
913910
'{c} 50%, transparent 50%)')
914911

915912
attrs_pos = (base + 'background: linear-gradient(90deg, transparent 0%'
916-
', transparent 50%, {c} 50%, {c} {w}%, '
917-
'transparent {w}%)')
913+
', transparent 50%, {c} 50%, {c} {w:.1f}%, '
914+
'transparent {w:.1f}%)')
918915

919916
return [attrs_pos.format(c=color[1], w=(50 + x)) if x >= 0
920917
else attrs_neg.format(c=color[0], w=(50 + x))
@@ -924,7 +921,6 @@ def _bar_center_zero(s, color, width, base):
924921
def _bar_center_mid(s, color, width, base):
925922
"""
926923
Creates a bar chart where the midpoint is centered in the cell
927-
.. versionadded:: 0.19.2
928924
929925
Parameters
930926
----------
@@ -944,26 +940,26 @@ def _bar_center_mid(s, color, width, base):
944940
if s.min() >= 0:
945941
# In this case, we place the zero at the left, and the max() should
946942
# be at width
947-
zero = 0
943+
zero = 0.0
948944
slope = width / s.max()
949945
elif s.max() <= 0:
950946
# In this case, we place the zero at the right, and the min()
951947
# should be at 100-width
952-
zero = 100
948+
zero = 100.0
953949
slope = width / -s.min()
954950
else:
955951
slope = width / (s.max() - s.min())
956-
zero = (100 + width) / 2 - slope * s.max()
952+
zero = (100.0 + width) / 2.0 - slope * s.max()
957953

958954
normed = zero + slope * s
959955

960956
attrs_neg = (base + 'background: linear-gradient(90deg, transparent 0%'
961-
', transparent {w}%, {c} {w}%, '
962-
'{c} {zero}%, transparent {zero}%)')
957+
', transparent {w:.1f}%, {c} {w:.1f}%, '
958+
'{c} {zero:.1f}%, transparent {zero:.1f}%)')
963959

964960
attrs_pos = (base + 'background: linear-gradient(90deg, transparent 0%'
965-
', transparent {zero}%, {c} {zero}%, {c} {w}%, '
966-
'transparent {w}%)')
961+
', transparent {zero:.1f}%, {c} {zero:.1f}%, '
962+
'{c} {w:.1f}%, transparent {w:.1f}%)')
967963

968964
return [attrs_pos.format(c=color[1], zero=zero, w=x) if x > zero
969965
else attrs_neg.format(c=color[0], zero=zero, w=x)

0 commit comments

Comments
 (0)