From 2eef479b6493208561e5d8a2416a1573182a195c Mon Sep 17 00:00:00 2001 From: Jakob Gerhard Martinussen <10655778+JakobGM@users.noreply.github.com> Date: Mon, 4 Jul 2022 14:07:51 +0200 Subject: [PATCH] Make patito compatible with DuckDB version 0.4.0 --- poetry.lock | 78 ++++++++++++++++++++++---------------------- src/patito/duckdb.py | 26 ++++++++++++--- 2 files changed, 60 insertions(+), 44 deletions(-) diff --git a/poetry.lock b/poetry.lock index 0b9063f..d18cd85 100644 --- a/poetry.lock +++ b/poetry.lock @@ -156,7 +156,7 @@ python-versions = ">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*" [[package]] name = "duckdb" -version = "0.3.4" +version = "0.4.0" description = "DuckDB embedded database" category = "main" optional = true @@ -1106,44 +1106,44 @@ docutils = [ {file = "docutils-0.17.1.tar.gz", hash = "sha256:686577d2e4c32380bb50cbb22f575ed742d58168cee37e99117a854bcd88f125"}, ] duckdb = [ - {file = "duckdb-0.3.4-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:4ecfa5e8c6bde61efead473b05b35ed989dc08fe76c7ab1c931e4c16e082b10b"}, - {file = "duckdb-0.3.4-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:7bda539e070d08391b36370e847122350c66d90d9fdf20727b23cde86847fa39"}, - {file = "duckdb-0.3.4-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:6d913ea8d59c4004508ed2a21b70dcf7c5cd5d667e7a48efac01e0453627aadc"}, - {file = "duckdb-0.3.4-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:eeab0867e5194e14ea39dbe1d14164c058c9d9fff1328b120361fa6da87aa622"}, - {file = "duckdb-0.3.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:0695ee38ad8b2fa4390507ef75c491c93bb508dbe636fec4d08f66bc20b2f911"}, - {file = "duckdb-0.3.4-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:b4a743dc8f1e78539070295be548dfbb7a01c1625d2e37f2414068378a11c3d5"}, - {file = "duckdb-0.3.4-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:6202a9f611aa6526db9699ba625ee0518ca3e269642d6955b995375285f38a7e"}, - {file = "duckdb-0.3.4-cp310-cp310-win32.whl", hash = "sha256:f3452e6780756508f07cd45b696dd92a08adac02d032442ffb4146578c31ff19"}, - {file = "duckdb-0.3.4-cp310-cp310-win_amd64.whl", hash = "sha256:e27f5a6e486785797afc109204dffc81982e6eb0af2001e1e1709dd25c0c203d"}, - {file = "duckdb-0.3.4-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:6e0b88fd0a905e23efb5555f22b980952494c9b94f103c14ea3b613019522095"}, - {file = "duckdb-0.3.4-cp36-cp36m-win32.whl", hash = "sha256:99ba0cdfbbaee22828cb936c4c324617476970359ff6a9e80b5b7daf4269c500"}, - {file = "duckdb-0.3.4-cp36-cp36m-win_amd64.whl", hash = "sha256:03020e992d6093a68ab597e11da2e34587863f238bcc317690e1fec1e93bca41"}, - {file = "duckdb-0.3.4-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:d6280debb6c10a44b1efa073ba07fb067911f3e11d7f5ae9db715478a819a67d"}, - {file = "duckdb-0.3.4-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4b2107da403605bf68692ed5b9194e5692290bd73fa9abdd48fde82be0d6457d"}, - {file = "duckdb-0.3.4-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e47ab2f2112a258f2e8fae66321009bb51253d674fadf7dd964be0886514684c"}, - {file = "duckdb-0.3.4-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:9df6867017644f016cde47da37de57065540d3cfa410e50b943bd90f42d96110"}, - {file = "duckdb-0.3.4-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:0da2cadcdfbf9aa2e34eba9cc4413ed7c635aaa0bb4cafef7eb37d951f205223"}, - {file = "duckdb-0.3.4-cp37-cp37m-win32.whl", hash = "sha256:672645773abbe32801bf543d12a1189dbc67122db4da6b90a57f3acecd525dbf"}, - {file = "duckdb-0.3.4-cp37-cp37m-win_amd64.whl", hash = "sha256:6fa14f1d3cf225f788ad7f055e25b98d99c06d3a379df4b788fdf66ebe7f9b98"}, - {file = "duckdb-0.3.4-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:155f6717ad9fe1aa99d8d631508d2577b06519661b7e30cb14cff46a0446558c"}, - {file = "duckdb-0.3.4-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:013a65ddac424d2d778dff37d5b1e91c2f68365436cc8ec76ea45a906313e0bf"}, - {file = "duckdb-0.3.4-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:ba1d627a913154c651daca5ca168b8fa49caa6792a61f069f30eae645a8d52cd"}, - {file = "duckdb-0.3.4-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e8d4e960945955b19ba051e5bb0d6b17c3bcea3d29f9114bb94faaa7585df8c5"}, - {file = "duckdb-0.3.4-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:56ecd82eb31d89ff349059fd909e02906efa1971faeec1a0f7a81357d09d1ad9"}, - {file = "duckdb-0.3.4-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:78c8d2c6629e14140fd038402bf3cbb8c2017ba68148c29c66f8142ffa8f3a39"}, - {file = "duckdb-0.3.4-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:4811c3fd101d1561d46b5d6c7b9915c3b2adbc8a6270e7cddc63411c6a4b4a0c"}, - {file = "duckdb-0.3.4-cp38-cp38-win32.whl", hash = "sha256:aa42d850cf2dd3f5f664f7a9c8be548f8618064ca6260808fa4e361a334ce2b1"}, - {file = "duckdb-0.3.4-cp38-cp38-win_amd64.whl", hash = "sha256:6ec0be5153a35e3a7462c014a90bba81964f63f114af3f25384b97b0bf5fcae7"}, - {file = "duckdb-0.3.4-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:e35d92606c34cfb56f084eca2540db6573b260f974245465f6dae9dbcdbe6434"}, - {file = "duckdb-0.3.4-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:54cf2d11ea8e8a9d474a83137ea654a66b2ac7ea26f615ef4498b9e3fb5091f1"}, - {file = "duckdb-0.3.4-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:de8762917c1349c1517487500d5975c2788f3544b82ae341d79984eaa836e20a"}, - {file = "duckdb-0.3.4-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:60a163e65a1afdf410b2b9cbecd124875a53e53ad9271bdd66ed98ae42034778"}, - {file = "duckdb-0.3.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:f552592ac977d368ea02c6a89b62373fb53a49a36aa8e7d3b3c89999ee420010"}, - {file = "duckdb-0.3.4-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:a1c355929e06f22f35a2d3a74c16721d7b2ecd35e5088bf9722f1ca574ff5a2b"}, - {file = "duckdb-0.3.4-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:f5c65d6a4afa8c313c612d6bc92bca055f1cbcc81646640d5dde797c745b7876"}, - {file = "duckdb-0.3.4-cp39-cp39-win32.whl", hash = "sha256:79256b5521c3945f540dd4ccfcc7658d18e98a42ba619c5571eb075fc234b5a1"}, - {file = "duckdb-0.3.4-cp39-cp39-win_amd64.whl", hash = "sha256:f38cdf5a55a4a4f18c30d2ad73055d4531679fa3282cb08cacf2646f0a0150be"}, - {file = "duckdb-0.3.4.tar.gz", hash = "sha256:ab94cfc9e4c25f93d4a7be2063879475c308d771d53588bfd6198a89a8c2bcd2"}, + {file = "duckdb-0.4.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:5f95fd257d1fd996f99cd498669edefd53f419ec8183c6deee89bba291d7808f"}, + {file = "duckdb-0.4.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:1737acec74d9c352e0a32c9bca620252e8151473943f11995db03853f40acd56"}, + {file = "duckdb-0.4.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:c0f9f59818a74f242d008e63cd440e8272b32911700faebc4e1e85c13726acb7"}, + {file = "duckdb-0.4.0-cp310-cp310-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:4a7809189fa4418f208a7fd0ca39ae519d73f92ab2c944de504f75fb765d4ea8"}, + {file = "duckdb-0.4.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3b216c938beccdfb0aa56bd324622a00e643e0a9b21f59dec18e5215e1591bb1"}, + {file = "duckdb-0.4.0-cp310-cp310-musllinux_1_1_i686.whl", hash = "sha256:2d3660b47057f20a4ffce026e47a7598955611948265f17e03449208c319c17b"}, + {file = "duckdb-0.4.0-cp310-cp310-musllinux_1_1_x86_64.whl", hash = "sha256:f733a646f7c28f7bf4f3917153b7e34be050b82575117b1912838f45efcd2e37"}, + {file = "duckdb-0.4.0-cp310-cp310-win32.whl", hash = "sha256:eb7cad38455649dc2cd5a602322ff1dc60fdb76b5d6f4db50530fc3b87e4badd"}, + {file = "duckdb-0.4.0-cp310-cp310-win_amd64.whl", hash = "sha256:054ef189c7d373f1e2471e673e9daf3ba01d235ba5410c9d7f4d58629464bc49"}, + {file = "duckdb-0.4.0-cp36-cp36m-macosx_10_9_x86_64.whl", hash = "sha256:3ecc9c0e4b4dc55f3e4e33a84b3fe4bcafe15b23ab37f3489cc3c9fb7efe5328"}, + {file = "duckdb-0.4.0-cp36-cp36m-win32.whl", hash = "sha256:5abc2686d2b50a2ff8c322924e348f5903879f05802ebd0f8bd4680149a2ff08"}, + {file = "duckdb-0.4.0-cp36-cp36m-win_amd64.whl", hash = "sha256:55b33f5abe123780d2f69d29b3a7b5e8fd9345a2ff5d0bef5abb3f8ab17bd9d9"}, + {file = "duckdb-0.4.0-cp37-cp37m-macosx_10_9_x86_64.whl", hash = "sha256:a329b11b772ace7795e5d9640e8281665cf9de91a72fc4a3037c27563922cc66"}, + {file = "duckdb-0.4.0-cp37-cp37m-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9b7ac4b4c2a6f640a43748bc684a11932ba4668e1221380d609724850c4e6bff"}, + {file = "duckdb-0.4.0-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:4c268cb4abcb29b0851c513e6ec8ce164d78bc68ff93aa8f9406313b30d504eb"}, + {file = "duckdb-0.4.0-cp37-cp37m-musllinux_1_1_i686.whl", hash = "sha256:b1a648ad9cab58325219cf9f8810d16415410d737dc68e83635d3926d5c2e90b"}, + {file = "duckdb-0.4.0-cp37-cp37m-musllinux_1_1_x86_64.whl", hash = "sha256:ad3d11344e70da162b23f27c82672dbf84be6ba3cb9193e2e283b0bf4d7bb8bc"}, + {file = "duckdb-0.4.0-cp37-cp37m-win32.whl", hash = "sha256:bdc59ef2921e0612c92fd79720021ea9195538c678e07ad2bd7661dfb81f0922"}, + {file = "duckdb-0.4.0-cp37-cp37m-win_amd64.whl", hash = "sha256:e8fac683a12118c4471b9bfb90007b557a5d894172e81197fd0202ffd52ac86c"}, + {file = "duckdb-0.4.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:5871e2eed76f709877294d160ce68d4a05dc7878891d8bd9e254cb2fb10aafdd"}, + {file = "duckdb-0.4.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:17472f9f235beeacee1c14a0d7a24ed5634f44cb0d01d39001a7caf8a8ff6ed2"}, + {file = "duckdb-0.4.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:93081861be6d5e46e442087c674e592207dc96cd3b0278aef039e8e39a8ba195"}, + {file = "duckdb-0.4.0-cp38-cp38-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:5d5e9203350e2c33945c704398bd6b2a148c07811052ad7358b2fc1d2dad1a14"}, + {file = "duckdb-0.4.0-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:19c982fed9b9c7a49919097c2f797a2ab4903ecf127bab367557d07556077e2a"}, + {file = "duckdb-0.4.0-cp38-cp38-musllinux_1_1_i686.whl", hash = "sha256:c900ae6bf596e3b9f9afdcddf322fe63a79f91caf584f5bd02b5969eaa46bdbe"}, + {file = "duckdb-0.4.0-cp38-cp38-musllinux_1_1_x86_64.whl", hash = "sha256:668665a76d52ecfc52ca02e6a87142a87e27ff415dabadddf9f907a0036ad810"}, + {file = "duckdb-0.4.0-cp38-cp38-win32.whl", hash = "sha256:d340a2b7c82114abf7aba0b3744356d66e42d3cb25752ddcd055a2cff1c4be5f"}, + {file = "duckdb-0.4.0-cp38-cp38-win_amd64.whl", hash = "sha256:34f53158913c2bcf0722a11dcd2c57fbeb850c98aed0eac16f84ab3f803fcbd9"}, + {file = "duckdb-0.4.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:892106dfa58841b88a4defbd753e5f1faf796e7e6167d586572c19e2f4709eb7"}, + {file = "duckdb-0.4.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:9108196817df5ed3e4e700cda8489b01a41580d6387e03ef48dbf9248db8514f"}, + {file = "duckdb-0.4.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:8471b5aa985bfe80344c0e680d75f588a4310cba149e830c0d35381033b5e849"}, + {file = "duckdb-0.4.0-cp39-cp39-manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:d21ed770d89e43a941c09ce1295cf2db6ba643a2594bdc14090666051a96ae58"}, + {file = "duckdb-0.4.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b26f4c26b2ef5126f737cb9a3b4a16600669dd05f27593cc78d2dc30091d3055"}, + {file = "duckdb-0.4.0-cp39-cp39-musllinux_1_1_i686.whl", hash = "sha256:b337822a958ae82886c26673b2892f6d2079a943fda6b69d226ea272ca948b82"}, + {file = "duckdb-0.4.0-cp39-cp39-musllinux_1_1_x86_64.whl", hash = "sha256:a5f5f81a16e134d5817c84543dd6ca004d8d7af1d3b1130a7f52d20c7034c119"}, + {file = "duckdb-0.4.0-cp39-cp39-win32.whl", hash = "sha256:2ac18fbebf60b470e4bc338a96109b42bf0154e2fff360fd62e3b4cfbeea63d5"}, + {file = "duckdb-0.4.0-cp39-cp39-win_amd64.whl", hash = "sha256:7f5677229b897a90c0c32e222956e64eb0ba996dc870a1fb90427250f4ce5cb2"}, + {file = "duckdb-0.4.0.tar.gz", hash = "sha256:569e5d618de871e21dd676925349a7a5e701b87ebda3433e0c1d57627a465c1c"}, ] flake8 = [ {file = "flake8-3.9.2-py2.py3-none-any.whl", hash = "sha256:bf8fd333346d844f616e8d47905ef3a3384edae6b4e9beb0c5101e25e3110907"}, diff --git a/src/patito/duckdb.py b/src/patito/duckdb.py index a4f7496..aeecd70 100644 --- a/src/patito/duckdb.py +++ b/src/patito/duckdb.py @@ -105,6 +105,24 @@ def _enum_type_name(field_properties: dict) -> str: return f"enum__{value_hash}" +def _is_missing_enum_type_exception(exception: BaseException) -> bool: + """ + Return True if the given exception might be caused by missing enum type definitions. + + Args: + exception: Exception raised by DuckDB. + + Returns: + True if the exception might be caused by a missing SQL enum type definition. + """ + description = str(exception) + # DuckDB version <= 0.3.4 + old_exception = description.startswith("Not implemented Error: DataType") + # DuckDB version >= 0.4.0 + new_exception = description.startswith("Catalog Error: Type with name enum_") + return old_exception or new_exception + + class Relation(Generic[ModelType]): # Can be set by subclasses in order to specify the serialization class for rows. # Must accept column names as keyword arguments. @@ -597,9 +615,7 @@ def project( # We might get a RunTime error if the enum type has not # been created yet. If so, we create all enum types for # this model. - if self.model is not None and str(exc).startswith( - "Not implemented Error: DataType" - ): + if self.model is not None and _is_missing_enum_type_exception(exc): self.database.create_enum_types(model=self.model) relation = self._relation.project(projection) else: @@ -799,7 +815,7 @@ def with_missing_defaultable_columns( # We might get a RunTime error if the enum type has not # been created yet. If so, we create all enum types for # this model. - if str(exc).startswith("Not implemented Error: DataType"): + if _is_missing_enum_type_exception(exc): self.database.create_enum_types(model=self.model) relation = self._relation.project(projection) else: @@ -846,7 +862,7 @@ def with_missing_nullable_columns( # We might get a RunTime error if the enum type has not # been created yet. If so, we create all enum types for # this model. - if str(exc).startswith("Not implemented Error: DataType"): + if _is_missing_enum_type_exception(exc): self.database.create_enum_types(model=self.model) relation = self._relation.project(projection) else: