Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- env-llmeval/lib/python3.10/site-packages/dataproperty/__init__.py +45 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/__version__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_align.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_align_getter.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_base.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_column.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_common.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_container.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_converter.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_dataproperty.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_extractor.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_formatter.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_function.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_interface.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_line_break.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_preprocessor.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/typing.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/__version__.py +6 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_align.py +25 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_align_getter.py +33 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_base.py +98 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_column.py +352 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_common.py +69 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_container.py +193 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_converter.py +90 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_dataproperty.py +382 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_extractor.py +814 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_formatter.py +98 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_function.py +112 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_interface.py +30 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_line_break.py +8 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/_preprocessor.py +173 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/logger/__init__.py +7 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/logger/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/logger/__pycache__/_logger.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/logger/__pycache__/_null_logger.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/logger/_logger.py +22 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/logger/_null_logger.py +41 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/py.typed +0 -0
- env-llmeval/lib/python3.10/site-packages/dataproperty/typing.py +62 -0
- env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/__init__.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/conftest.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/convert.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/convert_matrix.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/exception.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/lazy_imports.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/relabel.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/networkx/algorithms/approximation/__pycache__/traveling_salesman.cpython-310.pyc +0 -0
- env-llmeval/lib/python3.10/site-packages/networkx/algorithms/approximation/__pycache__/treewidth.cpython-310.pyc +0 -0
env-llmeval/lib/python3.10/site-packages/dataproperty/__init__.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from .__version__ import __author__, __copyright__, __email__, __license__, __version__
|
6 |
+
from ._align import Align
|
7 |
+
from ._align_getter import align_getter
|
8 |
+
from ._column import ColumnDataProperty
|
9 |
+
from ._common import MAX_STRICT_LEVEL_MAP, MIN_STRICT_LEVEL_MAP, NOT_QUOTING_FLAGS, DefaultValue
|
10 |
+
from ._container import MinMaxContainer
|
11 |
+
from ._dataproperty import DataProperty
|
12 |
+
from ._extractor import DataPropertyExtractor, DataPropertyMatrix, MatrixFormatting
|
13 |
+
from ._formatter import Format
|
14 |
+
from ._function import calc_ascii_char_width, get_integer_digit, get_number_of_digit
|
15 |
+
from ._line_break import LineBreakHandling
|
16 |
+
from ._preprocessor import Preprocessor
|
17 |
+
from .logger import set_logger
|
18 |
+
|
19 |
+
|
20 |
+
__all__ = (
|
21 |
+
"Align",
|
22 |
+
"align_getter",
|
23 |
+
"ColumnDataProperty",
|
24 |
+
"DataProperty",
|
25 |
+
"DataPropertyExtractor",
|
26 |
+
"DataPropertyMatrix",
|
27 |
+
"Format",
|
28 |
+
"LineBreakHandling",
|
29 |
+
"MatrixFormatting",
|
30 |
+
"MinMaxContainer",
|
31 |
+
"Preprocessor",
|
32 |
+
"calc_ascii_char_width",
|
33 |
+
"get_integer_digit",
|
34 |
+
"get_number_of_digit",
|
35 |
+
"MAX_STRICT_LEVEL_MAP",
|
36 |
+
"MIN_STRICT_LEVEL_MAP",
|
37 |
+
"NOT_QUOTING_FLAGS",
|
38 |
+
"DefaultValue",
|
39 |
+
"set_logger",
|
40 |
+
"__author__",
|
41 |
+
"__copyright__",
|
42 |
+
"__email__",
|
43 |
+
"__license__",
|
44 |
+
"__version__",
|
45 |
+
)
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (1.3 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/__version__.cpython-310.pyc
ADDED
Binary file (383 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_align.cpython-310.pyc
ADDED
Binary file (1.06 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_align_getter.cpython-310.pyc
ADDED
Binary file (1.39 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_base.cpython-310.pyc
ADDED
Binary file (2.67 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_column.cpython-310.pyc
ADDED
Binary file (10.5 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_common.cpython-310.pyc
ADDED
Binary file (1.78 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_container.cpython-310.pyc
ADDED
Binary file (6.12 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_converter.cpython-310.pyc
ADDED
Binary file (3.29 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_dataproperty.cpython-310.pyc
ADDED
Binary file (9.38 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_extractor.cpython-310.pyc
ADDED
Binary file (20.6 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_formatter.cpython-310.pyc
ADDED
Binary file (3 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_function.cpython-310.pyc
ADDED
Binary file (3.18 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_interface.cpython-310.pyc
ADDED
Binary file (1.25 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_line_break.cpython-310.pyc
ADDED
Binary file (457 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/_preprocessor.cpython-310.pyc
ADDED
Binary file (4.92 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__pycache__/typing.cpython-310.pyc
ADDED
Binary file (1.39 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/__version__.py
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
__author__ = "Tsuyoshi Hombashi"
|
2 |
+
__copyright__ = f"Copyright 2016, {__author__}"
|
3 |
+
__license__ = "MIT License"
|
4 |
+
__version__ = "1.0.1"
|
5 |
+
__maintainer__ = __author__
|
6 |
+
__email__ = "[email protected]"
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_align.py
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import enum
|
6 |
+
|
7 |
+
|
8 |
+
@enum.unique
|
9 |
+
class Align(enum.Enum):
|
10 |
+
AUTO = (1 << 0, "auto")
|
11 |
+
LEFT = (1 << 1, "left")
|
12 |
+
RIGHT = (1 << 2, "right")
|
13 |
+
CENTER = (1 << 3, "center")
|
14 |
+
|
15 |
+
@property
|
16 |
+
def align_code(self) -> int:
|
17 |
+
return self.__align_code
|
18 |
+
|
19 |
+
@property
|
20 |
+
def align_string(self) -> str:
|
21 |
+
return self.__align_string
|
22 |
+
|
23 |
+
def __init__(self, code: int, string: str) -> None:
|
24 |
+
self.__align_code = code
|
25 |
+
self.__align_string = string
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_align_getter.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from typing import Dict
|
6 |
+
|
7 |
+
from typepy import Typecode
|
8 |
+
|
9 |
+
from ._align import Align
|
10 |
+
|
11 |
+
|
12 |
+
class AlignGetter:
|
13 |
+
@property
|
14 |
+
def typecode_align_table(self):
|
15 |
+
raise NotImplementedError()
|
16 |
+
|
17 |
+
@typecode_align_table.setter
|
18 |
+
def typecode_align_table(self, x: Dict[Typecode, Align]) -> None:
|
19 |
+
self.__typecode_align_table = x
|
20 |
+
|
21 |
+
def get_align_from_typecode(self, typecode: Typecode) -> Align:
|
22 |
+
return self.__typecode_align_table.get(typecode, self.default_align)
|
23 |
+
|
24 |
+
def __init__(self) -> None:
|
25 |
+
self.typecode_align_table = {
|
26 |
+
Typecode.STRING: Align.LEFT,
|
27 |
+
Typecode.INTEGER: Align.RIGHT,
|
28 |
+
Typecode.REAL_NUMBER: Align.RIGHT,
|
29 |
+
}
|
30 |
+
self.default_align = Align.LEFT
|
31 |
+
|
32 |
+
|
33 |
+
align_getter = AlignGetter()
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_base.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Dict, Optional, Type
|
2 |
+
|
3 |
+
from typepy import (
|
4 |
+
Bool,
|
5 |
+
DateTime,
|
6 |
+
Dictionary,
|
7 |
+
Infinity,
|
8 |
+
Integer,
|
9 |
+
IpAddress,
|
10 |
+
List,
|
11 |
+
Nan,
|
12 |
+
NoneType,
|
13 |
+
NullString,
|
14 |
+
RealNumber,
|
15 |
+
String,
|
16 |
+
Typecode,
|
17 |
+
)
|
18 |
+
from typepy.type import AbstractType
|
19 |
+
|
20 |
+
from ._formatter import Formatter
|
21 |
+
from ._interface import DataPeropertyInterface
|
22 |
+
|
23 |
+
|
24 |
+
class DataPeropertyBase(DataPeropertyInterface):
|
25 |
+
__slots__ = (
|
26 |
+
"_datetime_format_str",
|
27 |
+
"_decimal_places",
|
28 |
+
"_east_asian_ambiguous_width",
|
29 |
+
"_formatter",
|
30 |
+
"_typecode",
|
31 |
+
"__format_str",
|
32 |
+
)
|
33 |
+
|
34 |
+
__TYPE_CLASS_TABLE: Dict[Typecode, AbstractType] = {
|
35 |
+
Typecode.BOOL: Bool,
|
36 |
+
Typecode.DATETIME: DateTime,
|
37 |
+
Typecode.DICTIONARY: Dictionary,
|
38 |
+
Typecode.INTEGER: Integer,
|
39 |
+
Typecode.INFINITY: Infinity,
|
40 |
+
Typecode.IP_ADDRESS: IpAddress,
|
41 |
+
Typecode.LIST: List,
|
42 |
+
Typecode.NAN: Nan,
|
43 |
+
Typecode.NONE: NoneType,
|
44 |
+
Typecode.NULL_STRING: NullString,
|
45 |
+
Typecode.REAL_NUMBER: RealNumber,
|
46 |
+
Typecode.STRING: String,
|
47 |
+
}
|
48 |
+
|
49 |
+
@property
|
50 |
+
def type_class(self) -> Type[AbstractType]:
|
51 |
+
return self.__TYPE_CLASS_TABLE[self.typecode]
|
52 |
+
|
53 |
+
@property
|
54 |
+
def typecode(self) -> Typecode:
|
55 |
+
"""
|
56 |
+
``typepy.Typecode`` that corresponds to the type of the ``data``.
|
57 |
+
|
58 |
+
:return:
|
59 |
+
One of the Enum value that are defined ``typepy.Typecode``.
|
60 |
+
:rtype: typepy.Typecode
|
61 |
+
"""
|
62 |
+
|
63 |
+
assert self._typecode
|
64 |
+
|
65 |
+
return self._typecode
|
66 |
+
|
67 |
+
@property
|
68 |
+
def typename(self) -> str:
|
69 |
+
return self.typecode.name
|
70 |
+
|
71 |
+
def __init__(
|
72 |
+
self,
|
73 |
+
format_flags: Optional[int],
|
74 |
+
is_formatting_float: bool,
|
75 |
+
datetime_format_str: str,
|
76 |
+
east_asian_ambiguous_width: int,
|
77 |
+
) -> None:
|
78 |
+
self._decimal_places: Optional[int] = None
|
79 |
+
self._east_asian_ambiguous_width = east_asian_ambiguous_width
|
80 |
+
self._typecode: Optional[Typecode] = None
|
81 |
+
|
82 |
+
self._datetime_format_str = datetime_format_str
|
83 |
+
self.__format_str = ""
|
84 |
+
|
85 |
+
self._formatter = Formatter(
|
86 |
+
format_flags=format_flags,
|
87 |
+
datetime_format_str=self._datetime_format_str,
|
88 |
+
is_formatting_float=is_formatting_float,
|
89 |
+
)
|
90 |
+
|
91 |
+
@property
|
92 |
+
def format_str(self) -> str:
|
93 |
+
if self.__format_str:
|
94 |
+
return self.__format_str
|
95 |
+
|
96 |
+
self.__format_str = self._formatter.make_format_str(self.typecode, self.decimal_places)
|
97 |
+
|
98 |
+
return self.__format_str
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_column.py
ADDED
@@ -0,0 +1,352 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from typing import Any, Dict, List, Optional
|
2 |
+
|
3 |
+
from mbstrdecoder import MultiByteStrDecoder
|
4 |
+
from typepy import Integer, StrictLevel, Typecode, TypeConversionError
|
5 |
+
|
6 |
+
from ._align import Align
|
7 |
+
from ._align_getter import align_getter
|
8 |
+
from ._base import DataPeropertyBase
|
9 |
+
from ._common import DefaultValue
|
10 |
+
from ._container import ListContainer, MinMaxContainer
|
11 |
+
from ._dataproperty import DataProperty
|
12 |
+
from ._function import calc_ascii_char_width
|
13 |
+
from .typing import FloatType
|
14 |
+
|
15 |
+
|
16 |
+
class ColumnDataProperty(DataPeropertyBase):
|
17 |
+
__slots__ = (
|
18 |
+
"__header_ascii_char_width",
|
19 |
+
"__body_ascii_char_width",
|
20 |
+
"__column_index",
|
21 |
+
"__dp_list",
|
22 |
+
"__float_type",
|
23 |
+
"__format_map",
|
24 |
+
"__is_calculate",
|
25 |
+
"__max_precision",
|
26 |
+
"__minmax_integer_digits",
|
27 |
+
"__minmax_decimal_places",
|
28 |
+
"__minmax_additional_format_len",
|
29 |
+
"__typecode_bitmap",
|
30 |
+
)
|
31 |
+
|
32 |
+
@property
|
33 |
+
def align(self) -> Align:
|
34 |
+
return align_getter.get_align_from_typecode(self.typecode)
|
35 |
+
|
36 |
+
@property
|
37 |
+
def bit_length(self) -> Optional[int]:
|
38 |
+
if self.typecode != Typecode.INTEGER:
|
39 |
+
return None
|
40 |
+
|
41 |
+
bit_length = 0
|
42 |
+
for value_dp in self.__dp_list:
|
43 |
+
try:
|
44 |
+
bit_length = max(bit_length, int.bit_length(value_dp.data))
|
45 |
+
except TypeError:
|
46 |
+
pass
|
47 |
+
|
48 |
+
return bit_length
|
49 |
+
|
50 |
+
@property
|
51 |
+
def column_index(self) -> int:
|
52 |
+
return self.__column_index
|
53 |
+
|
54 |
+
@property
|
55 |
+
def decimal_places(self) -> Optional[int]:
|
56 |
+
return self._decimal_places
|
57 |
+
|
58 |
+
@property
|
59 |
+
def ascii_char_width(self) -> int:
|
60 |
+
return max(self.__header_ascii_char_width, self.__body_ascii_char_width)
|
61 |
+
|
62 |
+
@property
|
63 |
+
def minmax_integer_digits(self) -> MinMaxContainer:
|
64 |
+
return self.__minmax_integer_digits
|
65 |
+
|
66 |
+
@property
|
67 |
+
def minmax_decimal_places(self) -> ListContainer:
|
68 |
+
return self.__minmax_decimal_places
|
69 |
+
|
70 |
+
@property
|
71 |
+
def minmax_additional_format_len(self) -> MinMaxContainer:
|
72 |
+
return self.__minmax_additional_format_len
|
73 |
+
|
74 |
+
def __init__(
|
75 |
+
self,
|
76 |
+
column_index: int,
|
77 |
+
float_type: Optional[FloatType],
|
78 |
+
min_width: int = 0,
|
79 |
+
format_flags: Optional[int] = None,
|
80 |
+
is_formatting_float: bool = True,
|
81 |
+
datetime_format_str: str = DefaultValue.DATETIME_FORMAT,
|
82 |
+
east_asian_ambiguous_width: int = 1,
|
83 |
+
max_precision: int = DefaultValue.MAX_PRECISION,
|
84 |
+
) -> None:
|
85 |
+
super().__init__(
|
86 |
+
format_flags=format_flags,
|
87 |
+
is_formatting_float=is_formatting_float,
|
88 |
+
datetime_format_str=datetime_format_str,
|
89 |
+
east_asian_ambiguous_width=east_asian_ambiguous_width,
|
90 |
+
)
|
91 |
+
|
92 |
+
self.__header_ascii_char_width = 0
|
93 |
+
self.__body_ascii_char_width = min_width
|
94 |
+
self.__column_index = column_index
|
95 |
+
|
96 |
+
self.__float_type = float_type
|
97 |
+
|
98 |
+
self.__is_calculate = True
|
99 |
+
self.__dp_list: List[DataProperty] = []
|
100 |
+
self.__minmax_integer_digits = MinMaxContainer()
|
101 |
+
self.__minmax_decimal_places = ListContainer()
|
102 |
+
self.__minmax_additional_format_len = MinMaxContainer()
|
103 |
+
self.__max_precision = max_precision
|
104 |
+
|
105 |
+
self.__typecode_bitmap = Typecode.NONE.value
|
106 |
+
self.__calc_typecode_from_bitmap()
|
107 |
+
|
108 |
+
self.__format_map: Dict[Typecode, str] = self._formatter.make_format_map(
|
109 |
+
decimal_places=self._decimal_places
|
110 |
+
)
|
111 |
+
|
112 |
+
def __repr__(self) -> str:
|
113 |
+
element_list = []
|
114 |
+
|
115 |
+
if self.column_index is not None:
|
116 |
+
element_list.append(f"column={self.column_index}")
|
117 |
+
|
118 |
+
element_list.extend(
|
119 |
+
[
|
120 |
+
f"type={self.typename}",
|
121 |
+
f"align={self.align.align_string}",
|
122 |
+
f"ascii_width={self.ascii_char_width}",
|
123 |
+
]
|
124 |
+
)
|
125 |
+
|
126 |
+
if Integer(self.bit_length).is_type():
|
127 |
+
element_list.append(f"bit_len={self.bit_length}")
|
128 |
+
|
129 |
+
if self.minmax_integer_digits.has_value():
|
130 |
+
if self.minmax_integer_digits.is_same_value():
|
131 |
+
value = f"int_digits={self.minmax_integer_digits.min_value}"
|
132 |
+
else:
|
133 |
+
value = f"int_digits=({self.minmax_integer_digits})"
|
134 |
+
|
135 |
+
element_list.append(value)
|
136 |
+
|
137 |
+
if self.minmax_decimal_places.has_value():
|
138 |
+
if self.minmax_decimal_places.is_same_value():
|
139 |
+
value = f"decimal_places={self.minmax_decimal_places.min_value}"
|
140 |
+
else:
|
141 |
+
value = f"decimal_places=({self.minmax_decimal_places})"
|
142 |
+
|
143 |
+
element_list.append(value)
|
144 |
+
|
145 |
+
if not self.minmax_additional_format_len.is_zero():
|
146 |
+
if self.minmax_additional_format_len.is_same_value():
|
147 |
+
value = f"extra_len={self.minmax_additional_format_len.min_value}"
|
148 |
+
else:
|
149 |
+
value = f"extra_len=({self.minmax_additional_format_len})"
|
150 |
+
|
151 |
+
element_list.append(value)
|
152 |
+
|
153 |
+
return ", ".join(element_list)
|
154 |
+
|
155 |
+
def dp_to_str(self, value_dp: DataProperty) -> str:
|
156 |
+
if value_dp.typecode == Typecode.STRING:
|
157 |
+
return str(value_dp.data)
|
158 |
+
|
159 |
+
try:
|
160 |
+
value = self.__preprocess_value_before_tostring(value_dp)
|
161 |
+
except TypeConversionError:
|
162 |
+
return self.__format_map.get(value_dp.typecode, "{:s}").format(value_dp.data)
|
163 |
+
|
164 |
+
to_string_format_str = self.__get_tostring_format(value_dp)
|
165 |
+
|
166 |
+
try:
|
167 |
+
return to_string_format_str.format(value)
|
168 |
+
except (ValueError, TypeError):
|
169 |
+
pass
|
170 |
+
|
171 |
+
try:
|
172 |
+
return MultiByteStrDecoder(value).unicode_str
|
173 |
+
except ValueError:
|
174 |
+
pass
|
175 |
+
|
176 |
+
return str(value)
|
177 |
+
|
178 |
+
def extend_width(self, ascii_char_width: int) -> None:
|
179 |
+
self.extend_header_width(ascii_char_width)
|
180 |
+
self.extend_body_width(ascii_char_width)
|
181 |
+
|
182 |
+
def extend_header_width(self, ascii_char_width: int) -> None:
|
183 |
+
self.__header_ascii_char_width += ascii_char_width
|
184 |
+
|
185 |
+
def extend_body_width(self, ascii_char_width: int) -> None:
|
186 |
+
self.__body_ascii_char_width += ascii_char_width
|
187 |
+
|
188 |
+
def update_header(self, header_db: DataProperty) -> None:
|
189 |
+
self.__header_ascii_char_width = header_db.ascii_char_width
|
190 |
+
|
191 |
+
def update_body(self, value_dp: DataProperty) -> None:
|
192 |
+
if value_dp.is_include_ansi_escape:
|
193 |
+
assert value_dp.no_ansi_escape_dp
|
194 |
+
value_dp = value_dp.no_ansi_escape_dp
|
195 |
+
|
196 |
+
self.__typecode_bitmap |= value_dp.typecode.value
|
197 |
+
self.__calc_typecode_from_bitmap()
|
198 |
+
|
199 |
+
if value_dp.typecode in (Typecode.REAL_NUMBER, Typecode.INTEGER):
|
200 |
+
self.__minmax_integer_digits.update(value_dp.integer_digits)
|
201 |
+
self.__minmax_decimal_places.update(value_dp.decimal_places)
|
202 |
+
self.__update_decimal_places()
|
203 |
+
|
204 |
+
self.__minmax_additional_format_len.update(value_dp.additional_format_len)
|
205 |
+
|
206 |
+
self.__dp_list.append(value_dp)
|
207 |
+
self.__update_ascii_char_width()
|
208 |
+
|
209 |
+
def merge(self, column_dp: "ColumnDataProperty") -> None:
|
210 |
+
self.__typecode_bitmap |= column_dp.typecode.value
|
211 |
+
self.__calc_typecode_from_bitmap()
|
212 |
+
|
213 |
+
self.__minmax_integer_digits.merge(column_dp.minmax_integer_digits)
|
214 |
+
self.__minmax_decimal_places.merge(column_dp.minmax_decimal_places)
|
215 |
+
self.__update_decimal_places()
|
216 |
+
|
217 |
+
self.__minmax_additional_format_len.merge(column_dp.minmax_additional_format_len)
|
218 |
+
|
219 |
+
self.__body_ascii_char_width = max(self.__body_ascii_char_width, column_dp.ascii_char_width)
|
220 |
+
self.__update_ascii_char_width()
|
221 |
+
|
222 |
+
def begin_update(self) -> None:
|
223 |
+
self.__is_calculate = False
|
224 |
+
|
225 |
+
def end_update(self) -> None:
|
226 |
+
self.__is_calculate = True
|
227 |
+
|
228 |
+
self.__calc_typecode_from_bitmap()
|
229 |
+
self.__update_decimal_places()
|
230 |
+
self.__update_ascii_char_width()
|
231 |
+
|
232 |
+
def __is_not_single_typecode(self, typecode_bitmap: int) -> bool:
|
233 |
+
return bool(
|
234 |
+
self.__typecode_bitmap & typecode_bitmap and self.__typecode_bitmap & ~typecode_bitmap
|
235 |
+
)
|
236 |
+
|
237 |
+
def __is_float_typecode(self) -> bool:
|
238 |
+
FLOAT_TYPECODE_BMP = (
|
239 |
+
Typecode.REAL_NUMBER.value | Typecode.INFINITY.value | Typecode.NAN.value
|
240 |
+
)
|
241 |
+
NUMBER_TYPECODE_BMP = FLOAT_TYPECODE_BMP | Typecode.INTEGER.value
|
242 |
+
|
243 |
+
if self.__is_not_single_typecode(NUMBER_TYPECODE_BMP | Typecode.NULL_STRING.value):
|
244 |
+
return False
|
245 |
+
|
246 |
+
if (
|
247 |
+
bin(self.__typecode_bitmap & (FLOAT_TYPECODE_BMP | Typecode.NULL_STRING.value)).count(
|
248 |
+
"1"
|
249 |
+
)
|
250 |
+
>= 2
|
251 |
+
):
|
252 |
+
return True
|
253 |
+
|
254 |
+
if bin(self.__typecode_bitmap & NUMBER_TYPECODE_BMP).count("1") >= 2:
|
255 |
+
return True
|
256 |
+
|
257 |
+
return False
|
258 |
+
|
259 |
+
def __calc_body_ascii_char_width(self) -> int:
|
260 |
+
width_list = [self.__body_ascii_char_width]
|
261 |
+
|
262 |
+
for value_dp in self.__dp_list:
|
263 |
+
if value_dp.is_include_ansi_escape:
|
264 |
+
assert value_dp.no_ansi_escape_dp
|
265 |
+
value_dp = value_dp.no_ansi_escape_dp
|
266 |
+
|
267 |
+
width_list.append(
|
268 |
+
calc_ascii_char_width(self.dp_to_str(value_dp), self._east_asian_ambiguous_width)
|
269 |
+
)
|
270 |
+
|
271 |
+
return max(width_list)
|
272 |
+
|
273 |
+
def __calc_decimal_places(self) -> Optional[int]:
|
274 |
+
if self.minmax_decimal_places.max_value is None:
|
275 |
+
return None
|
276 |
+
|
277 |
+
return min(self.__max_precision, int(self.minmax_decimal_places.max_value))
|
278 |
+
|
279 |
+
def __get_tostring_format(self, value_dp: DataProperty) -> str:
|
280 |
+
if self.typecode == Typecode.STRING:
|
281 |
+
return self.__format_map.get(value_dp.typecode, "{:s}")
|
282 |
+
|
283 |
+
return self.__format_map.get(self.typecode, "{:s}")
|
284 |
+
|
285 |
+
def __get_typecode_from_bitmap(self) -> Typecode:
|
286 |
+
if self.__is_float_typecode():
|
287 |
+
return Typecode.REAL_NUMBER
|
288 |
+
|
289 |
+
if any(
|
290 |
+
[
|
291 |
+
self.__is_not_single_typecode(Typecode.BOOL.value),
|
292 |
+
self.__is_not_single_typecode(Typecode.DATETIME.value),
|
293 |
+
]
|
294 |
+
):
|
295 |
+
return Typecode.STRING
|
296 |
+
|
297 |
+
typecode_list = [
|
298 |
+
Typecode.STRING,
|
299 |
+
Typecode.REAL_NUMBER,
|
300 |
+
Typecode.INTEGER,
|
301 |
+
Typecode.DATETIME,
|
302 |
+
Typecode.DICTIONARY,
|
303 |
+
Typecode.IP_ADDRESS,
|
304 |
+
Typecode.LIST,
|
305 |
+
Typecode.BOOL,
|
306 |
+
Typecode.INFINITY,
|
307 |
+
Typecode.NAN,
|
308 |
+
Typecode.NULL_STRING,
|
309 |
+
]
|
310 |
+
|
311 |
+
for typecode in typecode_list:
|
312 |
+
if self.__typecode_bitmap & typecode.value:
|
313 |
+
return typecode
|
314 |
+
|
315 |
+
if self.__typecode_bitmap == Typecode.NONE.value:
|
316 |
+
return Typecode.NONE
|
317 |
+
|
318 |
+
return Typecode.STRING
|
319 |
+
|
320 |
+
def __update_ascii_char_width(self) -> None:
|
321 |
+
if not self.__is_calculate:
|
322 |
+
return
|
323 |
+
|
324 |
+
self.__body_ascii_char_width = self.__calc_body_ascii_char_width()
|
325 |
+
|
326 |
+
def __update_decimal_places(self) -> None:
|
327 |
+
if not self.__is_calculate:
|
328 |
+
return
|
329 |
+
|
330 |
+
self._decimal_places = self.__calc_decimal_places()
|
331 |
+
self.__format_map = self._formatter.make_format_map(decimal_places=self._decimal_places)
|
332 |
+
|
333 |
+
def __calc_typecode_from_bitmap(self) -> None:
|
334 |
+
if not self.__is_calculate:
|
335 |
+
return
|
336 |
+
|
337 |
+
self._typecode = self.__get_typecode_from_bitmap()
|
338 |
+
|
339 |
+
def __preprocess_value_before_tostring(self, value_dp: DataProperty) -> Any:
|
340 |
+
if self.typecode == value_dp.typecode or self.typecode in [
|
341 |
+
Typecode.STRING,
|
342 |
+
Typecode.BOOL,
|
343 |
+
Typecode.DATETIME,
|
344 |
+
]:
|
345 |
+
return value_dp.data
|
346 |
+
|
347 |
+
return self.type_class(
|
348 |
+
value_dp.data,
|
349 |
+
strict_level=StrictLevel.MIN,
|
350 |
+
float_type=self.__float_type,
|
351 |
+
strip_ansi_escape=False,
|
352 |
+
).convert()
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_common.py
ADDED
@@ -0,0 +1,69 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import copy
|
6 |
+
import itertools
|
7 |
+
from datetime import datetime
|
8 |
+
from decimal import Decimal
|
9 |
+
|
10 |
+
from typepy import StrictLevel, Typecode
|
11 |
+
|
12 |
+
from .typing import StrictLevelMap, TypeValueMap
|
13 |
+
|
14 |
+
|
15 |
+
NOT_QUOTING_FLAGS = {
|
16 |
+
Typecode.BOOL: False,
|
17 |
+
Typecode.DATETIME: False,
|
18 |
+
Typecode.DICTIONARY: False,
|
19 |
+
Typecode.INFINITY: False,
|
20 |
+
Typecode.INTEGER: False,
|
21 |
+
Typecode.IP_ADDRESS: False,
|
22 |
+
Typecode.LIST: False,
|
23 |
+
Typecode.NAN: False,
|
24 |
+
Typecode.NULL_STRING: False,
|
25 |
+
Typecode.NONE: False,
|
26 |
+
Typecode.REAL_NUMBER: False,
|
27 |
+
Typecode.STRING: False,
|
28 |
+
}
|
29 |
+
|
30 |
+
MAX_STRICT_LEVEL_MAP: StrictLevelMap = dict(itertools.product(list(Typecode), [StrictLevel.MAX]))
|
31 |
+
MIN_STRICT_LEVEL_MAP: StrictLevelMap = dict(itertools.product(list(Typecode), [StrictLevel.MIN]))
|
32 |
+
|
33 |
+
|
34 |
+
class DefaultValue:
|
35 |
+
DATETIME_FORMAT = "%Y-%m-%dT%H:%M:%S%z"
|
36 |
+
FLOAT_TYPE = Decimal
|
37 |
+
INF_VALUE = FLOAT_TYPE("inf")
|
38 |
+
NAN_VALUE = FLOAT_TYPE("nan")
|
39 |
+
|
40 |
+
QUOTING_FLAGS = copy.deepcopy(NOT_QUOTING_FLAGS)
|
41 |
+
|
42 |
+
STRICT_LEVEL_MAP: StrictLevelMap = {
|
43 |
+
"default": StrictLevel.MAX,
|
44 |
+
Typecode.BOOL: StrictLevel.MAX,
|
45 |
+
Typecode.DATETIME: StrictLevel.MAX,
|
46 |
+
Typecode.DICTIONARY: StrictLevel.MAX,
|
47 |
+
Typecode.REAL_NUMBER: 1,
|
48 |
+
Typecode.INFINITY: StrictLevel.MIN,
|
49 |
+
Typecode.INTEGER: 1,
|
50 |
+
Typecode.IP_ADDRESS: StrictLevel.MAX,
|
51 |
+
Typecode.LIST: StrictLevel.MAX,
|
52 |
+
Typecode.NAN: StrictLevel.MIN,
|
53 |
+
Typecode.NONE: StrictLevel.MAX,
|
54 |
+
Typecode.NULL_STRING: StrictLevel.MIN,
|
55 |
+
Typecode.STRING: StrictLevel.MIN,
|
56 |
+
}
|
57 |
+
|
58 |
+
TYPE_VALUE_MAP: TypeValueMap = {
|
59 |
+
Typecode.NONE: None,
|
60 |
+
Typecode.INFINITY: INF_VALUE,
|
61 |
+
Typecode.NAN: NAN_VALUE,
|
62 |
+
}
|
63 |
+
|
64 |
+
MAX_WORKERS = 1
|
65 |
+
MAX_PRECISION = 100
|
66 |
+
|
67 |
+
|
68 |
+
def default_datetime_formatter(value: datetime) -> str:
|
69 |
+
return value.strftime(DefaultValue.DATETIME_FORMAT)
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_container.py
ADDED
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import abc
|
6 |
+
from decimal import Decimal
|
7 |
+
from typing import Any, List, Optional, Sequence, Union
|
8 |
+
|
9 |
+
from typepy import RealNumber
|
10 |
+
|
11 |
+
|
12 |
+
T = Union[int, float, Decimal]
|
13 |
+
NAN = Decimal("nan")
|
14 |
+
|
15 |
+
|
16 |
+
class AbstractContainer(metaclass=abc.ABCMeta):
|
17 |
+
@abc.abstractproperty
|
18 |
+
def min_value(self) -> Optional[Decimal]: # pragma: no cover
|
19 |
+
pass
|
20 |
+
|
21 |
+
@abc.abstractproperty
|
22 |
+
def max_value(self) -> Optional[Decimal]: # pragma: no cover
|
23 |
+
pass
|
24 |
+
|
25 |
+
@abc.abstractmethod
|
26 |
+
def mean(self) -> Decimal: # pragma: no cover
|
27 |
+
pass
|
28 |
+
|
29 |
+
@abc.abstractmethod
|
30 |
+
def update(self, value: Optional[T]) -> None: # pragma: no cover
|
31 |
+
pass
|
32 |
+
|
33 |
+
@abc.abstractmethod
|
34 |
+
def merge(self, value: "AbstractContainer") -> None: # pragma: no cover
|
35 |
+
pass
|
36 |
+
|
37 |
+
def __repr__(self) -> str:
|
38 |
+
if not self.has_value():
|
39 |
+
return "None"
|
40 |
+
|
41 |
+
return ", ".join([f"min={self.min_value}", f"max={self.max_value}"])
|
42 |
+
|
43 |
+
def has_value(self) -> bool:
|
44 |
+
return self.min_value is not None and self.max_value is not None
|
45 |
+
|
46 |
+
def is_same_value(self) -> bool:
|
47 |
+
return self.has_value() and self.min_value == self.max_value
|
48 |
+
|
49 |
+
def is_zero(self) -> bool:
|
50 |
+
return self.has_value() and self.min_value == 0 and self.max_value == 0
|
51 |
+
|
52 |
+
|
53 |
+
class ListContainer(AbstractContainer):
|
54 |
+
__slots__ = ("__value_list",)
|
55 |
+
|
56 |
+
@property
|
57 |
+
def min_value(self) -> Optional[Decimal]:
|
58 |
+
try:
|
59 |
+
return min(self.__value_list)
|
60 |
+
except ValueError:
|
61 |
+
return None
|
62 |
+
|
63 |
+
@property
|
64 |
+
def max_value(self) -> Optional[Decimal]:
|
65 |
+
try:
|
66 |
+
return max(self.__value_list)
|
67 |
+
except ValueError:
|
68 |
+
return None
|
69 |
+
|
70 |
+
@property
|
71 |
+
def value_list(self) -> List[Decimal]:
|
72 |
+
return self.__value_list
|
73 |
+
|
74 |
+
def __init__(self, value_list: Optional[List[Decimal]] = None) -> None:
|
75 |
+
if value_list is None:
|
76 |
+
self.__value_list: List[Decimal] = []
|
77 |
+
return
|
78 |
+
|
79 |
+
for value in value_list:
|
80 |
+
self.update(value)
|
81 |
+
|
82 |
+
def mean(self) -> Decimal:
|
83 |
+
try:
|
84 |
+
return Decimal(sum(self.__value_list) / len(self.__value_list))
|
85 |
+
except ZeroDivisionError:
|
86 |
+
return NAN
|
87 |
+
|
88 |
+
def update(self, value: Union[int, float, Decimal, None]) -> None:
|
89 |
+
if value is None:
|
90 |
+
return
|
91 |
+
|
92 |
+
store_value = RealNumber(value).try_convert()
|
93 |
+
if store_value is None:
|
94 |
+
return
|
95 |
+
|
96 |
+
self.__value_list.append(store_value)
|
97 |
+
|
98 |
+
def merge(self, value: "AbstractContainer") -> None:
|
99 |
+
if not isinstance(value, ListContainer):
|
100 |
+
return
|
101 |
+
|
102 |
+
for v in value.value_list:
|
103 |
+
self.update(v)
|
104 |
+
|
105 |
+
|
106 |
+
class MinMaxContainer(AbstractContainer):
|
107 |
+
__slots__ = ("__min_value", "__max_value")
|
108 |
+
|
109 |
+
def __init__(self, value_list: Optional[Sequence[Decimal]] = None) -> None:
|
110 |
+
self.__min_value: Optional[Decimal] = None
|
111 |
+
self.__max_value: Optional[Decimal] = None
|
112 |
+
|
113 |
+
if value_list is None:
|
114 |
+
return
|
115 |
+
|
116 |
+
for value in value_list:
|
117 |
+
self.update(value)
|
118 |
+
|
119 |
+
@property
|
120 |
+
def min_value(self) -> Optional[Decimal]:
|
121 |
+
return self.__min_value
|
122 |
+
|
123 |
+
@property
|
124 |
+
def max_value(self) -> Optional[Decimal]:
|
125 |
+
return self.__max_value
|
126 |
+
|
127 |
+
def __eq__(self, other: Any) -> bool:
|
128 |
+
if not isinstance(other, MinMaxContainer):
|
129 |
+
return False
|
130 |
+
|
131 |
+
return all([self.min_value == other.min_value, self.max_value == other.max_value])
|
132 |
+
|
133 |
+
def __ne__(self, other: Any) -> bool:
|
134 |
+
if not isinstance(other, MinMaxContainer):
|
135 |
+
return True
|
136 |
+
|
137 |
+
return any([self.min_value != other.min_value, self.max_value != other.max_value])
|
138 |
+
|
139 |
+
def __contains__(self, x: T) -> bool:
|
140 |
+
if self.min_value is None:
|
141 |
+
return False
|
142 |
+
|
143 |
+
if self.max_value is None:
|
144 |
+
return False
|
145 |
+
|
146 |
+
return self.min_value <= x <= self.max_value
|
147 |
+
|
148 |
+
def diff(self) -> Decimal:
|
149 |
+
if self.min_value is None:
|
150 |
+
return NAN
|
151 |
+
|
152 |
+
if self.max_value is None:
|
153 |
+
return NAN
|
154 |
+
|
155 |
+
try:
|
156 |
+
return self.max_value - self.min_value
|
157 |
+
except TypeError:
|
158 |
+
return NAN
|
159 |
+
|
160 |
+
def mean(self) -> Decimal:
|
161 |
+
if self.min_value is None:
|
162 |
+
return NAN
|
163 |
+
|
164 |
+
if self.max_value is None:
|
165 |
+
return NAN
|
166 |
+
|
167 |
+
try:
|
168 |
+
return (self.max_value + self.min_value) * Decimal("0.5")
|
169 |
+
except TypeError:
|
170 |
+
return NAN
|
171 |
+
|
172 |
+
def update(self, value: Optional[T]) -> None:
|
173 |
+
if value is None:
|
174 |
+
return
|
175 |
+
|
176 |
+
decimal_value = Decimal(value)
|
177 |
+
|
178 |
+
if self.__min_value is None:
|
179 |
+
self.__min_value = decimal_value
|
180 |
+
else:
|
181 |
+
self.__min_value = min(self.__min_value, decimal_value)
|
182 |
+
|
183 |
+
if self.__max_value is None:
|
184 |
+
self.__max_value = decimal_value
|
185 |
+
else:
|
186 |
+
self.__max_value = max(self.__max_value, decimal_value)
|
187 |
+
|
188 |
+
def merge(self, value: "AbstractContainer") -> None:
|
189 |
+
if not isinstance(value, MinMaxContainer):
|
190 |
+
return
|
191 |
+
|
192 |
+
self.update(value.min_value)
|
193 |
+
self.update(value.max_value)
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_converter.py
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import re
|
6 |
+
from typing import Any, Dict, Optional
|
7 |
+
|
8 |
+
from typepy import Typecode, TypeConversionError
|
9 |
+
|
10 |
+
from ._common import MAX_STRICT_LEVEL_MAP, DefaultValue
|
11 |
+
from ._dataproperty import DataProperty
|
12 |
+
from ._preprocessor import Preprocessor
|
13 |
+
from .typing import DateTimeFormatter, FloatType, StrictLevelMap, TypeValueMap
|
14 |
+
|
15 |
+
|
16 |
+
class DataPropertyConverter:
|
17 |
+
__RE_QUOTE_LINE = re.compile(r"^\s*[\"'].*[\"']\s*$") # noqa: w605
|
18 |
+
__RE_QUOTE_CHAR = re.compile("[\"']")
|
19 |
+
|
20 |
+
def __init__(
|
21 |
+
self,
|
22 |
+
preprocessor: Preprocessor,
|
23 |
+
datetime_format_str: str,
|
24 |
+
datetime_formatter: Optional[DateTimeFormatter] = None,
|
25 |
+
type_value_map: Optional[TypeValueMap] = None,
|
26 |
+
quoting_flags: Optional[Dict[Typecode, bool]] = None,
|
27 |
+
float_type: Optional[FloatType] = None,
|
28 |
+
strict_level_map: Optional[StrictLevelMap] = None,
|
29 |
+
) -> None:
|
30 |
+
self.__preprocessor = preprocessor
|
31 |
+
self.__type_value_map: TypeValueMap = (
|
32 |
+
type_value_map if type_value_map else DefaultValue.TYPE_VALUE_MAP
|
33 |
+
)
|
34 |
+
self.__quoting_flags: Dict[Typecode, bool] = (
|
35 |
+
quoting_flags if quoting_flags else DefaultValue.QUOTING_FLAGS
|
36 |
+
)
|
37 |
+
|
38 |
+
self.__datetime_formatter = datetime_formatter
|
39 |
+
self.__datetime_format_str = datetime_format_str
|
40 |
+
self.__float_type = float_type
|
41 |
+
self.__strict_level_map = strict_level_map
|
42 |
+
|
43 |
+
def convert(self, dp_value: DataProperty) -> DataProperty:
|
44 |
+
try:
|
45 |
+
return self.__create_dataproperty(self.__convert_value(dp_value))
|
46 |
+
except TypeConversionError:
|
47 |
+
pass
|
48 |
+
|
49 |
+
if not self.__quoting_flags.get(dp_value.typecode):
|
50 |
+
if self.__preprocessor.is_escape_html_tag:
|
51 |
+
return self.__create_dataproperty(dp_value.to_str())
|
52 |
+
|
53 |
+
return dp_value
|
54 |
+
|
55 |
+
return self.__create_dataproperty(self.__apply_quote(dp_value.typecode, dp_value.to_str()))
|
56 |
+
|
57 |
+
def __create_dataproperty(self, value: Any) -> DataProperty:
|
58 |
+
return DataProperty(
|
59 |
+
value,
|
60 |
+
preprocessor=self.__preprocessor,
|
61 |
+
float_type=self.__float_type,
|
62 |
+
datetime_format_str=self.__datetime_format_str,
|
63 |
+
strict_level_map=MAX_STRICT_LEVEL_MAP,
|
64 |
+
)
|
65 |
+
|
66 |
+
def __apply_quote(self, typecode: Typecode, data: Any) -> Any:
|
67 |
+
if not self.__quoting_flags.get(typecode):
|
68 |
+
return data
|
69 |
+
|
70 |
+
try:
|
71 |
+
if self.__RE_QUOTE_LINE.search(data):
|
72 |
+
return data
|
73 |
+
except TypeError:
|
74 |
+
return data
|
75 |
+
|
76 |
+
return '"{}"'.format(self.__RE_QUOTE_CHAR.sub('\\"', data.replace("\\", "\\\\")))
|
77 |
+
|
78 |
+
def __convert_value(self, dp_value: DataProperty) -> Any:
|
79 |
+
if dp_value.typecode in self.__type_value_map:
|
80 |
+
return self.__apply_quote(dp_value.typecode, self.__type_value_map[dp_value.typecode])
|
81 |
+
|
82 |
+
if dp_value.typecode == Typecode.DATETIME and self.__datetime_formatter:
|
83 |
+
try:
|
84 |
+
return self.__apply_quote(
|
85 |
+
dp_value.typecode, self.__datetime_formatter(dp_value.data)
|
86 |
+
)
|
87 |
+
except TypeError:
|
88 |
+
raise TypeConversionError
|
89 |
+
|
90 |
+
raise TypeConversionError("no need to convert")
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_dataproperty.py
ADDED
@@ -0,0 +1,382 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import typing
|
6 |
+
from decimal import Decimal
|
7 |
+
from typing import Any, Optional, cast
|
8 |
+
|
9 |
+
import typepy
|
10 |
+
from mbstrdecoder import MultiByteStrDecoder
|
11 |
+
from typepy import (
|
12 |
+
Bool,
|
13 |
+
DateTime,
|
14 |
+
Dictionary,
|
15 |
+
Infinity,
|
16 |
+
Integer,
|
17 |
+
IpAddress,
|
18 |
+
Nan,
|
19 |
+
NoneType,
|
20 |
+
NullString,
|
21 |
+
RealNumber,
|
22 |
+
StrictLevel,
|
23 |
+
String,
|
24 |
+
Typecode,
|
25 |
+
TypeConversionError,
|
26 |
+
)
|
27 |
+
from typepy.type import AbstractType
|
28 |
+
|
29 |
+
from ._align import Align
|
30 |
+
from ._align_getter import align_getter
|
31 |
+
from ._base import DataPeropertyBase
|
32 |
+
from ._common import DefaultValue
|
33 |
+
from ._function import calc_ascii_char_width, get_number_of_digit
|
34 |
+
from ._preprocessor import Preprocessor
|
35 |
+
from .typing import FloatType, StrictLevelMap, TypeHint
|
36 |
+
|
37 |
+
|
38 |
+
class DataProperty(DataPeropertyBase):
|
39 |
+
__slots__ = (
|
40 |
+
"__data",
|
41 |
+
"__no_ansi_escape_data",
|
42 |
+
"__align",
|
43 |
+
"__integer_digits",
|
44 |
+
"__additional_format_len",
|
45 |
+
"__length",
|
46 |
+
"__ascii_char_width",
|
47 |
+
)
|
48 |
+
|
49 |
+
__type_class_list: typing.List[AbstractType] = [
|
50 |
+
NoneType,
|
51 |
+
Integer,
|
52 |
+
Infinity,
|
53 |
+
Nan,
|
54 |
+
IpAddress,
|
55 |
+
RealNumber,
|
56 |
+
Bool,
|
57 |
+
typepy.List,
|
58 |
+
Dictionary,
|
59 |
+
DateTime,
|
60 |
+
NullString,
|
61 |
+
String,
|
62 |
+
]
|
63 |
+
|
64 |
+
def __init__(
|
65 |
+
self,
|
66 |
+
data: Any,
|
67 |
+
preprocessor: Optional[Preprocessor] = None,
|
68 |
+
type_hint: TypeHint = None,
|
69 |
+
float_type: Optional[FloatType] = None,
|
70 |
+
format_flags: Optional[int] = None,
|
71 |
+
datetime_format_str: str = DefaultValue.DATETIME_FORMAT,
|
72 |
+
strict_level_map: Optional[StrictLevelMap] = None,
|
73 |
+
east_asian_ambiguous_width: int = 1,
|
74 |
+
) -> None:
|
75 |
+
super().__init__(
|
76 |
+
format_flags=format_flags,
|
77 |
+
is_formatting_float=True,
|
78 |
+
datetime_format_str=datetime_format_str,
|
79 |
+
east_asian_ambiguous_width=east_asian_ambiguous_width,
|
80 |
+
)
|
81 |
+
|
82 |
+
self.__additional_format_len: Optional[int] = None
|
83 |
+
self.__align: Optional[Align] = None
|
84 |
+
self.__ascii_char_width: Optional[int] = None
|
85 |
+
self.__integer_digits: Optional[int] = None
|
86 |
+
self.__length: Optional[int] = None
|
87 |
+
|
88 |
+
if preprocessor is None:
|
89 |
+
preprocessor = Preprocessor()
|
90 |
+
|
91 |
+
data, no_ansi_escape_data = preprocessor.preprocess(data)
|
92 |
+
|
93 |
+
self.__set_data(data, type_hint, float_type, strict_level_map)
|
94 |
+
|
95 |
+
if no_ansi_escape_data is None or len(data) == len(no_ansi_escape_data):
|
96 |
+
self.__no_ansi_escape_data: Optional[DataProperty] = None
|
97 |
+
else:
|
98 |
+
self.__no_ansi_escape_data = DataProperty(no_ansi_escape_data, float_type=float_type)
|
99 |
+
|
100 |
+
def __eq__(self, other: Any) -> bool:
|
101 |
+
if not isinstance(other, DataProperty):
|
102 |
+
return False
|
103 |
+
|
104 |
+
if self.typecode != other.typecode:
|
105 |
+
return False
|
106 |
+
|
107 |
+
if self.typecode == Typecode.NAN:
|
108 |
+
return True
|
109 |
+
|
110 |
+
return self.data == other.data
|
111 |
+
|
112 |
+
def __ne__(self, other: Any) -> bool:
|
113 |
+
if not isinstance(other, DataProperty):
|
114 |
+
return True
|
115 |
+
|
116 |
+
if self.typecode != other.typecode:
|
117 |
+
return True
|
118 |
+
|
119 |
+
if self.typecode == Typecode.NAN:
|
120 |
+
return False
|
121 |
+
|
122 |
+
return self.data != other.data
|
123 |
+
|
124 |
+
def __repr__(self) -> str:
|
125 |
+
element_list = []
|
126 |
+
|
127 |
+
if self.typecode == Typecode.DATETIME:
|
128 |
+
element_list.append(f"data={str(self.data):s}")
|
129 |
+
else:
|
130 |
+
try:
|
131 |
+
element_list.append("data=" + self.to_str())
|
132 |
+
except UnicodeEncodeError:
|
133 |
+
element_list.append(f"data={MultiByteStrDecoder(self.data).unicode_str}")
|
134 |
+
|
135 |
+
element_list.extend(
|
136 |
+
[
|
137 |
+
f"type={self.typename:s}",
|
138 |
+
f"align={self.align.align_string}",
|
139 |
+
f"ascii_width={self.ascii_char_width:d}",
|
140 |
+
]
|
141 |
+
)
|
142 |
+
|
143 |
+
if Integer(self.length).is_type():
|
144 |
+
element_list.append(f"length={self.length}")
|
145 |
+
|
146 |
+
if Integer(self.integer_digits).is_type():
|
147 |
+
element_list.append(f"int_digits={self.integer_digits}")
|
148 |
+
|
149 |
+
if Integer(self.decimal_places).is_type():
|
150 |
+
element_list.append(f"decimal_places={self.decimal_places}")
|
151 |
+
|
152 |
+
if Integer(self.additional_format_len).is_type():
|
153 |
+
element_list.append(f"extra_len={self.additional_format_len}")
|
154 |
+
|
155 |
+
return ", ".join(element_list)
|
156 |
+
|
157 |
+
@property
|
158 |
+
def align(self) -> Align:
|
159 |
+
if not self.__align:
|
160 |
+
if self.is_include_ansi_escape:
|
161 |
+
assert self.no_ansi_escape_dp
|
162 |
+
self.__align = self.no_ansi_escape_dp.align
|
163 |
+
else:
|
164 |
+
self.__align = align_getter.get_align_from_typecode(self.typecode)
|
165 |
+
|
166 |
+
assert self.__align
|
167 |
+
|
168 |
+
return self.__align
|
169 |
+
|
170 |
+
@property
|
171 |
+
def decimal_places(self) -> Optional[int]:
|
172 |
+
"""
|
173 |
+
:return:
|
174 |
+
Decimal places if the ``data`` type either ``float`` or
|
175 |
+
``decimal.Decimal``. Returns ``0`` if the ``data`` type is ``int``.
|
176 |
+
Otherwise, returns ``float("nan")``.
|
177 |
+
:rtype: int
|
178 |
+
"""
|
179 |
+
|
180 |
+
if self._decimal_places is None:
|
181 |
+
self.__set_digit()
|
182 |
+
|
183 |
+
return self._decimal_places
|
184 |
+
|
185 |
+
@property
|
186 |
+
def data(self) -> Any:
|
187 |
+
"""
|
188 |
+
:return: Original data value.
|
189 |
+
:rtype: Original data type.
|
190 |
+
"""
|
191 |
+
|
192 |
+
return self.__data
|
193 |
+
|
194 |
+
@property
|
195 |
+
def is_include_ansi_escape(self) -> bool:
|
196 |
+
if self.no_ansi_escape_dp is None:
|
197 |
+
return False
|
198 |
+
|
199 |
+
return self.length != self.no_ansi_escape_dp.length
|
200 |
+
|
201 |
+
@property
|
202 |
+
def no_ansi_escape_dp(self) -> Optional["DataProperty"]:
|
203 |
+
return self.__no_ansi_escape_data
|
204 |
+
|
205 |
+
@property
|
206 |
+
def length(self) -> Optional[int]:
|
207 |
+
"""
|
208 |
+
:return: Length of the ``data``.
|
209 |
+
:rtype: int
|
210 |
+
"""
|
211 |
+
|
212 |
+
if self.__length is None:
|
213 |
+
self.__length = self.__get_length()
|
214 |
+
|
215 |
+
return self.__length
|
216 |
+
|
217 |
+
@property
|
218 |
+
def ascii_char_width(self) -> int:
|
219 |
+
if self.__ascii_char_width is None:
|
220 |
+
self.__ascii_char_width = self.__calc_ascii_char_width()
|
221 |
+
|
222 |
+
return self.__ascii_char_width
|
223 |
+
|
224 |
+
@property
|
225 |
+
def integer_digits(self) -> Optional[int]:
|
226 |
+
"""
|
227 |
+
:return:
|
228 |
+
Integer digits if the ``data`` type either
|
229 |
+
``int``/``float``/``decimal.Decimal``.
|
230 |
+
Otherwise, returns ``None``.
|
231 |
+
:rtype: int
|
232 |
+
"""
|
233 |
+
|
234 |
+
if self.__integer_digits is None:
|
235 |
+
self.__set_digit()
|
236 |
+
|
237 |
+
return self.__integer_digits
|
238 |
+
|
239 |
+
@property
|
240 |
+
def additional_format_len(self) -> int:
|
241 |
+
if self.__additional_format_len is None:
|
242 |
+
self.__additional_format_len = self.__get_additional_format_len()
|
243 |
+
|
244 |
+
return self.__additional_format_len
|
245 |
+
|
246 |
+
def get_padding_len(self, ascii_char_width: int) -> int:
|
247 |
+
if self.typecode in (Typecode.LIST, Typecode.DICTIONARY):
|
248 |
+
unicode_str_len = DataProperty(MultiByteStrDecoder(str(self.data)).unicode_str).length
|
249 |
+
assert unicode_str_len
|
250 |
+
return max(
|
251 |
+
ascii_char_width - (self.ascii_char_width - unicode_str_len),
|
252 |
+
0,
|
253 |
+
)
|
254 |
+
|
255 |
+
try:
|
256 |
+
return max(ascii_char_width - (self.ascii_char_width - cast(int, self.length)), 0)
|
257 |
+
except TypeError:
|
258 |
+
return ascii_char_width
|
259 |
+
|
260 |
+
def to_str(self) -> str:
|
261 |
+
return self.format_str.format(self.data)
|
262 |
+
|
263 |
+
def __get_additional_format_len(self) -> int:
|
264 |
+
if not RealNumber(self.data, strip_ansi_escape=False).is_type():
|
265 |
+
return 0
|
266 |
+
|
267 |
+
format_len = 0
|
268 |
+
|
269 |
+
if Decimal(self.data) < 0:
|
270 |
+
# for minus character
|
271 |
+
format_len += 1
|
272 |
+
|
273 |
+
return format_len
|
274 |
+
|
275 |
+
def __get_base_float_len(self) -> int:
|
276 |
+
assert self.integer_digits is not None
|
277 |
+
assert self.decimal_places is not None
|
278 |
+
|
279 |
+
if any([self.integer_digits < 0, self.decimal_places < 0]):
|
280 |
+
raise ValueError("integer digits and decimal places must be greater or equals to zero")
|
281 |
+
|
282 |
+
float_len = self.integer_digits + self.decimal_places
|
283 |
+
if self.decimal_places > 0:
|
284 |
+
# for dot
|
285 |
+
float_len += 1
|
286 |
+
|
287 |
+
return float_len
|
288 |
+
|
289 |
+
def __get_length(self) -> Optional[int]:
|
290 |
+
if self.typecode in (Typecode.DICTIONARY, Typecode.LIST, Typecode.STRING):
|
291 |
+
return len(self.data)
|
292 |
+
|
293 |
+
return None
|
294 |
+
|
295 |
+
def __calc_ascii_char_width(self) -> int:
|
296 |
+
if self.typecode == Typecode.INTEGER:
|
297 |
+
return cast(int, self.integer_digits) + self.additional_format_len
|
298 |
+
|
299 |
+
if self.typecode == Typecode.REAL_NUMBER:
|
300 |
+
return self.__get_base_float_len() + self.additional_format_len
|
301 |
+
|
302 |
+
if self.typecode == Typecode.DATETIME:
|
303 |
+
try:
|
304 |
+
return len(self.to_str())
|
305 |
+
except ValueError:
|
306 |
+
# reach to this line if the year <1900.
|
307 |
+
# the datetime strftime() methods require year >= 1900.
|
308 |
+
return len(str(self.data))
|
309 |
+
|
310 |
+
if self.is_include_ansi_escape:
|
311 |
+
assert self.no_ansi_escape_dp
|
312 |
+
return self.no_ansi_escape_dp.ascii_char_width
|
313 |
+
|
314 |
+
try:
|
315 |
+
unicode_str = MultiByteStrDecoder(self.data).unicode_str
|
316 |
+
except ValueError:
|
317 |
+
unicode_str = self.to_str()
|
318 |
+
|
319 |
+
return calc_ascii_char_width(unicode_str, self._east_asian_ambiguous_width)
|
320 |
+
|
321 |
+
def __set_data(
|
322 |
+
self,
|
323 |
+
data: Any,
|
324 |
+
type_hint: TypeHint,
|
325 |
+
float_type: Optional[FloatType],
|
326 |
+
strict_level_map: Optional[StrictLevelMap],
|
327 |
+
) -> None:
|
328 |
+
if float_type is None:
|
329 |
+
float_type = DefaultValue.FLOAT_TYPE
|
330 |
+
|
331 |
+
if strict_level_map is None:
|
332 |
+
strict_level_map = DefaultValue.STRICT_LEVEL_MAP
|
333 |
+
|
334 |
+
if type_hint:
|
335 |
+
type_obj = type_hint(
|
336 |
+
data, strict_level=StrictLevel.MIN, float_type=float_type, strip_ansi_escape=False
|
337 |
+
)
|
338 |
+
self._typecode = type_obj.typecode
|
339 |
+
self.__data = type_obj.try_convert()
|
340 |
+
|
341 |
+
if type_hint(
|
342 |
+
self.__data,
|
343 |
+
strict_level=StrictLevel.MAX,
|
344 |
+
float_type=float_type,
|
345 |
+
strip_ansi_escape=False,
|
346 |
+
).is_type():
|
347 |
+
return
|
348 |
+
|
349 |
+
for type_class in self.__type_class_list:
|
350 |
+
strict_level = strict_level_map.get(
|
351 |
+
type_class(None).typecode, strict_level_map.get("default", StrictLevel.MAX)
|
352 |
+
)
|
353 |
+
|
354 |
+
if self.__try_convert_type(data, type_class, strict_level, float_type):
|
355 |
+
return
|
356 |
+
|
357 |
+
raise TypeConversionError(
|
358 |
+
f"failed to convert: data={data}, strict_level={strict_level_map}"
|
359 |
+
)
|
360 |
+
|
361 |
+
def __set_digit(self) -> None:
|
362 |
+
integer_digits, decimal_places = get_number_of_digit(self.__data)
|
363 |
+
self.__integer_digits = integer_digits
|
364 |
+
self._decimal_places = decimal_places
|
365 |
+
|
366 |
+
def __try_convert_type(
|
367 |
+
self,
|
368 |
+
data: Any,
|
369 |
+
type_class: AbstractType,
|
370 |
+
strict_level: int,
|
371 |
+
float_type: Optional[FloatType],
|
372 |
+
) -> bool:
|
373 |
+
type_obj = type_class(data, strict_level, float_type=float_type, strip_ansi_escape=False)
|
374 |
+
|
375 |
+
try:
|
376 |
+
self.__data = type_obj.convert()
|
377 |
+
except TypeConversionError:
|
378 |
+
return False
|
379 |
+
|
380 |
+
self._typecode = type_obj.typecode
|
381 |
+
|
382 |
+
return True
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_extractor.py
ADDED
@@ -0,0 +1,814 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import copy
|
6 |
+
import enum
|
7 |
+
import sys
|
8 |
+
import typing
|
9 |
+
from collections import Counter
|
10 |
+
from decimal import Decimal
|
11 |
+
from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple, Type, Union, cast
|
12 |
+
|
13 |
+
import typepy
|
14 |
+
from typepy import (
|
15 |
+
Bool,
|
16 |
+
DateTime,
|
17 |
+
Dictionary,
|
18 |
+
Infinity,
|
19 |
+
Integer,
|
20 |
+
IpAddress,
|
21 |
+
Nan,
|
22 |
+
NoneType,
|
23 |
+
NullString,
|
24 |
+
RealNumber,
|
25 |
+
StrictLevel,
|
26 |
+
String,
|
27 |
+
Typecode,
|
28 |
+
is_empty_sequence,
|
29 |
+
)
|
30 |
+
from typepy.type import AbstractType
|
31 |
+
|
32 |
+
from ._column import ColumnDataProperty
|
33 |
+
from ._common import MIN_STRICT_LEVEL_MAP, DefaultValue
|
34 |
+
from ._converter import DataPropertyConverter
|
35 |
+
from ._dataproperty import DataProperty
|
36 |
+
from ._formatter import Format
|
37 |
+
from ._preprocessor import Preprocessor
|
38 |
+
from .logger import logger
|
39 |
+
from .typing import (
|
40 |
+
DateTimeFormatter,
|
41 |
+
StrictLevelMap,
|
42 |
+
TransFunc,
|
43 |
+
TypeHint,
|
44 |
+
TypeValueMap,
|
45 |
+
normalize_type_hint,
|
46 |
+
)
|
47 |
+
|
48 |
+
|
49 |
+
DataPropertyMatrix = List[List[DataProperty]]
|
50 |
+
|
51 |
+
|
52 |
+
@enum.unique
|
53 |
+
class MatrixFormatting(enum.Enum):
|
54 |
+
# raise exception if the matrix is not properly formatted
|
55 |
+
EXCEPTION = 1 << 1
|
56 |
+
|
57 |
+
# trim to the minimum size column
|
58 |
+
TRIM = 1 << 2
|
59 |
+
|
60 |
+
# Append None values to columns so that it is the same as the maximum
|
61 |
+
# column size.
|
62 |
+
FILL_NONE = 1 << 3
|
63 |
+
|
64 |
+
HEADER_ALIGNED = 1 << 4
|
65 |
+
|
66 |
+
|
67 |
+
class DataPropertyExtractor:
|
68 |
+
"""
|
69 |
+
.. py:attribute:: quoting_flags
|
70 |
+
|
71 |
+
Configurations to add double quote to for each items in a matrix,
|
72 |
+
where |Typecode| of table-value is |True| in the ``quote_flag_table``
|
73 |
+
mapping table. ``quote_flag_table`` should be a dictionary.
|
74 |
+
And is ``{ Typecode : bool }``. Defaults to:
|
75 |
+
|
76 |
+
.. code-block:: json
|
77 |
+
:caption: The default values
|
78 |
+
|
79 |
+
{
|
80 |
+
Typecode.BOOL: False,
|
81 |
+
Typecode.DATETIME: False,
|
82 |
+
Typecode.DICTIONARY: False,
|
83 |
+
Typecode.INFINITY: False,
|
84 |
+
Typecode.INTEGER: False,
|
85 |
+
Typecode.IP_ADDRESS: False,
|
86 |
+
Typecode.LIST: False,
|
87 |
+
Typecode.NAN: False,
|
88 |
+
Typecode.NULL_STRING: False,
|
89 |
+
Typecode.NONE: False,
|
90 |
+
Typecode.REAL_NUMBER: False,
|
91 |
+
Typecode.STRING: False,
|
92 |
+
}
|
93 |
+
"""
|
94 |
+
|
95 |
+
def __init__(self, max_precision: Optional[int] = None) -> None:
|
96 |
+
self.max_workers = DefaultValue.MAX_WORKERS
|
97 |
+
|
98 |
+
if max_precision is None:
|
99 |
+
self.__max_precision = DefaultValue.MAX_PRECISION
|
100 |
+
else:
|
101 |
+
self.__max_precision = max_precision
|
102 |
+
|
103 |
+
self.__headers: Sequence[str] = []
|
104 |
+
self.__default_type_hint: TypeHint = None
|
105 |
+
self.__col_type_hints: List[TypeHint] = []
|
106 |
+
|
107 |
+
self.__strip_str_header: Optional[str] = None
|
108 |
+
self.__is_formatting_float = True
|
109 |
+
self.__min_col_ascii_char_width = 0
|
110 |
+
self.__default_format_flags = Format.NONE
|
111 |
+
self.__format_flags_list: Sequence[int] = []
|
112 |
+
self.__float_type: Union[Type[float], Type[Decimal], None] = None
|
113 |
+
self.__datetime_format_str = DefaultValue.DATETIME_FORMAT
|
114 |
+
self.__strict_level_map = copy.deepcopy(
|
115 |
+
cast(Dict[Union[Typecode, str], int], DefaultValue.STRICT_LEVEL_MAP)
|
116 |
+
)
|
117 |
+
self.__east_asian_ambiguous_width = 1
|
118 |
+
|
119 |
+
self.__preprocessor = Preprocessor()
|
120 |
+
|
121 |
+
self.__type_value_map: Mapping[Typecode, Union[float, Decimal, None]] = copy.deepcopy(
|
122 |
+
DefaultValue.TYPE_VALUE_MAP
|
123 |
+
)
|
124 |
+
|
125 |
+
self.__trans_func_list: List[TransFunc] = []
|
126 |
+
self.__quoting_flags = copy.deepcopy(DefaultValue.QUOTING_FLAGS)
|
127 |
+
self.__datetime_formatter: Optional[DateTimeFormatter] = None
|
128 |
+
self.__matrix_formatting = MatrixFormatting.TRIM
|
129 |
+
self.__dp_converter: DataPropertyConverter
|
130 |
+
|
131 |
+
self.__clear_cache()
|
132 |
+
|
133 |
+
def __clear_cache(self) -> None:
|
134 |
+
self.__update_dp_converter()
|
135 |
+
self.__dp_cache_zero = self.__to_dp_raw(0)
|
136 |
+
self.__dp_cache_one = self.__to_dp_raw(1)
|
137 |
+
self.__dp_cache_true = self.__to_dp_raw(True)
|
138 |
+
self.__dp_cache_false = self.__to_dp_raw(False)
|
139 |
+
self.__dp_cache_map = {None: self.__to_dp_raw(None), "": self.__to_dp_raw("")}
|
140 |
+
|
141 |
+
@property
|
142 |
+
def headers(self) -> Sequence[str]:
|
143 |
+
return self.__headers
|
144 |
+
|
145 |
+
@headers.setter
|
146 |
+
def headers(self, value: Sequence[str]) -> None:
|
147 |
+
if self.__headers == value:
|
148 |
+
return
|
149 |
+
|
150 |
+
self.__headers = value
|
151 |
+
self.__clear_cache()
|
152 |
+
|
153 |
+
@property
|
154 |
+
def default_type_hint(self) -> TypeHint:
|
155 |
+
return self.__default_type_hint
|
156 |
+
|
157 |
+
@default_type_hint.setter
|
158 |
+
def default_type_hint(self, value: TypeHint) -> None:
|
159 |
+
if self.__default_type_hint == value:
|
160 |
+
return
|
161 |
+
|
162 |
+
self.__default_type_hint = value
|
163 |
+
self.__clear_cache()
|
164 |
+
|
165 |
+
@property
|
166 |
+
def column_type_hints(self) -> List[TypeHint]:
|
167 |
+
return self.__col_type_hints
|
168 |
+
|
169 |
+
@column_type_hints.setter
|
170 |
+
def column_type_hints(self, value: Sequence[Union[str, TypeHint]]) -> None:
|
171 |
+
normalized_type_hints: List[TypeHint] = []
|
172 |
+
|
173 |
+
for type_hint in value:
|
174 |
+
type_hint = normalize_type_hint(type_hint)
|
175 |
+
if type_hint not in (
|
176 |
+
Bool,
|
177 |
+
DateTime,
|
178 |
+
Dictionary,
|
179 |
+
Infinity,
|
180 |
+
Integer,
|
181 |
+
IpAddress,
|
182 |
+
typepy.List,
|
183 |
+
Nan,
|
184 |
+
NoneType,
|
185 |
+
RealNumber,
|
186 |
+
String,
|
187 |
+
NullString,
|
188 |
+
None,
|
189 |
+
):
|
190 |
+
raise ValueError(f"invalid type hint: {type(type_hint)}")
|
191 |
+
|
192 |
+
normalized_type_hints.append(type_hint)
|
193 |
+
|
194 |
+
if self.__col_type_hints == normalized_type_hints:
|
195 |
+
return
|
196 |
+
|
197 |
+
self.__col_type_hints = normalized_type_hints
|
198 |
+
self.__clear_cache()
|
199 |
+
|
200 |
+
@property
|
201 |
+
def is_formatting_float(self) -> bool:
|
202 |
+
return self.__is_formatting_float
|
203 |
+
|
204 |
+
@is_formatting_float.setter
|
205 |
+
def is_formatting_float(self, value: bool) -> None:
|
206 |
+
self.__is_formatting_float = value
|
207 |
+
|
208 |
+
@property
|
209 |
+
def max_precision(self) -> int:
|
210 |
+
return self.__max_precision
|
211 |
+
|
212 |
+
@max_precision.setter
|
213 |
+
def max_precision(self, value: int) -> None:
|
214 |
+
if self.__max_precision == value:
|
215 |
+
return
|
216 |
+
|
217 |
+
self.__max_precision = value
|
218 |
+
self.__clear_cache()
|
219 |
+
|
220 |
+
@property
|
221 |
+
def preprocessor(self) -> Preprocessor:
|
222 |
+
return self.__preprocessor
|
223 |
+
|
224 |
+
@preprocessor.setter
|
225 |
+
def preprocessor(self, value: Preprocessor) -> None:
|
226 |
+
if self.preprocessor == value:
|
227 |
+
return
|
228 |
+
|
229 |
+
self.__preprocessor = value
|
230 |
+
self.__update_dp_converter()
|
231 |
+
|
232 |
+
@property
|
233 |
+
def strip_str_header(self) -> Optional[str]:
|
234 |
+
return self.__strip_str_header
|
235 |
+
|
236 |
+
@strip_str_header.setter
|
237 |
+
def strip_str_header(self, value: str) -> None:
|
238 |
+
if self.__strip_str_header == value:
|
239 |
+
return
|
240 |
+
|
241 |
+
self.__strip_str_header = value
|
242 |
+
self.__clear_cache()
|
243 |
+
|
244 |
+
@property
|
245 |
+
def min_column_width(self) -> int:
|
246 |
+
return self.__min_col_ascii_char_width
|
247 |
+
|
248 |
+
@min_column_width.setter
|
249 |
+
def min_column_width(self, value: int) -> None:
|
250 |
+
if self.__min_col_ascii_char_width == value:
|
251 |
+
return
|
252 |
+
|
253 |
+
self.__min_col_ascii_char_width = value
|
254 |
+
self.__clear_cache()
|
255 |
+
|
256 |
+
@property
|
257 |
+
def default_format_flags(self) -> int:
|
258 |
+
return self.__default_format_flags
|
259 |
+
|
260 |
+
@default_format_flags.setter
|
261 |
+
def default_format_flags(self, value: int) -> None:
|
262 |
+
if self.__default_format_flags == value:
|
263 |
+
return
|
264 |
+
|
265 |
+
self.__default_format_flags = value
|
266 |
+
self.__clear_cache()
|
267 |
+
|
268 |
+
@property
|
269 |
+
def format_flags_list(self) -> Sequence[int]:
|
270 |
+
return self.__format_flags_list
|
271 |
+
|
272 |
+
@format_flags_list.setter
|
273 |
+
def format_flags_list(self, value: Sequence[int]) -> None:
|
274 |
+
if self.__format_flags_list == value:
|
275 |
+
return
|
276 |
+
|
277 |
+
self.__format_flags_list = value
|
278 |
+
self.__clear_cache()
|
279 |
+
|
280 |
+
@property
|
281 |
+
def float_type(self) -> Union[Type[float], Type[Decimal], None]:
|
282 |
+
return self.__float_type
|
283 |
+
|
284 |
+
@float_type.setter
|
285 |
+
def float_type(self, value: Union[Type[float], Type[Decimal]]) -> None:
|
286 |
+
if self.__float_type == value:
|
287 |
+
return
|
288 |
+
|
289 |
+
self.__float_type = value
|
290 |
+
self.__clear_cache()
|
291 |
+
|
292 |
+
@property
|
293 |
+
def datetime_format_str(self) -> str:
|
294 |
+
return self.__datetime_format_str
|
295 |
+
|
296 |
+
@datetime_format_str.setter
|
297 |
+
def datetime_format_str(self, value: str) -> None:
|
298 |
+
if self.__datetime_format_str == value:
|
299 |
+
return
|
300 |
+
|
301 |
+
self.__datetime_format_str = value
|
302 |
+
self.__clear_cache()
|
303 |
+
|
304 |
+
@property
|
305 |
+
def strict_level_map(self) -> StrictLevelMap:
|
306 |
+
return self.__strict_level_map
|
307 |
+
|
308 |
+
@strict_level_map.setter
|
309 |
+
def strict_level_map(self, value: StrictLevelMap) -> None:
|
310 |
+
if self.__strict_level_map == value:
|
311 |
+
return
|
312 |
+
|
313 |
+
self.__strict_level_map = cast(Dict[Union[Typecode, str], int], value)
|
314 |
+
self.__clear_cache()
|
315 |
+
|
316 |
+
@property
|
317 |
+
def east_asian_ambiguous_width(self) -> int:
|
318 |
+
return self.__east_asian_ambiguous_width
|
319 |
+
|
320 |
+
@east_asian_ambiguous_width.setter
|
321 |
+
def east_asian_ambiguous_width(self, value: int) -> None:
|
322 |
+
if self.__east_asian_ambiguous_width == value:
|
323 |
+
return
|
324 |
+
|
325 |
+
self.__east_asian_ambiguous_width = value
|
326 |
+
self.__clear_cache()
|
327 |
+
|
328 |
+
@property
|
329 |
+
def type_value_map(self) -> TypeValueMap:
|
330 |
+
return self.__type_value_map
|
331 |
+
|
332 |
+
@type_value_map.setter
|
333 |
+
def type_value_map(self, value: TypeValueMap) -> None:
|
334 |
+
if self.__type_value_map == value:
|
335 |
+
return
|
336 |
+
|
337 |
+
self.__type_value_map = value
|
338 |
+
self.__clear_cache()
|
339 |
+
|
340 |
+
def register_trans_func(self, trans_func: TransFunc) -> None:
|
341 |
+
self.__trans_func_list.insert(0, trans_func)
|
342 |
+
self.__clear_cache()
|
343 |
+
|
344 |
+
@property
|
345 |
+
def quoting_flags(self) -> Dict[Typecode, bool]:
|
346 |
+
return self.__quoting_flags
|
347 |
+
|
348 |
+
@quoting_flags.setter
|
349 |
+
def quoting_flags(self, value: Dict[Typecode, bool]) -> None:
|
350 |
+
if self.__quoting_flags == value:
|
351 |
+
return
|
352 |
+
|
353 |
+
self.__quoting_flags = value
|
354 |
+
self.__clear_cache()
|
355 |
+
|
356 |
+
@property
|
357 |
+
def datetime_formatter(self) -> Optional[DateTimeFormatter]:
|
358 |
+
return self.__datetime_formatter
|
359 |
+
|
360 |
+
@datetime_formatter.setter
|
361 |
+
def datetime_formatter(self, value: Optional[DateTimeFormatter]) -> None:
|
362 |
+
if self.__datetime_formatter == value:
|
363 |
+
return
|
364 |
+
|
365 |
+
self.__datetime_formatter = value
|
366 |
+
self.__clear_cache()
|
367 |
+
|
368 |
+
@property
|
369 |
+
def matrix_formatting(self) -> MatrixFormatting:
|
370 |
+
return self.__matrix_formatting
|
371 |
+
|
372 |
+
@matrix_formatting.setter
|
373 |
+
def matrix_formatting(self, value: MatrixFormatting) -> None:
|
374 |
+
if self.__matrix_formatting == value:
|
375 |
+
return
|
376 |
+
|
377 |
+
self.__matrix_formatting = value
|
378 |
+
self.__clear_cache()
|
379 |
+
|
380 |
+
@property
|
381 |
+
def max_workers(self) -> int:
|
382 |
+
assert self.__max_workers
|
383 |
+
|
384 |
+
return self.__max_workers
|
385 |
+
|
386 |
+
@max_workers.setter
|
387 |
+
def max_workers(self, value: Optional[int]) -> None:
|
388 |
+
try:
|
389 |
+
from _multiprocessing import SemLock, sem_unlink # noqa
|
390 |
+
except ImportError:
|
391 |
+
logger.debug("This platform lacks a functioning sem_open implementation")
|
392 |
+
value = 1
|
393 |
+
|
394 |
+
if "pytest" in sys.modules and value != 1:
|
395 |
+
logger.debug("set max_workers to 1 to avoid deadlock when executed from pytest")
|
396 |
+
value = 1
|
397 |
+
|
398 |
+
self.__max_workers = value
|
399 |
+
if not self.__max_workers:
|
400 |
+
self.__max_workers = DefaultValue.MAX_WORKERS
|
401 |
+
|
402 |
+
def to_dp(self, value: Any) -> DataProperty:
|
403 |
+
self.__update_dp_converter()
|
404 |
+
|
405 |
+
return self.__to_dp(value)
|
406 |
+
|
407 |
+
def to_dp_list(self, values: Sequence[Any]) -> List[DataProperty]:
|
408 |
+
if is_empty_sequence(values):
|
409 |
+
return []
|
410 |
+
|
411 |
+
self.__update_dp_converter()
|
412 |
+
|
413 |
+
return self._to_dp_list(values)
|
414 |
+
|
415 |
+
def to_column_dp_list(
|
416 |
+
self,
|
417 |
+
value_dp_matrix: Any,
|
418 |
+
previous_column_dp_list: Optional[Sequence[ColumnDataProperty]] = None,
|
419 |
+
) -> List[ColumnDataProperty]:
|
420 |
+
col_dp_list = self.__get_col_dp_list_base()
|
421 |
+
|
422 |
+
logger.debug("converting to column dataproperty:")
|
423 |
+
|
424 |
+
logs = [" params:"]
|
425 |
+
if self.headers:
|
426 |
+
logs.append(f" headers={len(self.headers)}")
|
427 |
+
logs.extend(
|
428 |
+
[
|
429 |
+
" prev_col_count={}".format(
|
430 |
+
len(previous_column_dp_list) if previous_column_dp_list else None
|
431 |
+
),
|
432 |
+
f" matrix_formatting={self.matrix_formatting}",
|
433 |
+
]
|
434 |
+
)
|
435 |
+
if self.column_type_hints:
|
436 |
+
logs.append(
|
437 |
+
" column_type_hints=({})".format(
|
438 |
+
", ".join(
|
439 |
+
[
|
440 |
+
type_hint.__name__ if type_hint else "none"
|
441 |
+
for type_hint in self.column_type_hints
|
442 |
+
]
|
443 |
+
)
|
444 |
+
)
|
445 |
+
)
|
446 |
+
else:
|
447 |
+
logs.append(" column_type_hints=()")
|
448 |
+
|
449 |
+
for log in logs:
|
450 |
+
logger.debug(log)
|
451 |
+
|
452 |
+
logger.debug(" results:")
|
453 |
+
for col_idx, value_dp_list in enumerate(zip(*value_dp_matrix)):
|
454 |
+
try:
|
455 |
+
col_dp_list[col_idx]
|
456 |
+
except IndexError:
|
457 |
+
col_dp_list.append(
|
458 |
+
ColumnDataProperty(
|
459 |
+
column_index=col_idx,
|
460 |
+
float_type=self.float_type,
|
461 |
+
min_width=self.min_column_width,
|
462 |
+
format_flags=self.__get_format_flags(col_idx),
|
463 |
+
is_formatting_float=self.is_formatting_float,
|
464 |
+
datetime_format_str=self.datetime_format_str,
|
465 |
+
east_asian_ambiguous_width=self.east_asian_ambiguous_width,
|
466 |
+
max_precision=self.__max_precision,
|
467 |
+
)
|
468 |
+
)
|
469 |
+
|
470 |
+
col_dp = col_dp_list[col_idx]
|
471 |
+
col_dp.begin_update()
|
472 |
+
|
473 |
+
try:
|
474 |
+
col_dp.merge(previous_column_dp_list[col_idx]) # type: ignore
|
475 |
+
except (TypeError, IndexError):
|
476 |
+
pass
|
477 |
+
|
478 |
+
for value_dp in value_dp_list:
|
479 |
+
col_dp.update_body(value_dp)
|
480 |
+
|
481 |
+
col_dp.end_update()
|
482 |
+
|
483 |
+
logger.debug(f" {str(col_dp):s}")
|
484 |
+
|
485 |
+
return col_dp_list
|
486 |
+
|
487 |
+
def to_dp_matrix(self, value_matrix: Sequence[Sequence[Any]]) -> DataPropertyMatrix:
|
488 |
+
self.__update_dp_converter()
|
489 |
+
logger.debug(f"max_workers={self.max_workers}, preprocessor={self.__preprocessor}")
|
490 |
+
|
491 |
+
value_matrix = self.__strip_data_matrix(value_matrix)
|
492 |
+
|
493 |
+
if self.__is_dp_matrix(value_matrix):
|
494 |
+
logger.debug("already a dataproperty matrix")
|
495 |
+
return value_matrix # type: ignore
|
496 |
+
|
497 |
+
if self.max_workers <= 1:
|
498 |
+
return self.__to_dp_matrix_st(value_matrix)
|
499 |
+
|
500 |
+
return self.__to_dp_matrix_mt(value_matrix)
|
501 |
+
|
502 |
+
def to_header_dp_list(self) -> List[DataProperty]:
|
503 |
+
self.__update_dp_converter()
|
504 |
+
|
505 |
+
preprocessor = copy.deepcopy(self.__preprocessor)
|
506 |
+
preprocessor.strip_str = self.strip_str_header
|
507 |
+
|
508 |
+
return self._to_dp_list(
|
509 |
+
self.headers,
|
510 |
+
type_hint=String,
|
511 |
+
preprocessor=preprocessor,
|
512 |
+
strict_level_map=MIN_STRICT_LEVEL_MAP,
|
513 |
+
)
|
514 |
+
|
515 |
+
def update_preprocessor(self, **kwargs: Any) -> bool:
|
516 |
+
is_updated = self.__preprocessor.update(**kwargs)
|
517 |
+
self.__update_dp_converter()
|
518 |
+
|
519 |
+
return is_updated
|
520 |
+
|
521 |
+
def update_strict_level_map(self, value: StrictLevelMap) -> bool:
|
522 |
+
org = copy.deepcopy(self.__strict_level_map)
|
523 |
+
self.__strict_level_map.update(value)
|
524 |
+
|
525 |
+
if org == self.__strict_level_map:
|
526 |
+
return False
|
527 |
+
|
528 |
+
self.__clear_cache()
|
529 |
+
|
530 |
+
return True
|
531 |
+
|
532 |
+
"""
|
533 |
+
def update_dict(self, lhs: Mapping, rhs: Mapping) -> bool:
|
534 |
+
is_updated = False
|
535 |
+
|
536 |
+
for key, value in rhs.items():
|
537 |
+
if key not in lhs:
|
538 |
+
lhs[]
|
539 |
+
continue
|
540 |
+
|
541 |
+
if getattr(lhs, key) == value:
|
542 |
+
continue
|
543 |
+
|
544 |
+
setattr(lhs, key, value)
|
545 |
+
is_updated = True
|
546 |
+
|
547 |
+
return is_updated
|
548 |
+
"""
|
549 |
+
|
550 |
+
@staticmethod
|
551 |
+
def __is_dp_matrix(value: Any) -> bool:
|
552 |
+
try:
|
553 |
+
return isinstance(value[0][0], DataProperty)
|
554 |
+
except (TypeError, IndexError):
|
555 |
+
return False
|
556 |
+
|
557 |
+
def __get_col_type_hint(self, col_idx: int) -> TypeHint:
|
558 |
+
try:
|
559 |
+
return self.column_type_hints[col_idx]
|
560 |
+
except (TypeError, IndexError):
|
561 |
+
return self.default_type_hint
|
562 |
+
|
563 |
+
def __get_format_flags(self, col_idx: int) -> int:
|
564 |
+
try:
|
565 |
+
return self.format_flags_list[col_idx]
|
566 |
+
except (TypeError, IndexError):
|
567 |
+
return self.__default_format_flags
|
568 |
+
|
569 |
+
def __to_dp(
|
570 |
+
self,
|
571 |
+
data: Any,
|
572 |
+
type_hint: TypeHint = None,
|
573 |
+
preprocessor: Optional[Preprocessor] = None,
|
574 |
+
strict_level_map: Optional[StrictLevelMap] = None,
|
575 |
+
) -> DataProperty:
|
576 |
+
for trans_func in self.__trans_func_list:
|
577 |
+
data = trans_func(data)
|
578 |
+
|
579 |
+
if type_hint:
|
580 |
+
return self.__to_dp_raw(
|
581 |
+
data,
|
582 |
+
type_hint=type_hint,
|
583 |
+
preprocessor=preprocessor,
|
584 |
+
strict_level_map=strict_level_map,
|
585 |
+
)
|
586 |
+
|
587 |
+
try:
|
588 |
+
if data in self.__dp_cache_map:
|
589 |
+
return self.__dp_cache_map[data]
|
590 |
+
except TypeError:
|
591 |
+
# unhashable type
|
592 |
+
pass
|
593 |
+
|
594 |
+
if data == 0:
|
595 |
+
if data is False:
|
596 |
+
return self.__dp_cache_false
|
597 |
+
return self.__dp_cache_zero
|
598 |
+
if data == 1:
|
599 |
+
if data is True:
|
600 |
+
return self.__dp_cache_true
|
601 |
+
return self.__dp_cache_one
|
602 |
+
|
603 |
+
return self.__to_dp_raw(
|
604 |
+
data, type_hint=type_hint, preprocessor=preprocessor, strict_level_map=strict_level_map
|
605 |
+
)
|
606 |
+
|
607 |
+
def __to_dp_raw(
|
608 |
+
self,
|
609 |
+
data: Any,
|
610 |
+
type_hint: TypeHint = None,
|
611 |
+
preprocessor: Optional[Preprocessor] = None,
|
612 |
+
strict_level_map: Optional[StrictLevelMap] = None,
|
613 |
+
) -> DataProperty:
|
614 |
+
if preprocessor:
|
615 |
+
preprocessor = Preprocessor(
|
616 |
+
dequote=preprocessor.dequote,
|
617 |
+
line_break_handling=preprocessor.line_break_handling,
|
618 |
+
line_break_repl=preprocessor.line_break_repl,
|
619 |
+
strip_str=preprocessor.strip_str,
|
620 |
+
is_escape_formula_injection=preprocessor.is_escape_formula_injection,
|
621 |
+
)
|
622 |
+
else:
|
623 |
+
preprocessor = Preprocessor(
|
624 |
+
dequote=self.preprocessor.dequote,
|
625 |
+
line_break_handling=self.preprocessor.line_break_handling,
|
626 |
+
line_break_repl=self.preprocessor.line_break_repl,
|
627 |
+
strip_str=self.preprocessor.strip_str,
|
628 |
+
is_escape_formula_injection=self.__preprocessor.is_escape_formula_injection,
|
629 |
+
)
|
630 |
+
|
631 |
+
value_dp = DataProperty(
|
632 |
+
data,
|
633 |
+
preprocessor=preprocessor,
|
634 |
+
type_hint=(type_hint if type_hint is not None else self.default_type_hint),
|
635 |
+
float_type=self.float_type,
|
636 |
+
datetime_format_str=self.datetime_format_str,
|
637 |
+
strict_level_map=(strict_level_map if type_hint is not None else self.strict_level_map),
|
638 |
+
east_asian_ambiguous_width=self.east_asian_ambiguous_width,
|
639 |
+
)
|
640 |
+
|
641 |
+
return self.__dp_converter.convert(value_dp)
|
642 |
+
|
643 |
+
def __to_dp_matrix_st(self, value_matrix: Sequence[Sequence[Any]]) -> DataPropertyMatrix:
|
644 |
+
return list(
|
645 |
+
zip( # type: ignore
|
646 |
+
*(
|
647 |
+
_to_dp_list_helper(
|
648 |
+
self,
|
649 |
+
col_idx,
|
650 |
+
values,
|
651 |
+
self.__get_col_type_hint(col_idx),
|
652 |
+
self.__preprocessor,
|
653 |
+
)[1]
|
654 |
+
for col_idx, values in enumerate(zip(*value_matrix))
|
655 |
+
)
|
656 |
+
)
|
657 |
+
)
|
658 |
+
|
659 |
+
def __to_dp_matrix_mt(self, value_matrix: Sequence[Sequence[Any]]) -> DataPropertyMatrix:
|
660 |
+
from concurrent import futures
|
661 |
+
|
662 |
+
col_data_map = {}
|
663 |
+
|
664 |
+
with futures.ProcessPoolExecutor(self.max_workers) as executor:
|
665 |
+
future_list = [
|
666 |
+
executor.submit(
|
667 |
+
_to_dp_list_helper,
|
668 |
+
self,
|
669 |
+
col_idx,
|
670 |
+
values,
|
671 |
+
self.__get_col_type_hint(col_idx),
|
672 |
+
self.__preprocessor,
|
673 |
+
)
|
674 |
+
for col_idx, values in enumerate(zip(*value_matrix))
|
675 |
+
]
|
676 |
+
|
677 |
+
for future in futures.as_completed(future_list):
|
678 |
+
col_idx, value_dp_list = future.result()
|
679 |
+
col_data_map[col_idx] = value_dp_list
|
680 |
+
|
681 |
+
return list(
|
682 |
+
zip(*(col_data_map[col_idx] for col_idx in sorted(col_data_map))) # type: ignore
|
683 |
+
)
|
684 |
+
|
685 |
+
def _to_dp_list(
|
686 |
+
self,
|
687 |
+
data_list: Sequence[Any],
|
688 |
+
type_hint: TypeHint = None,
|
689 |
+
preprocessor: Optional[Preprocessor] = None,
|
690 |
+
strict_level_map: Optional[StrictLevelMap] = None,
|
691 |
+
) -> List[DataProperty]:
|
692 |
+
if is_empty_sequence(data_list):
|
693 |
+
return []
|
694 |
+
|
695 |
+
type_counter: typing.Counter[Type[AbstractType]] = Counter()
|
696 |
+
|
697 |
+
dp_list = []
|
698 |
+
for data in data_list:
|
699 |
+
expect_type_hint: TypeHint = type_hint
|
700 |
+
if type_hint is None:
|
701 |
+
try:
|
702 |
+
expect_type_hint, _count = type_counter.most_common(1)[0]
|
703 |
+
if not expect_type_hint(
|
704 |
+
data, float_type=self.float_type, strict_level=StrictLevel.MAX
|
705 |
+
).is_type():
|
706 |
+
expect_type_hint = None
|
707 |
+
except IndexError:
|
708 |
+
pass
|
709 |
+
|
710 |
+
dataprop = self.__to_dp(
|
711 |
+
data=data,
|
712 |
+
type_hint=expect_type_hint,
|
713 |
+
preprocessor=preprocessor if preprocessor else self.__preprocessor,
|
714 |
+
strict_level_map=strict_level_map,
|
715 |
+
)
|
716 |
+
type_counter[dataprop.type_class] += 1
|
717 |
+
|
718 |
+
dp_list.append(dataprop)
|
719 |
+
|
720 |
+
return dp_list
|
721 |
+
|
722 |
+
def __strip_data_matrix(self, data_matrix: Sequence[Sequence[Any]]) -> Sequence[Sequence[Any]]:
|
723 |
+
header_col_size = len(self.headers) if self.headers else 0
|
724 |
+
try:
|
725 |
+
col_size_list = [len(data_list) for data_list in data_matrix]
|
726 |
+
except TypeError:
|
727 |
+
return []
|
728 |
+
|
729 |
+
if self.headers:
|
730 |
+
min_col_size = min([header_col_size] + col_size_list)
|
731 |
+
max_col_size = max([header_col_size] + col_size_list)
|
732 |
+
elif col_size_list:
|
733 |
+
min_col_size = min(col_size_list)
|
734 |
+
max_col_size = max(col_size_list)
|
735 |
+
else:
|
736 |
+
min_col_size = 0
|
737 |
+
max_col_size = 0
|
738 |
+
|
739 |
+
if self.matrix_formatting == MatrixFormatting.EXCEPTION:
|
740 |
+
if min_col_size != max_col_size:
|
741 |
+
raise ValueError(
|
742 |
+
"nonuniform column size found: min={}, max={}".format(
|
743 |
+
min_col_size, max_col_size
|
744 |
+
)
|
745 |
+
)
|
746 |
+
|
747 |
+
return data_matrix
|
748 |
+
|
749 |
+
if self.matrix_formatting == MatrixFormatting.HEADER_ALIGNED:
|
750 |
+
if header_col_size > 0:
|
751 |
+
format_col_size = header_col_size
|
752 |
+
else:
|
753 |
+
format_col_size = max_col_size
|
754 |
+
elif self.matrix_formatting == MatrixFormatting.TRIM:
|
755 |
+
format_col_size = min_col_size
|
756 |
+
elif self.matrix_formatting == MatrixFormatting.FILL_NONE:
|
757 |
+
format_col_size = max_col_size
|
758 |
+
else:
|
759 |
+
raise ValueError(f"unknown matrix formatting: {self.matrix_formatting}")
|
760 |
+
|
761 |
+
return [
|
762 |
+
list(data_matrix[row_idx][:format_col_size]) + [None] * (format_col_size - col_size)
|
763 |
+
for row_idx, col_size in enumerate(col_size_list)
|
764 |
+
]
|
765 |
+
|
766 |
+
def __get_col_dp_list_base(self) -> List[ColumnDataProperty]:
|
767 |
+
header_dp_list = self.to_header_dp_list()
|
768 |
+
col_dp_list = []
|
769 |
+
|
770 |
+
for col_idx, header_dp in enumerate(header_dp_list):
|
771 |
+
col_dp = ColumnDataProperty(
|
772 |
+
column_index=col_idx,
|
773 |
+
float_type=self.float_type,
|
774 |
+
min_width=self.min_column_width,
|
775 |
+
format_flags=self.__get_format_flags(col_idx),
|
776 |
+
is_formatting_float=self.is_formatting_float,
|
777 |
+
datetime_format_str=self.datetime_format_str,
|
778 |
+
east_asian_ambiguous_width=self.east_asian_ambiguous_width,
|
779 |
+
max_precision=self.__max_precision,
|
780 |
+
)
|
781 |
+
col_dp.update_header(header_dp)
|
782 |
+
col_dp_list.append(col_dp)
|
783 |
+
|
784 |
+
return col_dp_list
|
785 |
+
|
786 |
+
def __update_dp_converter(self) -> None:
|
787 |
+
preprocessor = Preprocessor(
|
788 |
+
line_break_handling=self.__preprocessor.line_break_handling,
|
789 |
+
line_break_repl=self.preprocessor.line_break_repl,
|
790 |
+
is_escape_html_tag=self.__preprocessor.is_escape_html_tag,
|
791 |
+
is_escape_formula_injection=self.__preprocessor.is_escape_formula_injection,
|
792 |
+
)
|
793 |
+
self.__dp_converter = DataPropertyConverter(
|
794 |
+
preprocessor=preprocessor,
|
795 |
+
type_value_map=self.type_value_map,
|
796 |
+
quoting_flags=self.quoting_flags,
|
797 |
+
datetime_formatter=self.datetime_formatter,
|
798 |
+
datetime_format_str=self.datetime_format_str,
|
799 |
+
float_type=self.float_type,
|
800 |
+
strict_level_map=self.strict_level_map,
|
801 |
+
)
|
802 |
+
|
803 |
+
|
804 |
+
def _to_dp_list_helper(
|
805 |
+
extractor: DataPropertyExtractor,
|
806 |
+
col_idx: int,
|
807 |
+
data_list: Sequence[Any],
|
808 |
+
type_hint: TypeHint,
|
809 |
+
preprocessor: Preprocessor,
|
810 |
+
) -> Tuple[int, List[DataProperty]]:
|
811 |
+
return (
|
812 |
+
col_idx,
|
813 |
+
extractor._to_dp_list(data_list, type_hint=type_hint, preprocessor=preprocessor),
|
814 |
+
)
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_formatter.py
ADDED
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import copy
|
2 |
+
from decimal import Decimal
|
3 |
+
from typing import Dict, Optional, Union
|
4 |
+
|
5 |
+
from typepy import Nan, Typecode
|
6 |
+
|
7 |
+
|
8 |
+
DecimalPlaces = Union[float, Decimal]
|
9 |
+
|
10 |
+
|
11 |
+
class Format:
|
12 |
+
NONE = 0
|
13 |
+
THOUSAND_SEPARATOR = 1
|
14 |
+
|
15 |
+
|
16 |
+
class Formatter:
|
17 |
+
__slots__ = ("__is_formatting_float", "__format_flags", "__datetime_format_str")
|
18 |
+
|
19 |
+
_BLANK_CURLY_BRACES_FORMAT_MAP: Dict[Typecode, str] = {
|
20 |
+
Typecode.NONE: "{}",
|
21 |
+
Typecode.IP_ADDRESS: "{}",
|
22 |
+
Typecode.BOOL: "{}",
|
23 |
+
Typecode.DICTIONARY: "{}",
|
24 |
+
Typecode.LIST: "{}",
|
25 |
+
}
|
26 |
+
|
27 |
+
def __init__(
|
28 |
+
self,
|
29 |
+
datetime_format_str: str,
|
30 |
+
is_formatting_float: Optional[bool] = True,
|
31 |
+
format_flags: Optional[int] = None,
|
32 |
+
) -> None:
|
33 |
+
if format_flags is not None:
|
34 |
+
self.__format_flags = format_flags
|
35 |
+
else:
|
36 |
+
self.__format_flags = Format.NONE
|
37 |
+
|
38 |
+
self.__datetime_format_str = datetime_format_str
|
39 |
+
self.__is_formatting_float = is_formatting_float
|
40 |
+
|
41 |
+
def make_format_map(
|
42 |
+
self, decimal_places: Optional[DecimalPlaces] = None
|
43 |
+
) -> Dict[Typecode, str]:
|
44 |
+
format_map = copy.copy(self._BLANK_CURLY_BRACES_FORMAT_MAP)
|
45 |
+
format_map.update(
|
46 |
+
{
|
47 |
+
Typecode.INTEGER: self.make_format_str(Typecode.INTEGER),
|
48 |
+
Typecode.REAL_NUMBER: self.make_format_str(Typecode.REAL_NUMBER, decimal_places),
|
49 |
+
Typecode.INFINITY: self.make_format_str(Typecode.INFINITY),
|
50 |
+
Typecode.NAN: self.make_format_str(Typecode.NAN),
|
51 |
+
Typecode.DATETIME: self.make_format_str(Typecode.DATETIME),
|
52 |
+
}
|
53 |
+
)
|
54 |
+
|
55 |
+
return format_map
|
56 |
+
|
57 |
+
def make_format_str(
|
58 |
+
self, typecode: Typecode, decimal_places: Optional[DecimalPlaces] = None
|
59 |
+
) -> str:
|
60 |
+
format_str = self._BLANK_CURLY_BRACES_FORMAT_MAP.get(typecode)
|
61 |
+
if format_str is not None:
|
62 |
+
return format_str
|
63 |
+
|
64 |
+
if typecode == Typecode.INTEGER:
|
65 |
+
return self.__get_integer_format()
|
66 |
+
|
67 |
+
if typecode in (Typecode.REAL_NUMBER, Typecode.INFINITY, Typecode.NAN):
|
68 |
+
return self.__get_realnumber_format(decimal_places)
|
69 |
+
|
70 |
+
if typecode == Typecode.DATETIME:
|
71 |
+
return "{:" + self.__datetime_format_str + "}"
|
72 |
+
|
73 |
+
return "{:s}"
|
74 |
+
|
75 |
+
def __get_base_format_str(self) -> str:
|
76 |
+
if self.__format_flags & Format.THOUSAND_SEPARATOR:
|
77 |
+
return ","
|
78 |
+
|
79 |
+
return ""
|
80 |
+
|
81 |
+
def __get_integer_format(self) -> str:
|
82 |
+
return "{:" + self.__get_base_format_str() + "d}"
|
83 |
+
|
84 |
+
def __get_realnumber_format(self, decimal_places: Optional[DecimalPlaces]) -> str:
|
85 |
+
if not self.__is_formatting_float:
|
86 |
+
return "{}"
|
87 |
+
|
88 |
+
base_format = self.__get_base_format_str()
|
89 |
+
|
90 |
+
if decimal_places is None or Nan(decimal_places).is_type():
|
91 |
+
return "{:" + base_format + "f}"
|
92 |
+
|
93 |
+
try:
|
94 |
+
return "{:" + f"{base_format:s}.{decimal_places:d}f" + "}"
|
95 |
+
except ValueError:
|
96 |
+
pass
|
97 |
+
|
98 |
+
return "{:" + base_format + "f}"
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_function.py
ADDED
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import decimal
|
6 |
+
import re
|
7 |
+
from decimal import Decimal
|
8 |
+
from typing import Any, Optional, Tuple, Union
|
9 |
+
|
10 |
+
from typepy import Integer, RealNumber, TypeConversionError
|
11 |
+
|
12 |
+
|
13 |
+
decimal.setcontext(decimal.Context(prec=60, rounding=decimal.ROUND_HALF_DOWN))
|
14 |
+
|
15 |
+
_ansi_escape = re.compile(r"(\x9b|\x1b\[)[0-?]*[ -\/]*[@-~]", re.IGNORECASE)
|
16 |
+
|
17 |
+
|
18 |
+
def get_integer_digit(value: Any) -> int:
|
19 |
+
float_type = RealNumber(value)
|
20 |
+
|
21 |
+
try:
|
22 |
+
abs_value = abs(float_type.convert())
|
23 |
+
except TypeConversionError:
|
24 |
+
try:
|
25 |
+
abs_value = abs(Integer(value).convert())
|
26 |
+
except TypeConversionError:
|
27 |
+
raise ValueError(f"the value must be a number: value='{value}' type='{type(value)}'")
|
28 |
+
|
29 |
+
return len(str(abs_value))
|
30 |
+
|
31 |
+
if abs_value.is_zero():
|
32 |
+
return 1
|
33 |
+
|
34 |
+
try:
|
35 |
+
return len(str(abs_value.quantize(Decimal("1."), rounding=decimal.ROUND_DOWN)))
|
36 |
+
except decimal.InvalidOperation:
|
37 |
+
return len(str(abs_value))
|
38 |
+
|
39 |
+
|
40 |
+
class DigitCalculator:
|
41 |
+
REGEXP_COMMON_LOG = re.compile(r"[\d\.]+[eE]\-\d+")
|
42 |
+
REGEXP_SPLIT = re.compile(r"[eE]\-")
|
43 |
+
|
44 |
+
def get_decimal_places(self, value: Union[str, float, int, Decimal]) -> int:
|
45 |
+
if Integer(value).is_type():
|
46 |
+
return 0
|
47 |
+
|
48 |
+
float_digit_len = 0
|
49 |
+
abs_value = abs(float(value))
|
50 |
+
text_value = str(abs_value)
|
51 |
+
float_text = "0"
|
52 |
+
if text_value.find(".") != -1:
|
53 |
+
float_text = text_value.split(".")[1]
|
54 |
+
float_digit_len = len(float_text)
|
55 |
+
elif self.REGEXP_COMMON_LOG.search(text_value):
|
56 |
+
float_text = self.REGEXP_SPLIT.split(text_value)[1]
|
57 |
+
float_digit_len = int(float_text)
|
58 |
+
|
59 |
+
return float_digit_len
|
60 |
+
|
61 |
+
|
62 |
+
_digit_calculator = DigitCalculator()
|
63 |
+
|
64 |
+
|
65 |
+
def get_number_of_digit(
|
66 |
+
value: Any, max_decimal_places: int = 99
|
67 |
+
) -> Tuple[Optional[int], Optional[int]]:
|
68 |
+
try:
|
69 |
+
integer_digits = get_integer_digit(value)
|
70 |
+
except (ValueError, TypeError, OverflowError):
|
71 |
+
return (None, None)
|
72 |
+
|
73 |
+
try:
|
74 |
+
decimal_places: Optional[int] = min(
|
75 |
+
_digit_calculator.get_decimal_places(value), max_decimal_places
|
76 |
+
)
|
77 |
+
except (ValueError, TypeError):
|
78 |
+
decimal_places = None
|
79 |
+
|
80 |
+
return (integer_digits, decimal_places)
|
81 |
+
|
82 |
+
|
83 |
+
def _validate_eaaw(east_asian_ambiguous_width: int) -> None:
|
84 |
+
if east_asian_ambiguous_width in (1, 2):
|
85 |
+
return
|
86 |
+
|
87 |
+
raise ValueError(
|
88 |
+
"invalid east_asian_ambiguous_width: expected=1 or 2, actual={}".format(
|
89 |
+
east_asian_ambiguous_width
|
90 |
+
)
|
91 |
+
)
|
92 |
+
|
93 |
+
|
94 |
+
def strip_ansi_escape(unicode_str: str) -> str:
|
95 |
+
return _ansi_escape.sub("", unicode_str)
|
96 |
+
|
97 |
+
|
98 |
+
def calc_ascii_char_width(unicode_str: str, east_asian_ambiguous_width: int = 1) -> int:
|
99 |
+
import unicodedata
|
100 |
+
|
101 |
+
width = 0
|
102 |
+
for char in unicode_str:
|
103 |
+
char_width = unicodedata.east_asian_width(char)
|
104 |
+
if char_width in "WF":
|
105 |
+
width += 2
|
106 |
+
elif char_width == "A":
|
107 |
+
_validate_eaaw(east_asian_ambiguous_width)
|
108 |
+
width += east_asian_ambiguous_width
|
109 |
+
else:
|
110 |
+
width += 1
|
111 |
+
|
112 |
+
return width
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_interface.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
import abc
|
6 |
+
from typing import Optional
|
7 |
+
|
8 |
+
from typepy import Typecode
|
9 |
+
|
10 |
+
from ._align import Align
|
11 |
+
|
12 |
+
|
13 |
+
class DataPeropertyInterface(metaclass=abc.ABCMeta):
|
14 |
+
__slots__ = ()
|
15 |
+
|
16 |
+
@abc.abstractproperty
|
17 |
+
def align(self) -> Align: # pragma: no cover
|
18 |
+
pass
|
19 |
+
|
20 |
+
@abc.abstractproperty
|
21 |
+
def decimal_places(self) -> Optional[int]: # pragma: no cover
|
22 |
+
pass
|
23 |
+
|
24 |
+
@abc.abstractproperty
|
25 |
+
def typecode(self) -> Typecode: # pragma: no cover
|
26 |
+
pass
|
27 |
+
|
28 |
+
@abc.abstractproperty
|
29 |
+
def typename(self) -> str: # pragma: no cover
|
30 |
+
pass
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_line_break.py
ADDED
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from enum import Enum, unique
|
2 |
+
|
3 |
+
|
4 |
+
@unique
|
5 |
+
class LineBreakHandling(Enum):
|
6 |
+
NOP = 0
|
7 |
+
REPLACE = 1
|
8 |
+
ESCAPE = 2
|
env-llmeval/lib/python3.10/site-packages/dataproperty/_preprocessor.py
ADDED
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import html
|
2 |
+
import re
|
3 |
+
from typing import Any, Optional, Tuple, Union
|
4 |
+
|
5 |
+
from mbstrdecoder import MultiByteStrDecoder
|
6 |
+
|
7 |
+
from ._function import strip_ansi_escape
|
8 |
+
from ._line_break import LineBreakHandling
|
9 |
+
|
10 |
+
|
11 |
+
_RE_LINE_BREAK = re.compile(r"\r\n|\n")
|
12 |
+
_RE_FORMULA_PREFIX = re.compile(r"^[-\+=@]")
|
13 |
+
|
14 |
+
|
15 |
+
def normalize_lbh(value: Optional[LineBreakHandling]) -> LineBreakHandling:
|
16 |
+
if isinstance(value, LineBreakHandling):
|
17 |
+
return value
|
18 |
+
|
19 |
+
if value is None:
|
20 |
+
return LineBreakHandling.NOP
|
21 |
+
|
22 |
+
return LineBreakHandling[value.upper()] # type: ignore
|
23 |
+
|
24 |
+
|
25 |
+
class Preprocessor:
|
26 |
+
@property
|
27 |
+
def line_break_handling(self) -> Optional[LineBreakHandling]:
|
28 |
+
return self.__line_break_handling
|
29 |
+
|
30 |
+
@line_break_handling.setter
|
31 |
+
def line_break_handling(self, value: Optional[LineBreakHandling]) -> None:
|
32 |
+
self.__line_break_handling = normalize_lbh(value)
|
33 |
+
|
34 |
+
def __init__(
|
35 |
+
self,
|
36 |
+
strip_str: Optional[Union[str, bytes]] = None,
|
37 |
+
replace_tabs_with_spaces: bool = True,
|
38 |
+
tab_length: int = 2,
|
39 |
+
line_break_handling: Optional[LineBreakHandling] = None,
|
40 |
+
line_break_repl: str = " ",
|
41 |
+
dequote: bool = False,
|
42 |
+
is_escape_html_tag: bool = False,
|
43 |
+
is_escape_formula_injection: bool = False,
|
44 |
+
) -> None:
|
45 |
+
self.strip_str = strip_str
|
46 |
+
self.replace_tabs_with_spaces = replace_tabs_with_spaces
|
47 |
+
self.tab_length = tab_length
|
48 |
+
self.line_break_handling = line_break_handling
|
49 |
+
self.line_break_repl = line_break_repl
|
50 |
+
self.dequote = dequote
|
51 |
+
self.is_escape_html_tag = is_escape_html_tag
|
52 |
+
self.is_escape_formula_injection = is_escape_formula_injection
|
53 |
+
|
54 |
+
def __repr__(self) -> str:
|
55 |
+
return ", ".join(
|
56 |
+
[
|
57 |
+
f"strip_str={self.strip_str!r}",
|
58 |
+
f"replace_tabs_with_spaces={self.replace_tabs_with_spaces}",
|
59 |
+
f"tab_length={self.tab_length}",
|
60 |
+
f"line_break_handling={self.line_break_handling}",
|
61 |
+
f"line_break_repl={self.line_break_repl}",
|
62 |
+
f"escape_html_tag={self.is_escape_html_tag}",
|
63 |
+
f"escape_formula_injection={self.is_escape_formula_injection}",
|
64 |
+
]
|
65 |
+
)
|
66 |
+
|
67 |
+
def preprocess(self, data: Any) -> Tuple:
|
68 |
+
data, no_ansi_escape_data = self.__preprocess_string(
|
69 |
+
self.__preprocess_data(data, self.strip_str),
|
70 |
+
)
|
71 |
+
return (data, no_ansi_escape_data)
|
72 |
+
|
73 |
+
def update(self, **kwargs: Any) -> bool:
|
74 |
+
is_updated = False
|
75 |
+
|
76 |
+
for key, value in kwargs.items():
|
77 |
+
if not hasattr(self, key):
|
78 |
+
continue
|
79 |
+
|
80 |
+
if getattr(self, key) == value:
|
81 |
+
continue
|
82 |
+
|
83 |
+
setattr(self, key, value)
|
84 |
+
is_updated = True
|
85 |
+
|
86 |
+
return is_updated
|
87 |
+
|
88 |
+
def __preprocess_string(self, raw_data: Any) -> Tuple[Any, Optional[str]]:
|
89 |
+
data = raw_data
|
90 |
+
|
91 |
+
if not isinstance(data, str):
|
92 |
+
return (data, None)
|
93 |
+
|
94 |
+
if self.replace_tabs_with_spaces:
|
95 |
+
try:
|
96 |
+
data = data.replace("\t", " " * self.tab_length)
|
97 |
+
except (TypeError, AttributeError, ValueError):
|
98 |
+
pass
|
99 |
+
|
100 |
+
if self.is_escape_html_tag:
|
101 |
+
try:
|
102 |
+
data = html.escape(data)
|
103 |
+
except AttributeError:
|
104 |
+
return (data, None)
|
105 |
+
|
106 |
+
data = self.__process_line_break(data)
|
107 |
+
data = self.__escape_formula_injection(data)
|
108 |
+
data = self.__dequote(data)
|
109 |
+
|
110 |
+
try:
|
111 |
+
return (data, strip_ansi_escape(data))
|
112 |
+
except TypeError:
|
113 |
+
return (data, None)
|
114 |
+
|
115 |
+
@staticmethod
|
116 |
+
def __preprocess_data(data: Any, strip_str: Optional[Union[str, bytes]]) -> Any:
|
117 |
+
if strip_str is None:
|
118 |
+
return data
|
119 |
+
|
120 |
+
try:
|
121 |
+
return data.strip(strip_str)
|
122 |
+
except AttributeError:
|
123 |
+
return data
|
124 |
+
except UnicodeDecodeError:
|
125 |
+
return MultiByteStrDecoder(data).unicode_str.strip(strip_str)
|
126 |
+
except TypeError:
|
127 |
+
# reach here when data and strip_str type are different
|
128 |
+
if isinstance(data, bytes):
|
129 |
+
return MultiByteStrDecoder(data).unicode_str.strip(strip_str)
|
130 |
+
elif isinstance(strip_str, bytes):
|
131 |
+
return data.strip(MultiByteStrDecoder(strip_str).unicode_str)
|
132 |
+
|
133 |
+
def __dequote(self, s: str) -> str:
|
134 |
+
if not self.dequote or not s:
|
135 |
+
return s
|
136 |
+
|
137 |
+
try:
|
138 |
+
if (s[0] == s[-1]) and s.startswith(("'", '"')):
|
139 |
+
if s.count(s[0]) == 2:
|
140 |
+
return s[1:-1]
|
141 |
+
except TypeError:
|
142 |
+
pass
|
143 |
+
|
144 |
+
return s
|
145 |
+
|
146 |
+
def __process_line_break(self, data: str) -> str:
|
147 |
+
lbh = self.line_break_handling
|
148 |
+
|
149 |
+
if lbh == LineBreakHandling.NOP:
|
150 |
+
return data
|
151 |
+
|
152 |
+
try:
|
153 |
+
if lbh == LineBreakHandling.REPLACE:
|
154 |
+
return _RE_LINE_BREAK.sub(self.line_break_repl, data)
|
155 |
+
|
156 |
+
if lbh == LineBreakHandling.ESCAPE:
|
157 |
+
return data.replace("\n", "\\n").replace("\r", "\\r")
|
158 |
+
except (TypeError, AttributeError):
|
159 |
+
return data
|
160 |
+
|
161 |
+
raise ValueError(f"unexpected line_break_handling: {lbh}")
|
162 |
+
|
163 |
+
def __escape_formula_injection(self, data: str) -> str:
|
164 |
+
if not self.is_escape_formula_injection:
|
165 |
+
return data
|
166 |
+
|
167 |
+
try:
|
168 |
+
if _RE_FORMULA_PREFIX.search(data):
|
169 |
+
return "'" + data
|
170 |
+
except (TypeError, AttributeError):
|
171 |
+
return data
|
172 |
+
|
173 |
+
return data
|
env-llmeval/lib/python3.10/site-packages/dataproperty/logger/__init__.py
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from ._logger import logger, set_logger
|
2 |
+
|
3 |
+
|
4 |
+
__all__ = (
|
5 |
+
"logger",
|
6 |
+
"set_logger",
|
7 |
+
)
|
env-llmeval/lib/python3.10/site-packages/dataproperty/logger/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (258 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/logger/__pycache__/_logger.cpython-310.pyc
ADDED
Binary file (695 Bytes). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/logger/__pycache__/_null_logger.cpython-310.pyc
ADDED
Binary file (1.92 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/dataproperty/logger/_logger.py
ADDED
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
"""
|
2 |
+
.. codeauthor:: Tsuyoshi Hombashi <[email protected]>
|
3 |
+
"""
|
4 |
+
|
5 |
+
from ._null_logger import NullLogger
|
6 |
+
|
7 |
+
|
8 |
+
MODULE_NAME = "dataproperty"
|
9 |
+
|
10 |
+
try:
|
11 |
+
from loguru import logger
|
12 |
+
|
13 |
+
logger.disable(MODULE_NAME)
|
14 |
+
except ImportError:
|
15 |
+
logger = NullLogger() # type: ignore
|
16 |
+
|
17 |
+
|
18 |
+
def set_logger(is_enable: bool, propagation_depth: int = 1) -> None:
|
19 |
+
if is_enable:
|
20 |
+
logger.enable(MODULE_NAME)
|
21 |
+
else:
|
22 |
+
logger.disable(MODULE_NAME)
|
env-llmeval/lib/python3.10/site-packages/dataproperty/logger/_null_logger.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
class NullLogger:
|
2 |
+
level_name = None
|
3 |
+
|
4 |
+
def remove(self, handler_id=None): # pragma: no cover
|
5 |
+
pass
|
6 |
+
|
7 |
+
def add(self, sink, **kwargs): # pragma: no cover
|
8 |
+
pass
|
9 |
+
|
10 |
+
def disable(self, name): # pragma: no cover
|
11 |
+
pass
|
12 |
+
|
13 |
+
def enable(self, name): # pragma: no cover
|
14 |
+
pass
|
15 |
+
|
16 |
+
def critical(self, __message, *args, **kwargs): # pragma: no cover
|
17 |
+
pass
|
18 |
+
|
19 |
+
def debug(self, __message, *args, **kwargs): # pragma: no cover
|
20 |
+
pass
|
21 |
+
|
22 |
+
def error(self, __message, *args, **kwargs): # pragma: no cover
|
23 |
+
pass
|
24 |
+
|
25 |
+
def exception(self, __message, *args, **kwargs): # pragma: no cover
|
26 |
+
pass
|
27 |
+
|
28 |
+
def info(self, __message, *args, **kwargs): # pragma: no cover
|
29 |
+
pass
|
30 |
+
|
31 |
+
def log(self, __level, __message, *args, **kwargs): # pragma: no cover
|
32 |
+
pass
|
33 |
+
|
34 |
+
def success(self, __message, *args, **kwargs): # pragma: no cover
|
35 |
+
pass
|
36 |
+
|
37 |
+
def trace(self, __message, *args, **kwargs): # pragma: no cover
|
38 |
+
pass
|
39 |
+
|
40 |
+
def warning(self, __message, *args, **kwargs): # pragma: no cover
|
41 |
+
pass
|
env-llmeval/lib/python3.10/site-packages/dataproperty/py.typed
ADDED
File without changes
|
env-llmeval/lib/python3.10/site-packages/dataproperty/typing.py
ADDED
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from datetime import datetime
|
2 |
+
from decimal import Decimal
|
3 |
+
from typing import Any, Callable, Mapping, Optional, Type, Union
|
4 |
+
|
5 |
+
from typepy import (
|
6 |
+
Bool,
|
7 |
+
DateTime,
|
8 |
+
Dictionary,
|
9 |
+
Infinity,
|
10 |
+
Integer,
|
11 |
+
IpAddress,
|
12 |
+
List,
|
13 |
+
Nan,
|
14 |
+
NoneType,
|
15 |
+
NullString,
|
16 |
+
RealNumber,
|
17 |
+
String,
|
18 |
+
Typecode,
|
19 |
+
)
|
20 |
+
from typepy.type import AbstractType
|
21 |
+
|
22 |
+
|
23 |
+
TypeHint = Optional[Type[AbstractType]]
|
24 |
+
TransFunc = Callable[[Any], Any]
|
25 |
+
DateTimeFormatter = Callable[[datetime], str]
|
26 |
+
|
27 |
+
FloatType = Union[Type[Decimal], Type[float]]
|
28 |
+
StrictLevelMap = Mapping[Union[str, Typecode], int]
|
29 |
+
TypeValueMap = Mapping[Typecode, Union[float, Decimal, None]]
|
30 |
+
|
31 |
+
_type_hint_map = {
|
32 |
+
# high frequently used types
|
33 |
+
"int": Integer,
|
34 |
+
"float": RealNumber,
|
35 |
+
"realnumber": RealNumber,
|
36 |
+
"str": String,
|
37 |
+
# low frequently used types
|
38 |
+
"bool": Bool,
|
39 |
+
"datetime": DateTime,
|
40 |
+
"dict": Dictionary,
|
41 |
+
"inf": Infinity,
|
42 |
+
"ip": IpAddress,
|
43 |
+
"list": List,
|
44 |
+
"nan": Nan,
|
45 |
+
"none": NoneType,
|
46 |
+
"nullstr": NullString,
|
47 |
+
}
|
48 |
+
|
49 |
+
|
50 |
+
def normalize_type_hint(type_hint: Union[str, TypeHint]) -> TypeHint:
|
51 |
+
if not type_hint:
|
52 |
+
return None
|
53 |
+
|
54 |
+
if not isinstance(type_hint, str):
|
55 |
+
return type_hint
|
56 |
+
|
57 |
+
type_hint = type_hint.strip().casefold()
|
58 |
+
for key, value in _type_hint_map.items():
|
59 |
+
if type_hint.startswith(key):
|
60 |
+
return value
|
61 |
+
|
62 |
+
raise ValueError(f"unknown typehint: {type_hint}")
|
env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/__init__.cpython-310.pyc
ADDED
Binary file (1.23 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/conftest.cpython-310.pyc
ADDED
Binary file (6.11 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/convert.cpython-310.pyc
ADDED
Binary file (13.2 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/convert_matrix.cpython-310.pyc
ADDED
Binary file (37.5 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/exception.cpython-310.pyc
ADDED
Binary file (4.52 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/lazy_imports.cpython-310.pyc
ADDED
Binary file (5.86 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/networkx/__pycache__/relabel.cpython-310.pyc
ADDED
Binary file (10.2 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/networkx/algorithms/approximation/__pycache__/traveling_salesman.cpython-310.pyc
ADDED
Binary file (46.1 kB). View file
|
|
env-llmeval/lib/python3.10/site-packages/networkx/algorithms/approximation/__pycache__/treewidth.cpython-310.pyc
ADDED
Binary file (6.64 kB). View file
|
|