Skip to content

Commit efef264

Browse files
authored
add formatting benchmarks to Styler render (#41302)
Co-authored-by: JHM Darbyshire (iMac) <attack68@users.noreply.github.com>
1 parent fea6799 commit efef264

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

asv_bench/benchmarks/io/style.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import numpy as np
22

3-
from pandas import DataFrame
3+
from pandas import (
4+
DataFrame,
5+
IndexSlice,
6+
)
47

58

69
class Render:
@@ -31,6 +34,14 @@ def peakmem_classes_render(self, cols, rows):
3134
self._style_classes()
3235
self.st._render_html()
3336

37+
def time_format_render(self, cols, rows):
38+
self._style_format()
39+
self.st.render()
40+
41+
def peakmem_format_render(self, cols, rows):
42+
self._style_format()
43+
self.st.render()
44+
3445
def _style_apply(self):
3546
def _apply_func(s):
3647
return [
@@ -43,3 +54,12 @@ def _style_classes(self):
4354
classes = self.df.applymap(lambda v: ("cls-1" if v > 0 else ""))
4455
classes.index, classes.columns = self.df.index, self.df.columns
4556
self.st = self.df.style.set_td_classes(classes)
57+
58+
def _style_format(self):
59+
ic = int(len(self.df.columns) / 4 * 3)
60+
ir = int(len(self.df.index) / 4 * 3)
61+
# apply a formatting function
62+
# subset is flexible but hinders vectorised solutions
63+
self.st = self.df.style.format(
64+
"{:,.3f}", subset=IndexSlice["row_1":f"row_{ir}", "float_1":f"float_{ic}"]
65+
)

0 commit comments

Comments
 (0)