Skip to content

Commit 132ecfc

Browse files
committed
rounded off the values to avoid floating point error
1 parent 48d5159 commit 132ecfc

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pandas/io/formats/format.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1713,10 +1713,10 @@ def format_percentiles(
17131713

17141714
percentiles = 100 * percentiles
17151715

1716-
int_idx = np.isclose(percentiles.astype(int), percentiles)
1716+
int_idx = np.isclose(percentiles.round(), percentiles)
17171717

17181718
if np.all(int_idx):
1719-
out = percentiles.astype(int).astype(str)
1719+
out = percentiles.round().astype(int).astype(str)
17201720
return [i + "%" for i in out]
17211721

17221722
unique_pcts = np.unique(percentiles)
@@ -1729,7 +1729,7 @@ def format_percentiles(
17291729
).astype(int)
17301730
prec = max(1, prec)
17311731
out = np.empty_like(percentiles, dtype=object)
1732-
out[int_idx] = percentiles[int_idx].astype(int).astype(str)
1732+
out[int_idx] = percentiles[int_idx].round().astype(int).astype(str)
17331733

17341734
out[~int_idx] = percentiles[~int_idx].round(prec).astype(str)
17351735
return [i + "%" for i in out]

0 commit comments

Comments
 (0)