From 9c25713cc3a0c6f54994ec86ad529334c4fa4730 Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Sun, 24 Dec 2023 10:24:45 +0400 Subject: [PATCH 1/5] jinja2 experiment --- experiment/creator.py.jinja2 | 18 ++++++++ experiment/demo1.py | 30 ++++++++++++ experiment/fill.py | 14 ++++++ poetry.lock | 90 +++++++++++++++++++++++++++++++----- pyproject.toml | 2 +- 5 files changed, 141 insertions(+), 13 deletions(-) create mode 100644 experiment/creator.py.jinja2 create mode 100644 experiment/demo1.py create mode 100644 experiment/fill.py diff --git a/experiment/creator.py.jinja2 b/experiment/creator.py.jinja2 new file mode 100644 index 00000000..40f48a35 --- /dev/null +++ b/experiment/creator.py.jinja2 @@ -0,0 +1,18 @@ +"""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/experiment/demo1.py b/experiment/demo1.py new file mode 100644 index 00000000..ef526cbb --- /dev/null +++ b/experiment/demo1.py @@ -0,0 +1,30 @@ +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__": + data = DataAPI(A=pl.DataFrame(), B=pl.DataFrame(), C=pl.DataFrame()) + print(data.tables) + print(data.A) + print(data.B) + print(data.C) diff --git a/experiment/fill.py b/experiment/fill.py new file mode 100644 index 00000000..bbfbd295 --- /dev/null +++ b/experiment/fill.py @@ -0,0 +1,14 @@ +"""Create a dataclass from a template""" +from jinja2 import Template + +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"} + + # 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/poetry.lock b/poetry.lock index c2b2e563..d0f5b57c 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. [[package]] name = "bson" @@ -169,6 +169,23 @@ files = [ {file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"}, ] +[[package]] +name = "jinja2" +version = "3.1.2" +description = "A very fast and expressive template engine." +optional = false +python-versions = ">=3.7" +files = [ + {file = "Jinja2-3.1.2-py3-none-any.whl", hash = "sha256:6088930bfe239f0e6710546ab9c19c9ef35e29792895fed6e6e31a023a182a61"}, + {file = "Jinja2-3.1.2.tar.gz", hash = "sha256:31351a702a408a9e7595a8fc6150fc3f43bb6bf7e319770cbc0db9df9437e852"}, +] + +[package.dependencies] +MarkupSafe = ">=2.0" + +[package.extras] +i18n = ["Babel (>=2.7)"] + [[package]] name = "loguru" version = "0.7.2" @@ -187,6 +204,65 @@ 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-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" @@ -548,7 +624,6 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, - {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -556,15 +631,8 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, - {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, - {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, - {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, - {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, - {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, - {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -581,7 +649,6 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, - {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -589,7 +656,6 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, - {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -692,4 +758,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 = "8ee9a7410a68b9d807a6d50c31749fea071e6c1c6a8e8a44118d799d416bb4c7" diff --git a/pyproject.toml b/pyproject.toml index f61c61ac..a8e6ae9c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -25,7 +25,7 @@ pre-commit = "*" [tool.poetry.group.dev.dependencies] loguru = "*" - +jinja2 = "*" [[tool.poetry.source]] name = "PyPI" From af474d470579b521b8fa9f71b5d7555cec493367 Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Mon, 25 Dec 2023 07:55:27 +0400 Subject: [PATCH 2/5] testing dataclass --- cvx/bson/io.py | 16 +++++++++++++++- cvx/data/__init__.py | 13 +++++++++++++ cvx/data/render.py | 31 +++++++++++++++++++++++++++++++ experiment/demo1.py | 26 ++++++++++++++++++++++---- experiment/fill.py | 10 ++++++---- experiment/xxx.bson | Bin 0 -> 6846 bytes 6 files changed, 87 insertions(+), 9 deletions(-) create mode 100644 cvx/data/__init__.py create mode 100644 cvx/data/render.py create mode 100644 experiment/xxx.bson 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/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 index ef526cbb..b76bddab 100644 --- a/experiment/demo1.py +++ b/experiment/demo1.py @@ -9,11 +9,8 @@ @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 @@ -23,8 +20,29 @@ class DataAPI(Data): if __name__ == "__main__": - data = DataAPI(A=pl.DataFrame(), B=pl.DataFrame(), C=pl.DataFrame()) + # 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 index bbfbd295..a132f573 100644 --- a/experiment/fill.py +++ b/experiment/fill.py @@ -1,14 +1,16 @@ -"""Create a dataclass from a template""" -from jinja2 import Template +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()) + # template = Template(open("creator.py.jinja2").read()) # we copy & paste the new class into a new file - print(template.render(names=names, strategy="s239")) + # 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 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 x4(zgbb@U__ac$yo$osI8u9B9blCG| Date: Mon, 25 Dec 2023 07:55:40 +0400 Subject: [PATCH 3/5] testing dataclass --- cvx/data/data_api.py.jinja2 | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 cvx/data/data_api.py.jinja2 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 }}) From 8322774e61f8b7c643c6724bd3a0829207185c8e Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Mon, 25 Dec 2023 09:04:36 +0400 Subject: [PATCH 4/5] moving jinja2 up --- Makefile | 1 - README.md | 2 +- experiment/creator.py.jinja2 | 18 ------------------ poetry.lock | 30 +++++++++++++++++++++++++----- pyproject.toml | 2 +- 5 files changed, 27 insertions(+), 26 deletions(-) delete mode 100644 experiment/creator.py.jinja2 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/experiment/creator.py.jinja2 b/experiment/creator.py.jinja2 deleted file mode 100644 index 40f48a35..00000000 --- a/experiment/creator.py.jinja2 +++ /dev/null @@ -1,18 +0,0 @@ -"""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/poetry.lock b/poetry.lock index d0f5b57c..2da5297d 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1,4 +1,4 @@ -# This file is automatically @generated by Poetry 1.6.1 and should not be changed by hand. +# This file is automatically @generated by Poetry 1.7.1 and should not be changed by hand. [[package]] name = "bson" @@ -231,6 +231,16 @@ files = [ {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"}, @@ -624,6 +634,7 @@ files = [ {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:69b023b2b4daa7548bcfbd4aa3da05b3a74b772db9e23b982788168117739938"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:81e0b275a9ecc9c0c0c07b4b90ba548307583c125f54d5b6946cfee6360c733d"}, {file = "PyYAML-6.0.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ba336e390cd8e4d1739f42dfe9bb83a3cc2e80f567d8805e11b46f4a943f5515"}, + {file = "PyYAML-6.0.1-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:326c013efe8048858a6d312ddd31d56e468118ad4cdeda36c719bf5bb6192290"}, {file = "PyYAML-6.0.1-cp310-cp310-win32.whl", hash = "sha256:bd4af7373a854424dabd882decdc5579653d7868b8fb26dc7d0e99f823aa5924"}, {file = "PyYAML-6.0.1-cp310-cp310-win_amd64.whl", hash = "sha256:fd1592b3fdf65fff2ad0004b5e363300ef59ced41c2e6b3a99d4089fa8c5435d"}, {file = "PyYAML-6.0.1-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:6965a7bc3cf88e5a1c3bd2e0b5c22f8d677dc88a455344035f03399034eb3007"}, @@ -631,8 +642,15 @@ files = [ {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:42f8152b8dbc4fe7d96729ec2b99c7097d656dc1213a3229ca5383f973a5ed6d"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:062582fca9fabdd2c8b54a3ef1c978d786e0f6b3a1510e0ac93ef59e0ddae2bc"}, {file = "PyYAML-6.0.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:d2b04aac4d386b172d5b9692e2d2da8de7bfb6c387fa4f801fbf6fb2e6ba4673"}, + {file = "PyYAML-6.0.1-cp311-cp311-musllinux_1_1_x86_64.whl", hash = "sha256:e7d73685e87afe9f3b36c799222440d6cf362062f78be1013661b00c5c6f678b"}, {file = "PyYAML-6.0.1-cp311-cp311-win32.whl", hash = "sha256:1635fd110e8d85d55237ab316b5b011de701ea0f29d07611174a1b42f1444741"}, {file = "PyYAML-6.0.1-cp311-cp311-win_amd64.whl", hash = "sha256:bf07ee2fef7014951eeb99f56f39c9bb4af143d8aa3c21b1677805985307da34"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:855fb52b0dc35af121542a76b9a84f8d1cd886ea97c84703eaa6d88e37a2ad28"}, + {file = "PyYAML-6.0.1-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:40df9b996c2b73138957fe23a16a4f0ba614f4c0efce1e9406a184b6d07fa3a9"}, + {file = "PyYAML-6.0.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:6c22bec3fbe2524cde73d7ada88f6566758a8f7227bfbf93a408a9d86bcc12a0"}, + {file = "PyYAML-6.0.1-cp312-cp312-musllinux_1_1_x86_64.whl", hash = "sha256:8d4e9c88387b0f5c7d5f281e55304de64cf7f9c0021a3525bd3b1c542da3b0e4"}, + {file = "PyYAML-6.0.1-cp312-cp312-win32.whl", hash = "sha256:d483d2cdf104e7c9fa60c544d92981f12ad66a457afae824d146093b8c294c54"}, + {file = "PyYAML-6.0.1-cp312-cp312-win_amd64.whl", hash = "sha256:0d3304d8c0adc42be59c5f8a4d9e3d7379e6955ad754aa9d6ab7a398b59dd1df"}, {file = "PyYAML-6.0.1-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:50550eb667afee136e9a77d6dc71ae76a44df8b3e51e41b77f6de2932bfe0f47"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:1fe35611261b29bd1de0070f0b2f47cb6ff71fa6595c077e42bd0c419fa27b98"}, {file = "PyYAML-6.0.1-cp36-cp36m-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:704219a11b772aea0d8ecd7058d0082713c3562b4e271b849ad7dc4a5c90c13c"}, @@ -649,6 +667,7 @@ files = [ {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a0cd17c15d3bb3fa06978b4e8958dcdc6e0174ccea823003a106c7d4d7899ac5"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:28c119d996beec18c05208a8bd78cbe4007878c6dd15091efb73a30e90539696"}, {file = "PyYAML-6.0.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7e07cbde391ba96ab58e532ff4803f79c4129397514e1413a7dc761ccd755735"}, + {file = "PyYAML-6.0.1-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:49a183be227561de579b4a36efbb21b3eab9651dd81b1858589f796549873dd6"}, {file = "PyYAML-6.0.1-cp38-cp38-win32.whl", hash = "sha256:184c5108a2aca3c5b3d3bf9395d50893a7ab82a38004c8f61c258d4428e80206"}, {file = "PyYAML-6.0.1-cp38-cp38-win_amd64.whl", hash = "sha256:1e2722cc9fbb45d9b87631ac70924c11d3a401b2d7f410cc0e3bbf249f2dca62"}, {file = "PyYAML-6.0.1-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9eb6caa9a297fc2c2fb8862bc5370d0303ddba53ba97e71f08023b6cd73d16a8"}, @@ -656,6 +675,7 @@ files = [ {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:5773183b6446b2c99bb77e77595dd486303b4faab2b086e7b17bc6bef28865f6"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_s390x.manylinux2014_s390x.whl", hash = "sha256:b786eecbdf8499b9ca1d697215862083bd6d2a99965554781d0d8d1ad31e13a0"}, {file = "PyYAML-6.0.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:bc1bf2925a1ecd43da378f4db9e4f799775d6367bdb94671027b73b393a7c42c"}, + {file = "PyYAML-6.0.1-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:04ac92ad1925b2cff1db0cfebffb6ffc43457495c9b3c39d3fcae417d7125dc5"}, {file = "PyYAML-6.0.1-cp39-cp39-win32.whl", hash = "sha256:faca3bdcf85b2fc05d06ff3fbc1f83e1391b3e724afa3feba7d13eeab355484c"}, {file = "PyYAML-6.0.1-cp39-cp39-win_amd64.whl", hash = "sha256:510c9deebc5c0225e8c96813043e62b680ba2f9c50a08d3724c7f28a747d1486"}, {file = "PyYAML-6.0.1.tar.gz", hash = "sha256:bfdf460b1736c775f2ba9f6a92bca30bc2095067b8a9d77876d1fad6cc3b4a43"}, @@ -663,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] @@ -758,4 +778,4 @@ dev = ["black (>=19.3b0)", "pytest (>=4.6.2)"] [metadata] lock-version = "2.0" python-versions = ">=3.9,<3.13" -content-hash = "8ee9a7410a68b9d807a6d50c31749fea071e6c1c6a8e8a44118d799d416bb4c7" +content-hash = "e54fa1d110b585d659ed1df21dc03569d85ab855bb02d6efdc63190ff0c8d891" diff --git a/pyproject.toml b/pyproject.toml index a8e6ae9c..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 = "*" @@ -25,7 +26,6 @@ pre-commit = "*" [tool.poetry.group.dev.dependencies] loguru = "*" -jinja2 = "*" [[tool.poetry.source]] name = "PyPI" From 2723439d2dbe8d3829e845837a1e7e2a7879ef20 Mon Sep 17 00:00:00 2001 From: Thomas Schmelzer Date: Mon, 25 Dec 2023 09:05:29 +0400 Subject: [PATCH 5/5] remove outdated test --- tests/test_bson.py | 13 ------------- 1 file changed, 13 deletions(-) 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