feilian 1.2.0__py3-none-any.whl → 1.2.2__py3-none-any.whl

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.

Potentially problematic release.


This version of feilian might be problematic. Click here for more details.

feilian/__init__.py CHANGED
@@ -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
  ]
feilian/_dist_ver.py CHANGED
@@ -1,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
2
  # file generated by setuptools_scm
3
3
  # don't change, don't track in version control
4
- VERSION = (1, 2, 0)
5
- __version__ = '1.2.0'
4
+ VERSION = (1, 2, 2)
5
+ __version__ = '1.2.2'
feilian/process.py CHANGED
@@ -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 read_data(self, filepath: str) -> Any:
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 read_dataframe(filepath, dtype=self.input_dtype)
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)
feilian/utils.py CHANGED
@@ -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
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: feilian
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Summary: General data processing tool.
5
5
  Author-email: darkpeath <darkpeath@gmail.com>
6
6
  Project-URL: Homepage, https://github.com/darkpeath/feilian
@@ -0,0 +1,15 @@
1
+ feilian/__init__.py,sha256=97Rvz2O6LknvCWInAjINH4GeqG4-QPPcep9n-V7KD8k,911
2
+ feilian/_dist_ver.py,sha256=SiCl_bfFc54zvOKPEIeqL_n-ebAmqzSF_PdLPL0lPlU,148
3
+ feilian/arg.py,sha256=n2nIcmC_3rb9A6BOzm9C5z3-T4lnubaGzH2sFhtqwZQ,8402
4
+ feilian/dataframe.py,sha256=DsUiNRuVAe2H6WwqtZ6TGu6WHiLxFEN_Xjl208xvvnw,10698
5
+ feilian/datetime.py,sha256=IONvWhLeGEy9IVe6GWKEW3FhrfRrShyhGP8-RTf9r3c,763
6
+ feilian/io.py,sha256=aYN3QwWcLoRKzhGMNutqdkmxArVcXfeWXzxCB07LcFc,155
7
+ feilian/json.py,sha256=1FkQ6e4JmbccpxhMobXpsGg-f7uVrTtUmu6jDCXCFTQ,1406
8
+ feilian/process.py,sha256=x3HKXakLriAkQ2jgbQ848wdQLYHQ1WBrOfDu_aUUHRA,3012
9
+ feilian/string.py,sha256=G_X3dnR0Oxmi4hXF-6E5jm5M7GPjGoMYrSMyI1dj6Z4,370
10
+ feilian/utils.py,sha256=pzzGEgngidVkYvuNJWY7KWjkdgGRuH5_ENaLS6kxBtk,2648
11
+ feilian/version.py,sha256=oH_DvE7jRCWlCCX9SSadwxwRJXFas_rIisYLBGPYZn4,350
12
+ feilian-1.2.2.dist-info/METADATA,sha256=Pqgl793zKpYn9z0z01MbF84tVra4avtYDP6MIhlgHdw,3723
13
+ feilian-1.2.2.dist-info/WHEEL,sha256=R0nc6qTxuoLk7ShA2_Y-UWkN8ZdfDBG2B6Eqpz2WXbs,91
14
+ feilian-1.2.2.dist-info/top_level.txt,sha256=1Q2-B6KJrcTr7drW_kik35PTVEUJLPP4wVrn0kYKwGw,8
15
+ feilian-1.2.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (70.2.0)
2
+ Generator: setuptools (72.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,15 +0,0 @@
1
- feilian/__init__.py,sha256=G5SKKbmcX8Um6BJ1-nZvMrXhiJnWJbDPMyBjhKkWWAc,881
2
- feilian/_dist_ver.py,sha256=U8gcehSDq7YjTNBnP2g7zZAOcoHw9_WLrgCWQX4QAUY,148
3
- feilian/arg.py,sha256=n2nIcmC_3rb9A6BOzm9C5z3-T4lnubaGzH2sFhtqwZQ,8402
4
- feilian/dataframe.py,sha256=DsUiNRuVAe2H6WwqtZ6TGu6WHiLxFEN_Xjl208xvvnw,10698
5
- feilian/datetime.py,sha256=IONvWhLeGEy9IVe6GWKEW3FhrfRrShyhGP8-RTf9r3c,763
6
- feilian/io.py,sha256=aYN3QwWcLoRKzhGMNutqdkmxArVcXfeWXzxCB07LcFc,155
7
- feilian/json.py,sha256=1FkQ6e4JmbccpxhMobXpsGg-f7uVrTtUmu6jDCXCFTQ,1406
8
- feilian/process.py,sha256=GLkmogYnhkxi6qf-JX-FwIlJAHmTynmgB7zSAggEe1E,2080
9
- feilian/string.py,sha256=G_X3dnR0Oxmi4hXF-6E5jm5M7GPjGoMYrSMyI1dj6Z4,370
10
- feilian/utils.py,sha256=DqBKjpRBbSNipRDau9sYnoCfSDR_Of-xTOCoNxGWUJk,2180
11
- feilian/version.py,sha256=oH_DvE7jRCWlCCX9SSadwxwRJXFas_rIisYLBGPYZn4,350
12
- feilian-1.2.0.dist-info/METADATA,sha256=P-6B1-dzIzMm-4tQU_Ew7azWeMOo9X8pKTUrAF9rWwI,3723
13
- feilian-1.2.0.dist-info/WHEEL,sha256=y4mX-SOX4fYIkonsAGA5N0Oy-8_gI4FXw5HNI1xqvWg,91
14
- feilian-1.2.0.dist-info/top_level.txt,sha256=1Q2-B6KJrcTr7drW_kik35PTVEUJLPP4wVrn0kYKwGw,8
15
- feilian-1.2.0.dist-info/RECORD,,