<commit_before>import pandas
import numpy

class TableStyle(object):
    """
    Keep track of styles for cells/headers in PrettyTable
    """
    def __init__(self, theme=None):
        self.row_head_style = CellStyle()
        self.col_head_style = CellStyle()
        self.cell_style = CellStyle()
        self.corner_style = CellStyle()

        # add themes as needed
        if theme == "basic":
            self.cell_style.set("border", "1px solid black")
            self.col_head_style.set("font-weight", "bold")
            self.row_head_style.set("font-weight", "bold")

        if theme == "theme1":
            self.cell_style.set("border", "1px solid black")
            self.cell_style.set("color", "black")
            self.col_head_style.set("color", "black")
            self.row_head_style.set("color", "black")
            self.col_head_style.set("font-weight", "bold")
            self.row_head_style.set("font_weight", "bold")
            self.col_head_style.set("background-color", "lightgray")
            self.row_head_style.set("background-color", "lightgray")

class CellStyle(object):
    """
    Styles for cells PrettyTable
    """
    
    def __init__(self):
        self.style_elements = {} # dictionary of CSS property -> value
        self.format_function = None

    def set(self, key, value):
        self.style_elements[key] = value

    def css(self):
        style = ""
        for key in self.style_elements:
            style += "%s: %s;"%(key, self.style_elements[key])
        return style

    def column_format(self, x):
        if self.format_function is None: return str(x)
        else:
            try:
                return self.format_function(x)
            except: return str(x)

    def copy(self):
        c = CellStyle()
        c.style_elements = self.style_elements.copy()
        c.format_function = self.format_function
        return c

