Skip to content

Commit

Permalink
[pre-commit.ci] pre-commit autoupdate (#27)
Browse files Browse the repository at this point in the history
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.4.6 → v0.7.3](astral-sh/ruff-pre-commit@v0.4.6...v0.7.3)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
pre-commit-ci[bot] authored Nov 15, 2024
1 parent 9ee98e3 commit 00abbf1
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 73 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
exclude: '.git|.tox'
default_stages: [commit]
default_stages: [pre-commit]
fail_fast: true

repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.4.6
rev: v0.7.3
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

0 comments on commit 00abbf1

Please sign in to comment.