Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pre-commit.ci] pre-commit autoupdate #27

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ fail_fast: true
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.6
rev: v0.6.8
hooks:
# Run the linter.
- id: ruff
Expand Down
72 changes: 37 additions & 35 deletions example/compare_to_jsonpickle.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@
},
"outputs": [],
"source": [
"import jsonpickle\n",
"import znjson\n",
"import json\n",
"import sys\n",
"import numpy as np"
"\n",
"import jsonpickle\n",
"import numpy as np\n",
"\n",
"import znjson"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"data1 = {\"a\": np.arange(1000), \"b\": [x for x in range(100)]}\n",
Expand All @@ -28,23 +33,23 @@
" \"list\": [1, 2, 3],\n",
" \"nested\": {\"numpy\": np.array([1, 2, 3]), \"list\": [1, 2, 3]},\n",
"}"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "markdown",
"source": [
"The following results are not affected by running one timeit before the other."
],
"metadata": {
"collapsed": false
}
},
"source": [
"The following results are not affected by running one timeit before the other."
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
Expand All @@ -62,14 +67,14 @@
"%timeit json.dumps(data2, cls=znjson.ZnEncoder)\n",
"%timeit json.dumps(data3, cls=znjson.ZnEncoder)\n",
"%timeit json.dumps(data4, cls=znjson.ZnEncoder)"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
Expand All @@ -87,14 +92,14 @@
"%timeit jsonpickle.dumps(data2)\n",
"%timeit jsonpickle.dumps(data3)\n",
"%timeit jsonpickle.dumps(data4)"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -135,14 +140,14 @@
],
"source": [
"print(json.dumps(data4, cls=znjson.ZnEncoder, indent=2))"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
Expand Down Expand Up @@ -268,14 +273,14 @@
],
"source": [
"print(jsonpickle.dumps(data4, indent=2))"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
Expand All @@ -293,14 +298,14 @@
"print(sys.getsizeof(jsonpickle.dumps(data2)))\n",
"print(sys.getsizeof(jsonpickle.dumps(data3)))\n",
"print(sys.getsizeof(jsonpickle.dumps(data4)))"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
Expand All @@ -318,10 +323,7 @@
"print(sys.getsizeof(json.dumps(data2, cls=znjson.ZnEncoder)))\n",
"print(sys.getsizeof(json.dumps(data3, cls=znjson.ZnEncoder)))\n",
"print(sys.getsizeof(json.dumps(data4, cls=znjson.ZnEncoder)))"
],
"metadata": {
"collapsed": false
}
]
}
],
"metadata": {
Expand Down
70 changes: 35 additions & 35 deletions example/datetime_converter.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,36 @@
"cells": [
{
"cell_type": "markdown",
"metadata": {
"collapsed": false
},
"source": [
"# Write a custom Converter\n",
"\n",
"In this Example we will write a custom converter for `datetime` objects."
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import json\n",
"\n",
"from znjson import ConverterBase\n",
"from datetime import datetime\n",
"import znjson"
],
"metadata": {
"collapsed": false
}
"\n",
"import znjson\n",
"from znjson import ConverterBase"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
Expand All @@ -41,14 +44,14 @@
"source": [
"dt = datetime.now()\n",
"print(dt)"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"class DatetimeConverter(ConverterBase):\n",
Expand Down Expand Up @@ -77,34 +80,34 @@
" def decode(self, value: str) -> datetime:\n",
" \"\"\"Create datetime object from str / isoformat\"\"\"\n",
" return datetime.fromisoformat(value)"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "markdown",
"source": [
"To use the new converter we have to add it to `znjson.config.ACTIVE_CONVERTERS` via `znjson.register()`"
],
"metadata": {
"collapsed": false
}
},
"source": [
"To use the new converter we have to add it to `znjson.config.ACTIVE_CONVERTERS` via `znjson.register()`"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"znjson.config.register(DatetimeConverter)"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
Expand All @@ -120,14 +123,14 @@
"source": [
"json_string = json.dumps(dt, cls=znjson.ZnEncoder, indent=4)\n",
"print(json_string)"
],
"metadata": {
"collapsed": false
}
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
Expand All @@ -140,10 +143,7 @@
],
"source": [
"json.loads(json_string, cls=znjson.ZnDecoder)"
],
"metadata": {
"collapsed": false
}
]
}
],
"metadata": {
Expand Down
4 changes: 3 additions & 1 deletion example/example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
},
"outputs": [],
"source": [
"import numpy as np\n",
"import json\n",
"\n",
"import numpy as np\n",
"\n",
"import znjson"
]
},
Expand Down
Loading