class PrettyTable(object):
    """
    Formatted tables for display in IPython notebooks
    """

    def __init__(self, df, tstyle=None, header_row=False, header_col=True, center=False):
        """
        df: pandas.DataFrame
        style: TableStyle
        header_row: include row headers
        header_col: include column headers
        """
        self.df = df
        self.num_rows = df.shape[0]
        self.num_cols = df.shape[1]
        self.header_row = header_row
        self.header_col = header_col
        self.style = tstyle
        self.center = center

        # overall table style
        if tstyle is None:
            self.cell_style = CellStyle()
            self.corner_style = CellStyle()
            self.header_row_styles = [CellStyle() for i in range(self.num_rows)]
            self.header_col_styles = [CellStyle() for i in range(self.num_cols)]
            self.cell_styles = [[CellStyle() for i in range(self.num_cols)]\
                                for j in range(self.num_rows)]
        else:
            self.cell_style = tstyle.cell_style
            self.corner_style = tstyle.corner_style
            self.header_row_styles = [tstyle.row_head_style.copy() for i in range(self.num_rows)]
            self.header_col_styles = [tstyle.col_head_style.copy() for i in range(self.num_cols)]
            self.cell_styles = [[self.cell_style.copy() for i in range(self.num_cols)]\
                                    for j in range(self.num_rows)]

    # functions to set styles
    def set_cell_style(self, style=None, rows=None, cols=None, format_function=None, **kwargs):
        """
        Apply cell style to rows and columns specified
        """
        if style is None: style = CellStyle()
        for key, value in kwargs.iteritems():
            k = key.replace("_", "-")
            style.set(k, value)
        if format_function is not None: style.format_function = format_function
        if rows is None: rows = range(self.num_rows)
        if cols is None: cols = range(self.num_cols)
        for i in rows:
            for j in cols:
                self.cell_styles[i][j] = style.copy()

    def set_row_header_style(self, style=None, indices=None, format_function=None, **kwargs):
        """
        Apply style to header at specific index<commit_msg>Update itable.py<commit_after>import pandas
import numpy

class TableStyle(object):
    """
    Keep track of styles for cells/headers in PrettyTable
    """
    def __init__(self, theme=None):
        self.row_head_style = CellStyle()
        self.col_head_style = CellStyle()
        self.cell_style = CellStyle()
        self.corner_style = CellStyle()

        # add themes as needed
        if theme == "basic":
            self.cell_style.set("border", "1px solid black")
            self.col_head_style.set("font-weight", "bold")
            self.row_head_style.set("font-weight", "bold")

        if theme == "theme1":
            self.cell_style.set("border", "1px solid black")
            self.cell_style.set("color", "black")
            self.col_head_style.set("color", "black")
            self.row_head_style.set("color", "black")
            self.col_head_style.set("font-weight", "bold")
            self.row_head_style.set("font_weight", "bold")
            self.col_head_style.set("background-color", "lightgray")
            self.row_head_style.set("background-color", "lightgray")

class CellStyle(object):
    """
    Styles for cells PrettyTable
    """
    
    def __init__(self):
        self.style_elements = {} # dictionary of CSS property -> value
        self.format_function = None

    def set(self, key, value):
        self.style_elements[key] = value

    def css(self):
        style = ""
        for key in self.style_elements:
            style += "%s: %s;"%(key, self.style_elements[key])
        return style

    def column_format(self, x):
        if self.format_function is None: return str(x)
        else:
            try:
                return self.format_function(x)
            except: return str(x)

    def copy(self):
        c = CellStyle()
        c.style_elements = self.style_elements.copy()
        c.format_function = self.format_function
        return c

class PrettyTable(object):
    """
    Formatted tables for display in IPython notebooks
    """

    def __init__(self, df, tstyle=None, header_row=False, header_col=True, center=False):
        """
        df: pandas.DataFrame
        style: TableStyle
        header_row: include row headers
        header_col: include column headers
        """
        self.df = df
        self.num_rows = df.shape[0]
        self.num_cols = df.shape[1]
        self.header_row = header_row
        self.header_col = header_col
        self.style = tstyle
        self.center = center

        # overall table style
        if tstyle is None:
            self.cell_style = CellStyle()
            self.corner_style = CellStyle()
            self.header_row_styles = [CellStyle() for i in range(self.num_rows)]
            self.header_col_styles = [CellStyle() for i in range(self.num_cols)]
            self.cell_styles = [[CellStyle() for i in range(self.num_cols)]\
                                for j in range(self.num_rows)]
        else:
            self.cell_style = tstyle.cell_style
            self.corner_style = tstyle.corner_style
            self.header_row_styles = [tstyle.row_head_style.copy() for i in range(self.num_rows)]
            self.header_col_styles = [tstyle.col_head_style.copy() for i in range(self.num_cols)]
            self.cell_styles = [[self.cell_style.copy() for i in range(self.num_cols)]\
                                    for j in range(self.num_rows)]

    # functions to set styles
    def set_cell_style(self, style=None, rows=None, cols=None, format_function=None, **kwargs):
        """
        Apply cell style to rows and columns specified
        """
        if style is None: style = CellStyle()
        for key, value in kwargs.iteritems():
            k = key.replace("_", "-")
            style.set(k, value)
        if format_function is not None: style.format_function = format_function
        if rows is None: rows = range(self.num_rows)
        if cols is None: cols = range(self.num_cols)
        for i in rows:
            for j in cols:
                self.cell_styles[i][j] = style.copy()
                
    def set_cell_style(self, tuples, style=None, format_function=None, **kwargs):
        """
        Apply cell style to rows and columns specified
        """
        if style is None: style = CellStyle()
        for key, value in kwargs.iteritems():
            k = key.replace("_", "-")
            style.set(k, value)
        if format_function is not None: style.format_function = format_function
        for tuple in tuples:
			i = tuple[0]
			j = tuple[1]
			self.cell_styles[i][j] = style.copy()

    def set_row_header_style(self, style=None, indices=None, format_function=None, **kwargs):
        """
        Apply style to header at specific index
{'fraction_non_alphanumeric': 0.1089119982108912, 'fraction_numerical': 0.0013418316001341832, 'mean_word_length': 2.1481872580077437, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1018868', 'n_tokens_mistral': 2642, 'n_tokens_neox': 2596, 'n_words': 646}