def test_normal_empty_value(self, dp_extractor): dp_extractor.header_list = ["a", "22", "cccc"] dp_extractor.data_matrix = None col_dp_list = dp_extractor.to_col_dataproperty_list() dp = col_dp_list[0] assert dp.typecode == Typecode.NONE assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 1 assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{}" dp = col_dp_list[1] assert dp.typecode == Typecode.NONE assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 2 assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{}" dp = col_dp_list[2] assert dp.typecode == Typecode.NONE assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 4 assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{}"
def __compare_helper(self, lhs, rhs): from typepy.type import Nan if Nan(lhs).is_type() and Nan(rhs).is_type(): return True return lhs == rhs
def test_normal_east_asian_ambiguous_width(self, dp_extractor, ambiguous_width): dp_extractor.header_list = ["ascii", "eaa"] dp_extractor.data_matrix = [ ["abcdefg", "Øαββ"], ["abcdefghij", "ØØ"], ] dp_extractor.east_asian_ambiguous_width = ambiguous_width col_dp_list = dp_extractor.to_col_dataproperty_list() assert len(col_dp_list) == 2 dp = col_dp_list[0] assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 10 assert Nan(dp.decimal_places).is_type() dp = col_dp_list[1] assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 4 * ambiguous_width assert Nan(dp.decimal_places).is_type()
def test_normal_nan(self, value, is_convert, expected_data, expected_typecode): dp = DataProperty( value, strict_type_mapping=get_strict_type_mapping(not is_convert)) assert Nan(dp.data).is_type() assert dp.typecode == expected_typecode
def test_normal_multibyte_char(self): col_dp = ColumnDataProperty() col_dp.update_header(DataProperty("abc")) for value in ["いろは", "abcde"]: col_dp.update_body(DataProperty(value)) assert col_dp.align == Align.LEFT assert Nan(col_dp.decimal_places).is_type() assert col_dp.typecode == Typecode.STRING assert col_dp.ascii_char_width == 6 assert col_dp.minmax_integer_digits.min_value is None assert col_dp.minmax_integer_digits.max_value is None assert col_dp.minmax_decimal_places.min_value is None assert col_dp.minmax_decimal_places.max_value is None assert col_dp.minmax_additional_format_len.min_value == 0 assert col_dp.minmax_additional_format_len.max_value == 0 assert str(col_dp) == ( "typename=STRING, align=left, ascii_char_width=6, " "integer_digits=(min=None, max=None), " "decimal_places=(min=None, max=None), " "additional_format_len=(min=0, max=0)" )
def test_normal_inf(self): col_dp = ColumnDataProperty() col_dp.update_header(DataProperty("inf")) for value in [inf, None, inf, "inf"]: col_dp.update_body(DataProperty(value)) assert col_dp.align == Align.LEFT assert Nan(col_dp.decimal_places).is_type() assert col_dp.typecode == Typecode.INFINITY assert col_dp.ascii_char_width == 8 assert col_dp.minmax_integer_digits.min_value is None assert col_dp.minmax_integer_digits.max_value is None assert col_dp.minmax_decimal_places.min_value is None assert col_dp.minmax_decimal_places.max_value is None assert col_dp.minmax_additional_format_len.min_value == 0 assert col_dp.minmax_additional_format_len.max_value == 0 assert str(col_dp) == ( "typename=INFINITY, align=left, ascii_char_width=8, " "integer_digits=(min=None, max=None), " "decimal_places=(min=None, max=None), " "additional_format_len=(min=0, max=0)")
def __get_decimal_places(self): try: avg = self.minmax_decimal_places.mean() except TypeError: return float("nan") if Nan(avg).is_type(): return float("nan") return int( min(math.ceil(avg + Decimal("1.0")), self.minmax_decimal_places.max_value))
def test_normal_nan_inf(self, dp_extractor): dp_extractor.header_list = ["n", "i"] dp_extractor.data_matrix = [ [nan, inf], ["nan", "inf"], ] col_dp_list = dp_extractor.to_col_dataproperty_list() assert len(col_dp_list) == 2 dp = col_dp_list[0] assert dp.typecode == Typecode.NAN assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 3 assert Nan(dp.decimal_places).is_type() dp = col_dp_list[1] assert dp.typecode == Typecode.INFINITY assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 8 assert Nan(dp.decimal_places).is_type()
def __get_format_str(self): format_str = { Typecode.NONE: "{}", Typecode.INTEGER: "{:d}", Typecode.BOOL: "{}", Typecode.DATETIME: "{:" + self.__datetime_format_str + "}", Typecode.DICTIONARY: "{}", Typecode.LIST: "{}", }.get(self.typecode) if format_str is not None: return format_str if self.typecode in (Typecode.REAL_NUMBER, Typecode.INFINITY, Typecode.NAN): if Nan(self.decimal_places).is_type(): return "{:f}" return "{:" + ".{:d}f".format(self.decimal_places) + "}" return "{:s}"
def test_normal_east_asian_ambiguous_width( self, ambiguous_width, ascii_char_width): col_dp = ColumnDataProperty( east_asian_ambiguous_width=ambiguous_width) col_dp.update_header(DataProperty("abc")) for value in ["ØØØ", "α", "ββ"]: col_dp.update_body(DataProperty( value, east_asian_ambiguous_width=ambiguous_width)) assert col_dp.align == Align.LEFT assert Nan(col_dp.decimal_places).is_type() assert col_dp.typecode == Typecode.STRING assert col_dp.ascii_char_width == ascii_char_width assert col_dp.minmax_integer_digits.min_value is None assert col_dp.minmax_integer_digits.max_value is None assert col_dp.minmax_decimal_places.min_value is None assert col_dp.minmax_decimal_places.max_value is None assert col_dp.minmax_additional_format_len.min_value == 0 assert col_dp.minmax_additional_format_len.max_value == 0
def test_abnormal(self, value, expected): dp = DataProperty(value) Nan(dp.length).is_type()
def test_normal_default(self, dp_extractor, header_list, value): dp_extractor.header_list = header_list dp_extractor.data_matrix = value col_dp_list = dp_extractor.to_col_dataproperty_list() assert len(col_dp_list) == 9 col_idx = 0 dp = col_dp_list[col_idx] assert dp.column_index == col_idx assert dp.typecode == Typecode.INTEGER assert dp.align.align_code == Align.RIGHT.align_code assert dp.align.align_string == Align.RIGHT.align_string assert dp.ascii_char_width == 1 assert dp.decimal_places == 0 assert dp.format_str == "{:d}" assert str(dp) == ( "typename=INTEGER, column=0, align=right, " "ascii_char_width=1, integer_digits=(min=1, max=1), " "decimal_places=(min=0, max=0), " "additional_format_len=(min=0, max=0)") col_idx += 1 dp = col_dp_list[col_idx] assert dp.column_index == col_idx assert dp.typecode == Typecode.REAL_NUMBER assert dp.align.align_code == Align.RIGHT.align_code assert dp.align.align_string == Align.RIGHT.align_string assert dp.ascii_char_width == 4 assert dp.decimal_places == 2 assert dp.format_str == "{:.2f}" col_idx += 1 dp = col_dp_list[col_idx] assert dp.column_index == col_idx assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 4 assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:s}" col_idx += 1 dp = col_dp_list[col_idx] assert dp.column_index == col_idx assert dp.typecode == Typecode.REAL_NUMBER assert dp.align.align_code == Align.RIGHT.align_code assert dp.align.align_string == Align.RIGHT.align_string assert dp.ascii_char_width == 4 assert dp.decimal_places == 1 assert dp.format_str == "{:.1f}" col_idx += 1 dp = col_dp_list[col_idx] assert dp.column_index == col_idx assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 3 assert dp.decimal_places == 1 assert dp.format_str == "{:s}" col_idx += 1 dp = col_dp_list[col_idx] assert dp.column_index == col_idx assert dp.typecode == Typecode.BOOL assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 5 assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{}" col_idx += 1 dp = col_dp_list[col_idx] assert dp.column_index == col_idx assert dp.typecode == Typecode.INFINITY assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 8 assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:f}" col_idx += 1 dp = col_dp_list[col_idx] assert dp.column_index == col_idx assert dp.typecode == Typecode.NAN assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 3 assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:f}" col_idx += 1 dp = col_dp_list[col_idx] assert dp.column_index == col_idx assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert dp.ascii_char_width == 24 assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:s}"
def test_null(self, container): assert Nan(container.mean()).is_type()
def test_nan(self, value): integer_digits, decimal_places = get_number_of_digit(value) assert Nan(integer_digits).is_type() assert Nan(decimal_places).is_type()
def test_null(self): col_dp = ColumnDataProperty() assert col_dp.align == Align.LEFT assert Nan(col_dp.decimal_places).is_type() assert col_dp.typecode == Typecode.NONE assert col_dp.ascii_char_width == 0
def test_abnormal(self, value): dp = DataProperty(value) Nan(dp.integer_digits).is_type()
def test_abnormal(self, value): dp = DataProperty(value) Nan(dp.decimal_places).is_type()
def test_normal(self, dp_extractor, value, type_value_mapping, const_value_mapping, datetime_formatter): dp_extractor.data_matrix = value dp_extractor.type_value_mapping = type_value_mapping dp_extractor.const_value_mapping = const_value_mapping dp_extractor.datetime_formatter = datetime_formatter dp_matrix = list(dp_extractor.to_dataproperty_matrix()) assert len(dp_matrix) == 4 dp = dp_matrix[0][0] assert dp.data == "null" assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:s}" dp = dp_matrix[0][1] assert dp.data == 1 assert dp.typecode == Typecode.INTEGER assert dp.align.align_code == Align.RIGHT.align_code assert dp.align.align_string == Align.RIGHT.align_string assert dp.decimal_places == 0 assert dp.format_str == "{:d}" dp = dp_matrix[1][0] assert dp.data == Decimal("1.1") assert dp.typecode == Typecode.REAL_NUMBER assert dp.align.align_code == Align.RIGHT.align_code assert dp.align.align_string == Align.RIGHT.align_string assert dp.decimal_places == 1 assert dp.format_str == "{:.1f}" dp = dp_matrix[1][1] assert dp.data == "a" assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:s}" dp = dp_matrix[2][0] assert dp.data == "NAN" assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:s}" dp = dp_matrix[2][1] assert dp.data == "INFINITY" assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:s}" dp = dp_matrix[3][0] assert dp.data == "false" assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:s}" dp = dp_matrix[3][1] assert dp.data == "20170102 030405" assert dp.typecode == Typecode.STRING assert dp.align.align_code == Align.LEFT.align_code assert dp.align.align_string == Align.LEFT.align_string assert Nan(dp.decimal_places).is_type() assert dp.format_str == "{:s}"