-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#131 related update: sync with AREkit updates
- Loading branch information
Showing
11 changed files
with
86 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class BaseReader(object): | ||
|
||
def extension(self): | ||
raise NotImplementedError() | ||
|
||
def read(self, target): | ||
raise NotImplementedError() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import importlib | ||
|
||
from arekit.contrib.utils.data.storages.pandas_based import PandasBasedRowsStorage | ||
|
||
from arelight.readers.base import BaseReader | ||
|
||
|
||
class PandasCsvReader(BaseReader): | ||
""" Represents a CSV-based reader, implmented via pandas API. | ||
""" | ||
|
||
def __init__(self, sep='\t', header='infer', compression='infer', encoding='utf-8', col_types=None, | ||
custom_extension=None): | ||
self.__sep = sep | ||
self.__compression = compression | ||
self.__encoding = encoding | ||
self.__header = header | ||
self.__custom_extension = custom_extension | ||
|
||
# Special assignation of types for certain columns. | ||
self.__col_types = col_types | ||
if self.__col_types is None: | ||
self.__col_types = dict() | ||
|
||
def extension(self): | ||
return ".tsv.gz" if self.__custom_extension is None else self.__custom_extension | ||
|
||
def __from_csv(self, filepath): | ||
pd = importlib.import_module("pandas") | ||
return pd.read_csv(filepath, | ||
sep=self.__sep, | ||
encoding=self.__encoding, | ||
compression=self.__compression, | ||
dtype=self.__col_types, | ||
header=self.__header) | ||
|
||
def read(self, target): | ||
df = self.__from_csv(filepath=target) | ||
return PandasBasedRowsStorage(df) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from arekit.contrib.utils.data.storages.jsonl_based import JsonlBasedRowsStorage | ||
|
||
from arelight.readers.base import BaseReader | ||
|
||
|
||
class JsonlReader(BaseReader): | ||
|
||
def extension(self): | ||
return ".jsonl" | ||
|
||
def read(self, target): | ||
rows = [] | ||
with open(target, "r") as f: | ||
for line in f.readlines(): | ||
rows.append(line) | ||
return JsonlBasedRowsStorage(rows) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from arekit.contrib.utils.data.storages.sqlite_based import SQliteBasedRowsStorage | ||
|
||
from arelight.readers.base import BaseReader | ||
|
||
|
||
class SQliteReader(BaseReader): | ||
|
||
def __init__(self, table_name): | ||
self.__table_name = table_name | ||
|
||
def extension(self): | ||
return ".sqlite" | ||
|
||
def read(self, target): | ||
return SQliteBasedRowsStorage(path=target, table_name=self.__table_name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters