feilian 1.2.0__tar.gz → 1.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {feilian-1.2.0 → feilian-1.2.2}/PKG-INFO +1 -1
- {feilian-1.2.0 → feilian-1.2.2}/feilian/__init__.py +2 -2
- {feilian-1.2.0 → feilian-1.2.2}/feilian/_dist_ver.py +2 -2
- {feilian-1.2.0 → feilian-1.2.2}/feilian/process.py +30 -7
- {feilian-1.2.0 → feilian-1.2.2}/feilian/utils.py +19 -1
- {feilian-1.2.0 → feilian-1.2.2}/feilian.egg-info/PKG-INFO +1 -1
- {feilian-1.2.0 → feilian-1.2.2}/README.md +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/build.sh +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian/arg.py +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian/dataframe.py +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian/datetime.py +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian/io.py +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian/json.py +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian/string.py +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian/version.py +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian.egg-info/SOURCES.txt +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian.egg-info/dependency_links.txt +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/feilian.egg-info/requires.txt +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/pyproject.toml +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/requirements.txt +0 -0
- {feilian-1.2.0 → feilian-1.2.2}/setup.cfg +0 -0
|
@@ -7,7 +7,7 @@ from .datetime import format_time, format_date
|
|
|
7
7
|
from .arg import ArgValueParser
|
|
8
8
|
from .json import read_json, save_json
|
|
9
9
|
from .process import DataframeProcessor
|
|
10
|
-
from .utils import flatten_dict
|
|
10
|
+
from .utils import flatten_dict, flatten_list
|
|
11
11
|
from .version import __version__
|
|
12
12
|
|
|
13
13
|
__all__ = [
|
|
@@ -18,6 +18,6 @@ __all__ = [
|
|
|
18
18
|
'ArgValueParser',
|
|
19
19
|
'read_json', 'save_json',
|
|
20
20
|
'DataframeProcessor',
|
|
21
|
-
'flatten_dict',
|
|
21
|
+
'flatten_dict', 'flatten_list',
|
|
22
22
|
'__version__',
|
|
23
23
|
]
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import abc
|
|
2
2
|
import tqdm
|
|
3
3
|
import pandas as pd
|
|
4
|
-
from typing import Any, Dict, Hashable
|
|
4
|
+
from typing import Any, Dict, Hashable, List, Tuple, Union, Iterable
|
|
5
5
|
from .dataframe import read_dataframe, save_dataframe
|
|
6
6
|
|
|
7
7
|
class BaseProcessor(abc.ABC):
|
|
@@ -10,10 +10,25 @@ class BaseProcessor(abc.ABC):
|
|
|
10
10
|
"""
|
|
11
11
|
|
|
12
12
|
@abc.abstractmethod
|
|
13
|
-
def
|
|
13
|
+
def read_single_file(self, filepath: str) -> Any:
|
|
14
|
+
"""
|
|
15
|
+
Actual method to read data from a single file.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
def merge_input_data(self, data: Iterable[Any]) -> Any:
|
|
19
|
+
"""
|
|
20
|
+
Merge data read from multi files.
|
|
21
|
+
"""
|
|
22
|
+
return data
|
|
23
|
+
|
|
24
|
+
def read_data(self, filepath: Union[str, List[str], Tuple[str]]) -> Any:
|
|
14
25
|
"""
|
|
15
26
|
Read data from input file.
|
|
16
27
|
"""
|
|
28
|
+
if isinstance(filepath, (list, tuple)):
|
|
29
|
+
return self.merge_input_data(self.read_single_file(x) for x in filepath)
|
|
30
|
+
else:
|
|
31
|
+
return self.read_single_file(filepath)
|
|
17
32
|
|
|
18
33
|
@abc.abstractmethod
|
|
19
34
|
def save_result(self, filepath: str, result: Any):
|
|
@@ -27,7 +42,7 @@ class BaseProcessor(abc.ABC):
|
|
|
27
42
|
Process data and return result.
|
|
28
43
|
"""
|
|
29
44
|
|
|
30
|
-
def run(self, input_path: str, output_path: str = None, write_output=True):
|
|
45
|
+
def run(self, input_path: Union[str, List[str], Tuple[str]], output_path: str = None, write_output=True):
|
|
31
46
|
"""
|
|
32
47
|
Read from a file, and save result to another file.
|
|
33
48
|
:param input_path: file with the data
|
|
@@ -40,12 +55,20 @@ class BaseProcessor(abc.ABC):
|
|
|
40
55
|
self.save_result(output_path or input_path, result)
|
|
41
56
|
|
|
42
57
|
class DataframeProcessor(BaseProcessor, abc.ABC):
|
|
43
|
-
def __init__(self, input_dtype=None, progress=False):
|
|
44
|
-
self.input_dtype = input_dtype
|
|
58
|
+
def __init__(self, input_dtype=None, progress=False, read_args: Dict[str, Any] = None):
|
|
45
59
|
self.progress = progress
|
|
60
|
+
self.read_args = read_args or {}
|
|
61
|
+
if input_dtype is not None:
|
|
62
|
+
self.read_args['dtype'] = input_dtype
|
|
63
|
+
|
|
64
|
+
def read_single_file(self, filepath: str) -> pd.DataFrame:
|
|
65
|
+
return read_dataframe(filepath, **self.read_args)
|
|
66
|
+
|
|
67
|
+
def merge_input_data(self, data: Iterable[pd.DataFrame]) -> pd.DataFrame:
|
|
68
|
+
return pd.concat(data)
|
|
46
69
|
|
|
47
|
-
def read_data(self, filepath: str) -> pd.DataFrame:
|
|
48
|
-
return
|
|
70
|
+
def read_data(self, filepath: Union[str, List[str], Tuple[str]]) -> pd.DataFrame:
|
|
71
|
+
return super().read_data(filepath)
|
|
49
72
|
|
|
50
73
|
def save_result(self, filepath: str, result: pd.DataFrame):
|
|
51
74
|
save_dataframe(filepath, result)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env python
|
|
2
2
|
# coding: utf-8
|
|
3
3
|
|
|
4
|
-
from typing import Dict, Any, Union, Collection
|
|
4
|
+
from typing import Dict, Any, Union, Collection, List
|
|
5
5
|
|
|
6
6
|
def flatten_dict(data: Dict[str, Any], prefix="", joiner=".",
|
|
7
7
|
exclude: Union[None, str, Collection[str]] = None,
|
|
@@ -62,3 +62,21 @@ def flatten_dict(data: Dict[str, Any], prefix="", joiner=".",
|
|
|
62
62
|
|
|
63
63
|
return res
|
|
64
64
|
|
|
65
|
+
|
|
66
|
+
def flatten_list(data: List[Any], res: List[Any] = None) -> List[Any]:
|
|
67
|
+
"""
|
|
68
|
+
Flatten nested list as a flat on layer list.
|
|
69
|
+
:param data: a nested list
|
|
70
|
+
:param res: the result flat layer list, create a new one if not given.
|
|
71
|
+
"""
|
|
72
|
+
if res is None:
|
|
73
|
+
res = []
|
|
74
|
+
|
|
75
|
+
for x in data:
|
|
76
|
+
if isinstance(x, list):
|
|
77
|
+
# flatten recursively
|
|
78
|
+
flatten_list(x, res)
|
|
79
|
+
else:
|
|
80
|
+
res.append(x)
|
|
81
|
+
|
|
82
|
+
return res
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|