Beispiel #1
0
    def __init__(self, **kwargs) -> None:
        self._logger = WriterLogger(self)

        self.table_name = kwargs.get("table_name", "")
        self.value_matrix = kwargs.get("value_matrix", [])

        self.is_write_header = True
        self.is_write_header_separator_row = True
        self.is_write_value_separator_row = False
        self.is_write_opening_row = False
        self.is_write_closing_row = False

        self._use_default_header = False

        self._dp_extractor = DataPropertyExtractor()
        self._dp_extractor.min_column_width = 1
        self._dp_extractor.strip_str_header = '"'
        self._dp_extractor.preprocessor = Preprocessor(strip_str='"')
        self._dp_extractor.type_value_map[Typecode.NONE] = ""
        self._dp_extractor.matrix_formatting = MatrixFormatting.HEADER_ALIGNED
        self._dp_extractor.update_strict_level_map({Typecode.BOOL: 1})

        self.is_formatting_float = kwargs.get("is_formatting_float", True)
        self.is_padding = True

        self.headers = kwargs.get("headers", [])
        self.type_hints = kwargs.get("type_hints", [])
        self._quoting_flags = {
            Typecode.BOOL: False,
            Typecode.DATETIME: True,
            Typecode.DICTIONARY: False,
            Typecode.INFINITY: False,
            Typecode.INTEGER: False,
            Typecode.IP_ADDRESS: True,
            Typecode.LIST: False,
            Typecode.NAN: False,
            Typecode.NONE: False,
            Typecode.NULL_STRING: True,
            Typecode.REAL_NUMBER: False,
            Typecode.STRING: True,
        }

        self._is_require_table_name = False
        self._is_require_header = False

        self.iteration_length = -1
        self.write_callback = lambda _iter_count, _iter_length: None  # NOP
        self._iter_count = None  # type: Optional[int]

        self.__default_style = Style()
        self.__col_style_list = kwargs.get("column_styles", [])  # type: List[Optional[Style]]
        self._style_filters = []  # type: List[StyleFilterFunc]
        self._styler = self._create_styler(self)
        self.style_filter_kwargs = {}  # type: Dict[str, Any]
        self.__colorize_terminal = kwargs.get("colorize_terminal", True)
        self.__enable_ansi_escape = True

        self.max_workers = kwargs.get("max_workers", 1)

        self.__clear_preprocess()
def main():
    # sample data definitions
    dt = datetime.datetime(2017, 1, 1, 0, 0, 0)
    inf = float("inf")
    nan = float("nan")
    data_matrix = [
        [1, 1.1,  "aa",   1,   1,     True,   inf,   nan,   dt],
        [2, 2.2,  "bbb",  2.2, 2.2,   False,  "inf", "nan", dt],
        [3, 3.33, "cccc", -3,  "ccc", "true", inf,
            "NAN", "2017-01-01T01:23:45+0900"],
    ]

    # extract property for each column from a matrix
    dp_extractor = DataPropertyExtractor()
    dp_extractor.header_list = [
        "int", "float", "str", "num", "mix", "bool", "inf", "nan", "time"]
    dp_extractor.data_matrix = data_matrix
    col_dp_list = dp_extractor.to_col_dataproperty_list()

    print("---------- typename ----------")
    print([Typecode.get_typename(dp.typecode) for dp in col_dp_list])

    display_col_dp(col_dp_list, "align")
    display_col_dp(col_dp_list, "ascii_char_width")
    display_col_dp(col_dp_list, "decimal_places")

    return 0
Beispiel #3
0
def main():
    # sample data definitions
    dt = datetime.datetime(2017, 1, 1, 0, 0, 0)
    inf = float("inf")
    nan = float("nan")

    # extract data property for each element from a matrix
    dp_extractor = DataPropertyExtractor()
    dp_matrix = dp_extractor.to_dp_matrix([
        [1, 1.1, "aa", 1, 1, True, inf, nan, dt],
        [2, 2.2, "bbb", 2.2, 2.2, False, "inf", "nan", dt],
        [
            3, 3.33, "cccc", -3, "ccc", "true", inf, "NAN",
            "2017-01-01T01:23:45+0900"
        ],
    ])

    print("---------- typename ----------")
    for dp_list in dp_matrix:
        print([dp.typecode.name for dp in dp_list])

    display_dp_matrix_attr(dp_matrix, "data")
    display_dp_matrix_attr(dp_matrix, "align")
    display_dp_matrix_attr(dp_matrix, "ascii_char_width")
    display_dp_matrix_attr(dp_matrix, "integer_digits")
    display_dp_matrix_attr(dp_matrix, "decimal_places")

    return 0
Beispiel #4
0
    def __init__(self, source, quoting_flags):
        self.table_name = tnt.DEFAULT
        self.source = source
        self.__quoting_flags = quoting_flags
        self._validator = None
        self._logger = None

        self.__dp_extractor = DataPropertyExtractor()
        self.__dp_extractor.quoting_flags = self.quoting_flags
Beispiel #5
0
    def __init__(self, source, quoting_flags, type_hints):
        self.table_name = tnt.DEFAULT
        self.source = source
        self.__quoting_flags = quoting_flags
        self.type_hints = type_hints
        self._validator = None
        self._logger = None

        self.__dp_extractor = DataPropertyExtractor()
        self.__dp_extractor.quoting_flags = self.quoting_flags
        self.__dp_extractor.strict_level_map[typepy.Typecode.BOOL] = 1
