-
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.
Create a plugin for additional filetypes (#40)
* plugin for additional file types * remove parquet and feather from xiplot * add plugin to publish workflow * Apply suggestions from code review Co-authored-by: Juniper Tyree <50025784+juntyr@users.noreply.github.com> * Add footnote about plugin to data_files.md * Add installation instructions to plugin README.md * unit tests for filetypes plugin * Do not force install test_plugin during testing Add it to requirements-dev.txt instead. And issue a warning during testing if not installed. --------- Co-authored-by: Juniper Tyree <50025784+juntyr@users.noreply.github.com>
- Loading branch information
Showing
16 changed files
with
254 additions
and
169 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
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 |
---|---|---|
|
@@ -135,3 +135,4 @@ Untitled.ipynb | |
data/ | ||
uploads/ | ||
node_modules | ||
plugins/*.whl |
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,12 @@ | ||
# [χiplot](https://github.com/edahelsinki/xiplot) plugin for additional file types | ||
|
||
This plugin adds support for additional file types (beside `csv` and `json`) to [χiplot](https://github.com/edahelsinki/xiplot). | ||
Currently, this plugin adds support for `feather` and `parquet`. | ||
Note that in the [WASM version](https://edahelsinki.fi/xiplot) only support for `parquet` is added. | ||
|
||
## Installation | ||
|
||
In non-WASM [χiplot](https://github.com/edahelsinki/xiplot) this plugin should be automatically installed. | ||
Otherwise you can use `pip install xiplot_filetypes` in the same Python environment. | ||
|
||
In the [WASM version](https://edahelsinki.fi/xiplot) you can install the plugin by going to the "Plugin" tab and selecting `xiplot_filetypes`. |
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 @@ | ||
|
||
[project] | ||
name = "xiplot_filetypes" | ||
version = "1.0" | ||
authors = [{ name = "Anton Björklund", email = "anton.bjorklund@helsinki.fi" }] | ||
description = "Xiplot plugin for additional file types" | ||
license = { file = "../LICENCE-MIT" } | ||
readme = "README.md" | ||
|
||
requires-python = ">=3.7" | ||
classifiers = [ | ||
"Programming Language :: Python :: 3", | ||
"License :: OSI Approved :: MIT License", | ||
"Operating System :: OS Independent", | ||
] | ||
dependencies = [ | ||
"pandas", | ||
"pyarrow >= 11.0.0; platform_system!='Emscripten'", | ||
"fastparquet; platform_system=='Emscripten'", | ||
] | ||
|
||
[build-system] | ||
requires = ["setuptools>=42", "wheel"] | ||
build-backend = "setuptools.build_meta" | ||
|
||
[tool.setuptools] | ||
packages = ["xiplot_filetypes"] | ||
|
||
[project.urls] | ||
homepage = "https://github.com/edahelsinki/xiplot" | ||
repository = "https://github.com/edahelsinki/xiplot.git" | ||
|
||
[project.entry-points."xiplot.plugin.read"] | ||
parquet-read = "xiplot_filetypes:read_parquet" | ||
feather-read = "xiplot_filetypes:read_feather" | ||
|
||
[project.entry-points."xiplot.plugin.write"] | ||
parquet-write = "xiplot_filetypes:write_parquet" | ||
feather-write = "xiplot_filetypes:write_feather" |
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,32 @@ | ||
from io import BytesIO | ||
|
||
import pandas as pd | ||
|
||
|
||
def read_parquet(): | ||
return pd.read_parquet, ".parquet" | ||
|
||
|
||
def write_parquet(): | ||
return pd.DataFrame.to_parquet, ".parquet", "application/octet-stream" | ||
|
||
|
||
def read_feather(): | ||
try: | ||
df = pd.DataFrame() | ||
ft = BytesIO() | ||
df.reset_index().to_feather(ft) | ||
pd.read_feather(ft) | ||
except ImportError: | ||
return | ||
|
||
return pd.read_feather, ".feather" | ||
|
||
|
||
def write_feather(): | ||
try: | ||
pd.DataFrame().reset_index().to_feather(BytesIO()) | ||
except ImportError: | ||
return | ||
|
||
return pd.DataFrame.to_feather, ".feather", "application/octet-stream" |
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -5,3 +5,4 @@ isort | |
pyproject-flake8 | ||
webdriver-manager | ||
selenium | ||
./test_plugin |
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,40 @@ | ||
from io import BytesIO | ||
|
||
import pandas as pd | ||
|
||
try: | ||
from xiplot_filetypes import ( | ||
read_feather, | ||
read_parquet, | ||
write_feather, | ||
write_parquet, | ||
) | ||
except ImportError: | ||
import sys | ||
from pathlib import Path | ||
|
||
sys.path.insert( | ||
0, str(Path(__file__).parent.parent / "plugin_xiplot_filetypes") | ||
) | ||
from xiplot_filetypes import ( | ||
read_feather, | ||
read_parquet, | ||
write_feather, | ||
write_parquet, | ||
) | ||
|
||
|
||
def test_feather(): | ||
df = pd.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}) | ||
io = BytesIO() | ||
write_feather()[0](df, io) | ||
df2 = read_feather()[0](io) | ||
assert df.equals(df2) | ||
|
||
|
||
def test_parquet(): | ||
df = pd.DataFrame({"a": [1, 2, 3], "b": ["a", "b", "c"]}) | ||
io = BytesIO() | ||
write_parquet()[0](df, io) | ||
df2 = read_parquet()[0](io) | ||
assert df.equals(df2) |
Oops, something went wrong.