From 6ac79fad36453e0ac1079cc7f07ab27410fcd2c6 Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Mon, 25 Dec 2023 11:18:57 +0400 Subject: [PATCH] 39 experiment with jinja2 (#40) * jinja2 experiment * testing dataclass * testing dataclass * moving jinja2 up * remove outdated test --- Makefile | 1 - README.md | 2 +- cvx/bson/io.py | 16 +++++- cvx/data/__init__.py | 13 +++++ cvx/data/data_api.py.jinja2 | 31 ++++++++++++ cvx/data/render.py | 31 ++++++++++++ experiment/demo1.py | 48 ++++++++++++++++++ experiment/fill.py | 16 ++++++ experiment/xxx.bson | Bin 0 -> 6846 bytes poetry.lock | 94 ++++++++++++++++++++++++++++++++++-- pyproject.toml | 2 +- tests/test_bson.py | 13 ----- 12 files changed, 246 insertions(+), 21 deletions(-) create mode 100644 cvx/data/__init__.py create mode 100644 cvx/data/data_api.py.jinja2 create mode 100644 cvx/data/render.py create mode 100644 experiment/demo1.py create mode 100644 experiment/fill.py create mode 100644 experiment/xxx.bson diff --git a/Makefile b/Makefile index 04aacf87..6bbf8f06 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,6 @@ coverage: install ## test and coverage xdg-open htmlcov/index.html 2> /dev/null; \ fi - .PHONY: help help: ## Display this help screen @echo -e "\033[1mAvailable commands:\033[0m" diff --git a/README.md b/README.md index c195bf8e..fec22a89 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ programming languages. However, they are not very efficient. Here we use their binary counterpart, bson files. Bson files are much more efficient but somewhat lack the flexibility of json files. Here we rely on the [bson](https://pypi.org/project/bson/) package to read and write bson files. We are interested in parsing dictionaries -of numpy arrays, pandas and polars dataframe as fast as possible. +of numpy arrays, pandas and polars dataframes as fast as possible. There might be faster ways to achieve this goal and we are open to suggestions and pull requests. diff --git a/cvx/bson/io.py b/cvx/bson/io.py index 5f9b6cb7..d998b59b 100644 --- a/cvx/bson/io.py +++ b/cvx/bson/io.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +import json from io import BytesIO from typing import Any, Union @@ -43,7 +44,17 @@ def encode(data: Union[np.ndarray, pd.DataFrame, pl.DataFrame]) -> Any: result.seek(0) return result.read() - raise TypeError(f"Invalid Datatype {type(data)}") + converted = json.dumps(data).encode(encoding="utf-8") + arr = bytes("cvx", "utf-8") + return arr + converted + + # return bytes. + # print(encoded_tuple) + # decoded_color = encoded_color.decode() + # orginal_form = json.load(decoded_color) + # return + + # raise TypeError(f"Invalid Datatype {type(data)}") def decode(data: bytes) -> Union[np.ndarray, pd.DataFrame, pl.DataFrame]: @@ -67,5 +78,8 @@ def decode(data: bytes) -> Union[np.ndarray, pd.DataFrame, pl.DataFrame]: if header == b"PAR": return pd.read_parquet(BytesIO(data)) + if header == b"cvx": + return json.loads(data[3:].decode()) + # if still here we try numpy return pa.ipc.read_tensor(data).to_numpy() diff --git a/cvx/data/__init__.py b/cvx/data/__init__.py new file mode 100644 index 00000000..6d037dc0 --- /dev/null +++ b/cvx/data/__init__.py @@ -0,0 +1,13 @@ +# Copyright 2023 Stanford University Convex Optimization Group +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. diff --git a/cvx/data/data_api.py.jinja2 b/cvx/data/data_api.py.jinja2 new file mode 100644 index 00000000..115fc589 --- /dev/null +++ b/cvx/data/data_api.py.jinja2 @@ -0,0 +1,31 @@ +# Copyright 2023 Stanford University Convex Optimization Group +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""DataAPI for {{ strategy }}""" +# This class has been generated by cvxbson +from dataclasses import dataclass, field +from typing import Dict + +import polars as pl + +from cvx.bson.dataclass import Data + +@dataclass(frozen=True) +class DataAPI(Data): + # List of tables + {% for name in names.keys() %} + {{ name }}: pl.DataFrame + {% endfor %} + + # Mapping from short name to full name + tables: Dict[str, str] = field(default_factory=lambda: {{ names }}) diff --git a/cvx/data/render.py b/cvx/data/render.py new file mode 100644 index 00000000..838c7c6f --- /dev/null +++ b/cvx/data/render.py @@ -0,0 +1,31 @@ +# Copyright 2023 Stanford University Convex Optimization Group +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +"""Create a dataclass from a template""" +from pathlib import Path + +from jinja2 import Template + + +def render(names, strategy): + # gain this dictionary through reflection + # every table has a shortname, e.g. prices and a longer descriptive name + # we use the shortname to name the variable refering to the code + # names = {"A": "AAA", "B": "BBB", "C": "CCC"} + path = Path(__file__).parent + + # open the template + template = Template(open(path / "data_api.py.jinja2", encoding="utf-8").read()) + + # we copy & paste the new class into a new file + return template.render(names=names, strategy=strategy) diff --git a/experiment/demo1.py b/experiment/demo1.py new file mode 100644 index 00000000..b76bddab --- /dev/null +++ b/experiment/demo1.py @@ -0,0 +1,48 @@ +from dataclasses import dataclass, field +from typing import Dict + +import polars as pl + +from cvx.bson.dataclass import Data + + +@dataclass(frozen=True) +class DataAPI(Data): + # List of tables expected + A: pl.DataFrame + B: pl.DataFrame + C: pl.DataFrame + + # Define a mutable value for the mapping from short name to full name + tables: Dict[str, str] = field( + default_factory=lambda: {"A": "AAA", "B": "BBB", "C": "CCC"} + ) + + +if __name__ == "__main__": + # We add this as a little demo + import numpy as np + + data = DataAPI( + A=pl.DataFrame(np.random.rand(10, 5)), + B=pl.DataFrame(np.random.rand(20, 3)), + C=pl.DataFrame(np.random.rand(50, 5)), + ) + + # We can access the tables + print(data.tables) + print(data.A) + print(data.B) + print(data.C) + + # convert all data into one bson file + print(data.to_bson("xxx.bson")) + + data2 = DataAPI.from_bson("xxx.bson") + print(data2) + + def strategy(api: DataAPI): + # the strategy has no idea how the data is stored + print(api.A) + + strategy(data2) diff --git a/experiment/fill.py b/experiment/fill.py new file mode 100644 index 00000000..a132f573 --- /dev/null +++ b/experiment/fill.py @@ -0,0 +1,16 @@ +from cvx.data.render import render + +if __name__ == "__main__": + # gain this dictionary through reflection + # every table has a shortname, e.g. prices and a longer descriptive name + # we use the shortname to name the variable refering to the code + names = {"A": "AAA", "B": "BBB", "C": "CCC"} + strategy = "s239" + + print(render(names, strategy)) + + # open the template + # template = Template(open("creator.py.jinja2").read()) + + # we copy & paste the new class into a new file + # print(template.render(names=names, strategy="s239")) diff --git a/experiment/xxx.bson b/experiment/xxx.bson new file mode 100644 index 0000000000000000000000000000000000000000..f1051c453406b4553eb3e4fe48b1164552e42bca GIT binary patch literal 6846 zcmeHMdpyV2LVhlyZcvL2&@~Av|7(G6zP*h4Dg^@yH zN*;wgkH_(joIK7sj>AEkq+9Oq$eHPOKlk==r$6rJerBD|K6|hAUBA75d#}CL+WVXw zIf4+-B}}Fe1fjcao5>Gq1Tjid#3X{?CuM_VTbiu-2~t3a5Tb+-`OQxZlX5XqB1C?; zr~vsrpHyif>oBrx8IuwOo77V!+lpk7AY_}_67;O?={-}TS(-0|X0oc7q{U5ozXOU-BoW$2sV?x7Pn{PFOKiH{|wXYm~GGZIws5T&5EMm?kFE#=y%#2KWqQLEQBD8pB z7vswUT7SQc>*dZaQo3 zLl{Qo-EY6vhT4A5MYN23Y*}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i{07RC#zC8&@{k2ft}@(VI;iXMg-)3H_K z$$}j6cwd`6ZSbu_4sHOM3@#l#Z151Z zz4DK&^z)Hmm8)Ljn++Q&4xe;j9}4A^x~EgRkg0a4+IbT>&y?9$8*M8Q!gpi&VrLE< zg=L-17Pe!n$JA=cBh?VrE}K3@za8JN&I~Mk!oqwT<-T&i9;A0W`dKS55TmFpHub-QuT7G%RPSZ#j_C1-4tSySft-Ei2Pwo||yc{CcyB%Z>(|JaA`oL?R2Gr!*;z zbv^K_CWK^a`j8c*cwAt7-fObJWR_ARh3TQ)>XP4C=MQYu#y-rm~o;8v& zbtMCqXiW3ZA@`@t!A2ji3iwO6=s>a$_7y@UO9N^k>8J9(wzUCv?yD@-GZ;{eG^UjL zUI#_-D8qCq2bxP&v@e}1M|G&->f31@C|!2zm>s#!E3Ul?|H<(sj>KKt+xh+_k`nUG z_QuhX_TAl%oAzDkx9)Vytxbi&U{CS0&}X2zCzKk*rK3{KO*@j(gXt1MYX?aGzHTo& zzr2)#iwZ?o>I2*0`i<<$1iLy27As$nk0nh$;+vqUxT=3ufP7y_>ce0eDz<; x4(zgbb@U__ac$yo$osI8u9B9blCG|=2.7)"] + [[package]] name = "loguru" version = "0.7.2" @@ -187,6 +204,75 @@ win32-setctime = {version = ">=1.0.0", markers = "sys_platform == \"win32\""} [package.extras] dev = ["Sphinx (==7.2.5)", "colorama (==0.4.5)", "colorama (==0.4.6)", "exceptiongroup (==1.1.3)", "freezegun (==1.1.0)", "freezegun (==1.2.2)", "mypy (==v0.910)", "mypy (==v0.971)", "mypy (==v1.4.1)", "mypy (==v1.5.1)", "pre-commit (==3.4.0)", "pytest (==6.1.2)", "pytest (==7.4.0)", "pytest-cov (==2.12.1)", "pytest-cov (==4.1.0)", "pytest-mypy-plugins (==1.9.3)", "pytest-mypy-plugins (==3.0.0)", "sphinx-autobuild (==2021.3.14)", "sphinx-rtd-theme (==1.3.0)", "tox (==3.27.1)", "tox (==4.11.0)"] +[[package]] +name = "markupsafe" +version = "2.1.3" +description = "Safely add untrusted strings to HTML/XML markup." +optional = false +python-versions = ">=3.7" +files = [ + {file = "MarkupSafe-2.1.3-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:cd0f502fe016460680cd20aaa5a76d241d6f35a1c3350c474bac1273803893fa"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:e09031c87a1e51556fdcb46e5bd4f59dfb743061cf93c4d6831bf894f125eb57"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:68e78619a61ecf91e76aa3e6e8e33fc4894a2bebe93410754bd28fce0a8a4f9f"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:65c1a9bcdadc6c28eecee2c119465aebff8f7a584dd719facdd9e825ec61ab52"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:525808b8019e36eb524b8c68acdd63a37e75714eac50e988180b169d64480a00"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-musllinux_1_1_aarch64.whl", hash = "sha256:962f82a3086483f5e5f64dbad880d31038b698494799b097bc59c2edf392fce6"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:aa7bd130efab1c280bed0f45501b7c8795f9fdbeb02e965371bbef3523627779"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:c9c804664ebe8f83a211cace637506669e7890fec1b4195b505c214e50dd4eb7"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-win32.whl", hash = "sha256:10bbfe99883db80bdbaff2dcf681dfc6533a614f700da1287707e8a5d78a8431"}, + {file = "MarkupSafe-2.1.3-cp310-cp310-win_amd64.whl", hash = "sha256:1577735524cdad32f9f694208aa75e422adba74f1baee7551620e43a3141f559"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:ad9e82fb8f09ade1c3e1b996a6337afac2b8b9e365f926f5a61aacc71adc5b3c"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:3c0fae6c3be832a0a0473ac912810b2877c8cb9d76ca48de1ed31e1c68386575"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b076b6226fb84157e3f7c971a47ff3a679d837cf338547532ab866c57930dbee"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bfce63a9e7834b12b87c64d6b155fdd9b3b96191b6bd334bf37db7ff1fe457f2"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:338ae27d6b8745585f87218a3f23f1512dbf52c26c28e322dbe54bcede54ccb9"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_aarch64.whl", hash = "sha256:e4dd52d80b8c83fdce44e12478ad2e85c64ea965e75d66dbeafb0a3e77308fcc"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_i686.whl", hash = "sha256:df0be2b576a7abbf737b1575f048c23fb1d769f267ec4358296f31c2479db8f9"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:5bbe06f8eeafd38e5d0a4894ffec89378b6c6a625ff57e3028921f8ff59318ac"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-win32.whl", hash = "sha256:dd15ff04ffd7e05ffcb7fe79f1b98041b8ea30ae9234aed2a9168b5797c3effb"}, + {file = "MarkupSafe-2.1.3-cp311-cp311-win_amd64.whl", hash = "sha256:134da1eca9ec0ae528110ccc9e48041e0828d79f24121a1a146161103c76e686"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:f698de3fd0c4e6972b92290a45bd9b1536bffe8c6759c62471efaa8acb4c37bc"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:aa57bd9cf8ae831a362185ee444e15a93ecb2e344c8e52e4d721ea3ab6ef1823"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:ffcc3f7c66b5f5b7931a5aa68fc9cecc51e685ef90282f4a82f0f5e9b704ad11"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:47d4f1c5f80fc62fdd7777d0d40a2e9dda0a05883ab11374334f6c4de38adffd"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:1f67c7038d560d92149c060157d623c542173016c4babc0c1913cca0564b9939"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_aarch64.whl", hash = "sha256:9aad3c1755095ce347e26488214ef77e0485a3c34a50c5a5e2471dff60b9dd9c"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_i686.whl", hash = "sha256:14ff806850827afd6b07a5f32bd917fb7f45b046ba40c57abdb636674a8b559c"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8f9293864fe09b8149f0cc42ce56e3f0e54de883a9de90cd427f191c346eb2e1"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-win32.whl", hash = "sha256:715d3562f79d540f251b99ebd6d8baa547118974341db04f5ad06d5ea3eb8007"}, + {file = "MarkupSafe-2.1.3-cp312-cp312-win_amd64.whl", hash = "sha256:1b8dd8c3fd14349433c79fa8abeb573a55fc0fdd769133baac1f5e07abf54aeb"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:8e254ae696c88d98da6555f5ace2279cf7cd5b3f52be2b5cf97feafe883b58d2"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:cb0932dc158471523c9637e807d9bfb93e06a95cbf010f1a38b98623b929ef2b"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9402b03f1a1b4dc4c19845e5c749e3ab82d5078d16a2a4c2cd2df62d57bb0707"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:ca379055a47383d02a5400cb0d110cef0a776fc644cda797db0c5696cfd7e18e"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-musllinux_1_1_aarch64.whl", hash = "sha256:b7ff0f54cb4ff66dd38bebd335a38e2c22c41a8ee45aa608efc890ac3e3931bc"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:c011a4149cfbcf9f03994ec2edffcb8b1dc2d2aede7ca243746df97a5d41ce48"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:56d9f2ecac662ca1611d183feb03a3fa4406469dafe241673d521dd5ae92a155"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-win32.whl", hash = "sha256:8758846a7e80910096950b67071243da3e5a20ed2546e6392603c096778d48e0"}, + {file = "MarkupSafe-2.1.3-cp37-cp37m-win_amd64.whl", hash = "sha256:787003c0ddb00500e49a10f2844fac87aa6ce977b90b0feaaf9de23c22508b24"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:2ef12179d3a291be237280175b542c07a36e7f60718296278d8593d21ca937d4"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:2c1b19b3aaacc6e57b7e25710ff571c24d6c3613a45e905b1fde04d691b98ee0"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:8afafd99945ead6e075b973fefa56379c5b5c53fd8937dad92c662da5d8fd5ee"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:8c41976a29d078bb235fea9b2ecd3da465df42a562910f9022f1a03107bd02be"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d080e0a5eb2529460b30190fcfcc4199bd7f827663f858a226a81bc27beaa97e"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-musllinux_1_1_aarch64.whl", hash = "sha256:69c0f17e9f5a7afdf2cc9fb2d1ce6aabdb3bafb7f38017c0b77862bcec2bbad8"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:504b320cd4b7eff6f968eddf81127112db685e81f7e36e75f9f84f0df46041c3"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:42de32b22b6b804f42c5d98be4f7e5e977ecdd9ee9b660fda1a3edf03b11792d"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-win32.whl", hash = "sha256:ceb01949af7121f9fc39f7d27f91be8546f3fb112c608bc4029aef0bab86a2a5"}, + {file = "MarkupSafe-2.1.3-cp38-cp38-win_amd64.whl", hash = "sha256:1b40069d487e7edb2676d3fbdb2b0829ffa2cd63a2ec26c4938b2d34391b4ecc"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:8023faf4e01efadfa183e863fefde0046de576c6f14659e8782065bcece22198"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:6b2b56950d93e41f33b4223ead100ea0fe11f8e6ee5f641eb753ce4b77a7042b"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:9dcdfd0eaf283af041973bff14a2e143b8bd64e069f4c383416ecd79a81aab58"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:05fb21170423db021895e1ea1e1f3ab3adb85d1c2333cbc2310f2a26bc77272e"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:282c2cb35b5b673bbcadb33a585408104df04f14b2d9b01d4c345a3b92861c2c"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-musllinux_1_1_aarch64.whl", hash = "sha256:ab4a0df41e7c16a1392727727e7998a467472d0ad65f3ad5e6e765015df08636"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:7ef3cb2ebbf91e330e3bb937efada0edd9003683db6b57bb108c4001f37a02ea"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:0a4e4a1aff6c7ac4cd55792abf96c915634c2b97e3cc1c7129578aa68ebd754e"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-win32.whl", hash = "sha256:fec21693218efe39aa7f8599346e90c705afa52c5b31ae019b2e57e8f6542bb2"}, + {file = "MarkupSafe-2.1.3-cp39-cp39-win_amd64.whl", hash = "sha256:3fd4abcb888d15a94f32b75d8fd18ee162ca0c064f35b11134be77050296d6ba"}, + {file = "MarkupSafe-2.1.3.tar.gz", hash = "sha256:af598ed32d6ae86f1b747b82783958b1a4ab8f617b06fe68795c7f026abbdcad"}, +] + [[package]] name = "nodeenv" version = "1.8.0" @@ -597,13 +683,13 @@ files = [ [[package]] name = "setuptools" -version = "69.0.2" +version = "69.0.3" description = "Easily download, build, install, upgrade, and uninstall Python packages" optional = false python-versions = ">=3.8" files = [ - {file = "setuptools-69.0.2-py3-none-any.whl", hash = "sha256:1e8fdff6797d3865f37397be788a4e3cba233608e9b509382a2777d25ebde7f2"}, - {file = "setuptools-69.0.2.tar.gz", hash = "sha256:735896e78a4742605974de002ac60562d286fa8051a7e2299445e8e8fbb01aa6"}, + {file = "setuptools-69.0.3-py3-none-any.whl", hash = "sha256:385eb4edd9c9d5c17540511303e39a147ce2fc04bc55289c322b9e5904fe2c05"}, + {file = "setuptools-69.0.3.tar.gz", hash = "sha256:be1af57fc409f93647f2e8e4573a142ed38724b8cdd389706a867bb4efcf1e78"}, ] [package.extras] @@ -692,4 +778,4 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.13" -content-hash = "219a5af37bc0c4a51008438a196175c0aa034fe070bb231fa9d9c2c50e5462c4" +content-hash = "e54fa1d110b585d659ed1df21dc03569d85ab855bb02d6efdc63190ff0c8d891" diff --git a/pyproject.toml b/pyproject.toml index f61c61ac..47c07989 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ pyarrow = "*" bson = "0.5.10" polars = "*" typing_extensions = "*" +jinja2 = "*" [tool.poetry.group.test.dependencies] pytest = "*" @@ -26,7 +27,6 @@ pre-commit = "*" [tool.poetry.group.dev.dependencies] loguru = "*" - [[tool.poetry.source]] name = "PyPI" priority = "primary" diff --git a/tests/test_bson.py b/tests/test_bson.py index 4e987233..1722fe38 100644 --- a/tests/test_bson.py +++ b/tests/test_bson.py @@ -26,19 +26,6 @@ def test_write(tmp_path, shape): np.allclose(x["a"], data["a"]) -def test_wrong_type(tmp_path): - """ - Test a TypeError is raised when trying to write a dict - of data that is not supported - - Args: - tmp_path: temporary path fixture - """ - data = {"B": 3} - with pytest.raises(TypeError): - write_bson(data=data, file=tmp_path / "maffay.bson") - - def test_vector(tmp_path): """ Test that a vector is written and read correctly