Beispiel #6
0
def dp_extractor():
    return DataPropertyExtractor()
Beispiel #7
0
    def __init__(self):
        self._logger = WriterLogger(self)

        self._table_name = None
        self.value_matrix = None

        self.is_write_header = True
        self.is_write_header_separator_row = True
        self.is_write_value_separator_row = False
        self.is_write_opening_row = False
        self.is_write_closing_row = False

        self._use_default_header = False

        self._dp_extractor = DataPropertyExtractor()
        self._dp_extractor.min_column_width = 1
        self._dp_extractor.strip_str_header = '"'
        self._dp_extractor.strip_str_value = '"'
        self._dp_extractor.type_value_map[Typecode.NONE] = ""
        self._dp_extractor.matrix_formatting = MatrixFormatting.HEADER_ALIGNED
        self._dp_extractor.strict_level_map[Typecode.BOOL] = 1

        self.is_formatting_float = True
        self.is_padding = True
        self.is_escape_html_tag = False

        self.header_list = None
        self.type_hint_list = None
        self._quoting_flags = {
            Typecode.BOOL: False,
            Typecode.DATETIME: True,
            Typecode.DICTIONARY: False,
            Typecode.INFINITY: False,
            Typecode.INTEGER: False,
            Typecode.IP_ADDRESS: True,
            Typecode.LIST: False,
            Typecode.NAN: False,
            Typecode.NONE: False,
            Typecode.NULL_STRING: True,
            Typecode.REAL_NUMBER: False,
            Typecode.STRING: True,
        }

        self._is_require_table_name = False
        self._is_require_header = False

        self.__line_break_handling = None
        self.line_break_handling = LineBreakHandling.NOP

        self.iteration_length = -1
        self.write_callback = lambda _iter_count, _iter_length: None  # NOP
        self._iter_count = None

        self.__align_list = []
        self.__align_char_mapping = {
            Align.AUTO: "<",
            Align.LEFT: "<",
            Align.RIGHT: ">",
            Align.CENTER: "^",
        }

        self.__style_list = []

        self.__clear_preprocess()
    def __init__(self, **kwargs) -> None:
        self._logger = WriterLogger(self)

        self.table_name = kwargs.get("table_name", "")
        self.value_matrix = kwargs.get("value_matrix", [])

        self.is_write_header = kwargs.get("is_write_header", True)
        self.is_write_header_separator_row = kwargs.get(
            "is_write_header_separator_row", True)
        self.is_write_value_separator_row = kwargs.get(
            "is_write_value_separator_row", False)
        self.is_write_opening_row = kwargs.get("is_write_opening_row", False)
        self.is_write_closing_row = kwargs.get("is_write_closing_row", False)

        self._use_default_header = False

        self._dp_extractor = DataPropertyExtractor(
            max_precision=kwargs.get("max_precision"))
        self._dp_extractor.min_column_width = 1
        self._dp_extractor.strip_str_header = '"'
        self._dp_extractor.preprocessor = Preprocessor(
            dequote=kwargs.get("dequote", True))
        self._dp_extractor.type_value_map[Typecode.NONE] = ""
        self._dp_extractor.matrix_formatting = MatrixFormatting.HEADER_ALIGNED
        self._dp_extractor.update_strict_level_map({Typecode.BOOL: 1})

        self.is_formatting_float = kwargs.get("is_formatting_float", True)
        self.is_padding = kwargs.get("is_padding", True)

        self.headers = kwargs.get("headers", [])
        self.type_hints = kwargs.get("type_hints", [])
        self._quoting_flags = {
            Typecode.BOOL: False,
            Typecode.DATETIME: True,
            Typecode.DICTIONARY: False,
            Typecode.INFINITY: False,
            Typecode.INTEGER: False,
            Typecode.IP_ADDRESS: True,
            Typecode.LIST: False,
            Typecode.NAN: False,
            Typecode.NONE: False,
            Typecode.NULL_STRING: True,
            Typecode.REAL_NUMBER: False,
            Typecode.STRING: True,
        }

        self._is_require_table_name = False
        self._is_require_header = False

        self.iteration_length = kwargs.get("iteration_length", -1)
        self.write_callback = kwargs.get(
            "write_callback",
            lambda _iter_count, _iter_length: None  # defaults to NOP callback
        )
        self._iter_count: Optional[int] = None

        self.__default_style: Style
        self.default_style = kwargs.get("default_style", Style())

        self.__col_style_list: List[Optional[Style]] = []
        self.column_styles = kwargs.get("column_styles", [])

        self._style_filters: List[StyleFilterFunc] = []
        self._styler = self._create_styler(self)
        self.style_filter_kwargs: Dict[str, Any] = kwargs.get(
            "style_filter_kwargs", {})
        self.__colorize_terminal = kwargs.get("colorize_terminal", True)
        self.__enable_ansi_escape = kwargs.get("enable_ansi_escape", True)

        self.max_workers = kwargs.get("max_workers", 1)

        if "dataframe" in kwargs:
            self.from_dataframe(kwargs["dataframe"])

        self.__clear_preprocess()