-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #91 from ArcanaFramework/text-load-save
added load save implementation for text files
- Loading branch information
Showing
7 changed files
with
51 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import load_save # 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import typing as ty | ||
from fileformats.core import extra_implementation, FileSet | ||
from fileformats.text import Plain # , Csv, Tsv | ||
|
||
# import pandas as pd | ||
|
||
|
||
@extra_implementation(FileSet.load) | ||
def load_text_file(text: Plain, **kwargs: ty.Any) -> Plain: | ||
return text.raw_contents # type: ignore[no-any-return] | ||
|
||
|
||
@extra_implementation(FileSet.save) | ||
def save_text_file(text: Plain, data: ty.Any, **kwargs: ty.Any) -> None: | ||
text.fspath.write_text(data) | ||
|
||
|
||
# @extra_implementation(FileSet.load) | ||
# def load_csv_file(csv_file: Csv, **kwargs: ty.Any) -> pd.DataFrame: | ||
# return pd.read_csv(csv_file.fspath, **kwargs) | ||
|
||
|
||
# @extra_implementation(FileSet.save) | ||
# def save_csv_file(csv_file: Csv, data: pd.DataFrame, **kwargs: ty.Any) -> None: | ||
# data.to_csv(csv_file.fspath, index=False, **kwargs) | ||
|
||
|
||
# @extra_implementation(FileSet.load) | ||
# def load_tsv_file(tsv_file: Tsv, **kwargs: ty.Any) -> pd.DataFrame: | ||
# return pd.read_csv(tsv_file.fspath, sep="\t", **kwargs) | ||
|
||
|
||
# @extra_implementation(FileSet.save) | ||
# def save_tsv_file(tsv_file: Tsv, data: pd.DataFrame, **kwargs: ty.Any) -> None: | ||
# data.to_csv(tsv_file.fspath, sep="\t", index=False, **kwargs) |
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 |
---|---|---|
@@ -1,21 +1,21 @@ | ||
from fileformats.generic import UnicodeFile | ||
from fileformats.text import Plain | ||
|
||
|
||
class Foo(UnicodeFile): | ||
class Foo(Plain): | ||
|
||
ext = ".foo" | ||
|
||
|
||
class Bar(UnicodeFile): | ||
class Bar(Plain): | ||
|
||
ext = ".bar" | ||
|
||
|
||
class Baz(UnicodeFile): | ||
class Baz(Plain): | ||
|
||
ext = ".baz" | ||
|
||
|
||
class Qux(UnicodeFile): | ||
class Qux(Plain): | ||
|
||
ext = ".qux" |
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