-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* general updates * add plotly converter * bump version * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * update tests, use contextlib * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * format --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
9bf5e83
commit 2c61ea9
Showing
12 changed files
with
415 additions
and
257 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,22 @@ | ||
name: Release | ||
on: | ||
release: | ||
types: | ||
- created | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.12" | ||
- name: Install Poetry | ||
uses: snok/install-poetry@v1 | ||
- name: Publish | ||
env: | ||
PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }} | ||
run: | | ||
poetry config pypi-token.pypi $PYPI_TOKEN | ||
poetry publish --build |
Large diffs are not rendered by default.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "znjson" | ||
version = "0.2.3" | ||
version = "0.2.4" | ||
description = "A Python Package to Encode/Decode some common file formats to json" | ||
authors = ["zincwarecode <[email protected]>"] | ||
license = "Apache-2.0" | ||
|
@@ -21,10 +21,11 @@ pytest = "^7" | |
ase = "^3.22.1" | ||
ruff = "^0.4.6" | ||
coverage = "^7" | ||
plotly = "^5.23.0" | ||
|
||
[build-system] | ||
requires = ["poetry-core>=1.0.0"] | ||
build-backend = "poetry.core.masonry.api" | ||
|
||
[tool.ruff.lint] | ||
select = ["I"] | ||
select = ["I", "E", "W", "C", "F"] |
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 @@ | ||
import plotly.express as px | ||
import pytest | ||
from plotly.graph_objs import Figure | ||
|
||
|
||
@pytest.fixture | ||
def plotly_figure(): | ||
df = px.data.iris() | ||
return px.scatter(df, x="sepal_width", y="sepal_length") | ||
|
||
|
||
def test_encode_plotly(plotly_figure): | ||
import znjson | ||
|
||
data = znjson.dumps(plotly_figure) | ||
assert data.startswith('{"_type": "plotly.graph_objs.Figure"') | ||
|
||
fig = znjson.loads(data) | ||
assert fig == plotly_figure | ||
assert isinstance(fig, Figure) | ||
|
||
assert fig.layout.xaxis.title.text == "sepal_width" | ||
assert fig.layout.yaxis.title.text == "sepal_length" | ||
|
||
|
||
def test_encode_list_plotly(plotly_figure): | ||
import znjson | ||
|
||
data = znjson.dumps([plotly_figure, plotly_figure]) | ||
assert data.startswith('[{"_type": "plotly.graph_objs.Figure"') | ||
|
||
fig = znjson.loads(data) | ||
assert fig == [plotly_figure, plotly_figure] | ||
assert isinstance(fig[0], Figure) | ||
assert isinstance(fig[1], Figure) | ||
|
||
assert fig[0].layout.xaxis.title.text == "sepal_width" | ||
assert fig[0].layout.yaxis.title.text == "sepal_length" | ||
assert fig[1].layout.xaxis.title.text == "sepal_width" | ||
assert fig[1].layout.yaxis.title.text == "sepal_length" |
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 |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
def test_version(): | ||
assert znjson.__version__ == "0.2.3" | ||
assert znjson.__version__ == "0.2.4" |
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,16 @@ | ||
import plotly.graph_objs | ||
import plotly.io as pio | ||
|
||
from znjson.base import ConverterBase | ||
|
||
|
||
class PlotlyConverter(ConverterBase): | ||
instance = plotly.graph_objs.Figure | ||
representation = "plotly.graph_objs.Figure" | ||
level = 10 | ||
|
||
def encode(self, obj): | ||
return obj.to_json() | ||
|
||
def decode(self, value): | ||
return pio.from_json(value) |
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