-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* 🔨 improve reader interface * 🔨 shrink reader code * This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst * 🔥 remove redundant functionalitoes, never will use. what's the point * 📚 updated doc string and the tutorial * 🔨 update import statements * 🔬 more test coverage * This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst * 💚 fix unit test failure * 📚 update reader plugin example * 💄 update coding style * 📚 fix index rst file * This is an auto-commit, updating project meta data, such as changelog.rst, contributors.rst Co-authored-by: chfw <chfw@users.noreply.github.com>
- Loading branch information
Showing
33 changed files
with
337 additions
and
76 deletions.
There are no files selected for viewing
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
|
||
|
||
5 contributors | ||
================================================================================ | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import yaml | ||
from pyexcel_io import get_data | ||
from pyexcel_io.sheet import NamedContent | ||
from pyexcel_io.plugins import IOPluginInfoChainV2 | ||
from pyexcel_io.plugin_api import ISheet, IReader | ||
|
||
|
||
class YourSingleSheet(ISheet): | ||
def __init__(self, your_native_sheet): | ||
self.two_dimensional_array = your_native_sheet | ||
|
||
def row_iterator(self): | ||
yield from self.two_dimensional_array | ||
|
||
def column_iterator(self, row): | ||
yield from row | ||
|
||
|
||
class YourReader(IReader): | ||
def __init__(self, file_name, file_type, **keywords): | ||
self.file_handle = open(file_name, "r") | ||
self.native_book = yaml.load(self.file_handle) | ||
self.content_array = [ | ||
NamedContent(key, values) | ||
for key, values in self.native_book.items() | ||
] | ||
|
||
def read_sheet(self, sheet_index): | ||
two_dimensional_array = self.content_array[sheet_index].payload | ||
return YourSingleSheet(two_dimensional_array) | ||
|
||
def close(self): | ||
self.file_handle.close() | ||
|
||
|
||
IOPluginInfoChainV2(__name__).add_a_reader( | ||
relative_plugin_class_path="YourReader", | ||
locations=["file"], | ||
file_types=["yaml"], | ||
stream_type="text", | ||
) | ||
|
||
if __name__ == "__main__": | ||
data = get_data("test.yaml") | ||
print(data) |
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,11 @@ | ||
sheet 1: | ||
- - 1 | ||
- 2 | ||
- 3 | ||
- - 2 | ||
- 3 | ||
- 4 | ||
sheet 2: | ||
- - A | ||
- B | ||
- C |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,8 +51,4 @@ def is_string(atype): | |
if atype == str: | ||
return True | ||
|
||
elif PY2: | ||
if atype == unicode: | ||
return True | ||
|
||
return False |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from .abstract_sheet import ISheet, ISheetWriter # noqa: F401 | ||
from .abstract_reader import IReader # noqa: F401 | ||
from .abstract_writer import IWriter # noqa: F401 |
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 |
---|---|---|
@@ -1,9 +1,18 @@ | ||
from pyexcel_io._compact import OrderedDict | ||
from .abstract_sheet import ISheet | ||
|
||
|
||
class IReader(object): | ||
def read_all(self): | ||
result = OrderedDict() | ||
for index, sheet in enumerate(self.content_array): | ||
result.update({sheet.name: self.read_sheet(index).to_array()}) | ||
return result | ||
""" | ||
content_array should be a list of NamedContent | ||
where: name is the sheet name, | ||
payload is the native sheet. | ||
""" | ||
|
||
def read_sheet(self, sheet_index) -> ISheet: | ||
raise NotImplementedError("") | ||
|
||
def sheet_names(self): | ||
return [content.name for content in self.content_array] | ||
|
||
def __len__(self): | ||
return len(self.content_array) |
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
Oops, something went wrong.