Skip to content

Commit 01c200c

Browse files
committed
Format flots to avoid issue with py2.7 / py3.5 compta.
1 parent 7ac2443 commit 01c200c

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
@@ -860,7 +860,6 @@ def set_properties(self, subset=None, **kwargs):
860860
def _bar_left(s, color, width, base):
861861
"""
862862
The minimum value is aligned at the left of the cell
863-
.. versionadded:: 0.17.1
864863
865864
Parameters
866865
----------
@@ -878,8 +877,7 @@ def _bar_left(s, color, width, base):
878877
"""
879878
normed = width * (s - s.min()) / (s.max() - s.min())
880879
zero_normed = width * (0 - s.min()) / (s.max() - s.min())
881-
base = 'width: 10em; height: 80%;'
882-
attrs = (base + 'background: linear-gradient(90deg,{c} {w}%, '
880+
attrs = (base + 'background: linear-gradient(90deg,{c} {w:.1f}%, '
883881
'transparent 0%)')
884882

885883
return [base if x == 0 else attrs.format(c=color[0], w=x)
@@ -891,7 +889,6 @@ def _bar_left(s, color, width, base):
891889
def _bar_center_zero(s, color, width, base):
892890
"""
893891
Creates a bar chart where the zero is centered in the cell
894-
.. versionadded:: 0.19.2
895892
896893
Parameters
897894
----------
@@ -912,15 +909,15 @@ def _bar_center_zero(s, color, width, base):
912909
# (50%, centered on zero)
913910
m = max(abs(s.min()), abs(s.max()))
914911

915-
normed = s * 50 * width / (100 * m)
912+
normed = s * 50 * width / (100.0 * m)
916913

917914
attrs_neg = (base + 'background: linear-gradient(90deg, transparent 0%'
918-
', transparent {w}%, {c} {w}%, '
915+
', transparent {w:.1f}%, {c} {w:.1f}%, '
919916
'{c} 50%, transparent 50%)')
920917

921918
attrs_pos = (base + 'background: linear-gradient(90deg, transparent 0%'
922-
', transparent 50%, {c} 50%, {c} {w}%, '
923-
'transparent {w}%)')
919+
', transparent 50%, {c} 50%, {c} {w:.1f}%, '
920+
'transparent {w:.1f}%)')
924921

925922
return [attrs_pos.format(c=color[1], w=(50 + x)) if x >= 0
926923
else attrs_neg.format(c=color[0], w=(50 + x))
@@ -930,7 +927,6 @@ def _bar_center_zero(s, color, width, base):
930927
def _bar_center_mid(s, color, width, base):
931928
"""
932929
Creates a bar chart where the midpoint is centered in the cell
933-
.. versionadded:: 0.19.2
934930
935931
Parameters
936932
----------
@@ -950,26 +946,26 @@ def _bar_center_mid(s, color, width, base):
950946
if s.min() >= 0:
951947
# In this case, we place the zero at the left, and the max() should
952948
# be at width
953-
zero = 0
949+
zero = 0.0
954950
slope = width / s.max()
955951
elif s.max() <= 0:
956952
# In this case, we place the zero at the right, and the min()
957953
# should be at 100-width
958-
zero = 100
954+
zero = 100.0
959955
slope = width / -s.min()
960956
else:
961957
slope = width / (s.max() - s.min())
962-
zero = (100 + width) / 2 - slope * s.max()
958+
zero = (100.0 + width) / 2.0 - slope * s.max()
963959

964960
normed = zero + slope * s
965961

966962
attrs_neg = (base + 'background: linear-gradient(90deg, transparent 0%'
967-
', transparent {w}%, {c} {w}%, '
968-
'{c} {zero}%, transparent {zero}%)')
963+
', transparent {w:.1f}%, {c} {w:.1f}%, '
964+
'{c} {zero:.1f}%, transparent {zero:.1f}%)')
969965

970966
attrs_pos = (base + 'background: linear-gradient(90deg, transparent 0%'
971-
', transparent {zero}%, {c} {zero}%, {c} {w}%, '
972-
'transparent {w}%)')
967+
', transparent {zero:.1f}%, {c} {zero:.1f}%, '
968+
'{c} {w:.1f}%, transparent {w:.1f}%)')
973969

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

0 commit comments

Comments
 (0)