feilian 1.2.1__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/_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, 1)
5
- __version__ = '1.2.1'
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)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: feilian
3
- Version: 1.2.1
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
@@ -1,15 +1,15 @@
1
1
  feilian/__init__.py,sha256=97Rvz2O6LknvCWInAjINH4GeqG4-QPPcep9n-V7KD8k,911
2
- feilian/_dist_ver.py,sha256=quKRw8l2uSmWwO0SXPBC-2dE29rT4esN_0UQ9PP_-bk,148
2
+ feilian/_dist_ver.py,sha256=SiCl_bfFc54zvOKPEIeqL_n-ebAmqzSF_PdLPL0lPlU,148
3
3
  feilian/arg.py,sha256=n2nIcmC_3rb9A6BOzm9C5z3-T4lnubaGzH2sFhtqwZQ,8402
4
4
  feilian/dataframe.py,sha256=DsUiNRuVAe2H6WwqtZ6TGu6WHiLxFEN_Xjl208xvvnw,10698
5
5
  feilian/datetime.py,sha256=IONvWhLeGEy9IVe6GWKEW3FhrfRrShyhGP8-RTf9r3c,763
6
6
  feilian/io.py,sha256=aYN3QwWcLoRKzhGMNutqdkmxArVcXfeWXzxCB07LcFc,155
7
7
  feilian/json.py,sha256=1FkQ6e4JmbccpxhMobXpsGg-f7uVrTtUmu6jDCXCFTQ,1406
8
- feilian/process.py,sha256=GLkmogYnhkxi6qf-JX-FwIlJAHmTynmgB7zSAggEe1E,2080
8
+ feilian/process.py,sha256=x3HKXakLriAkQ2jgbQ848wdQLYHQ1WBrOfDu_aUUHRA,3012
9
9
  feilian/string.py,sha256=G_X3dnR0Oxmi4hXF-6E5jm5M7GPjGoMYrSMyI1dj6Z4,370
10
10
  feilian/utils.py,sha256=pzzGEgngidVkYvuNJWY7KWjkdgGRuH5_ENaLS6kxBtk,2648
11
11
  feilian/version.py,sha256=oH_DvE7jRCWlCCX9SSadwxwRJXFas_rIisYLBGPYZn4,350
12
- feilian-1.2.1.dist-info/METADATA,sha256=v0pXur6UQVS3a6U8irka8ucSq9M-wyQ4bgshSv6IBJo,3723
13
- feilian-1.2.1.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
14
- feilian-1.2.1.dist-info/top_level.txt,sha256=1Q2-B6KJrcTr7drW_kik35PTVEUJLPP4wVrn0kYKwGw,8
15
- feilian-1.2.1.dist-info/RECORD,,
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 (71.1.0)
2
+ Generator: setuptools (72.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5