patito 0.4.4__py3-none-any.whl → 0.5.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- patito/__init__.py +12 -6
- patito/database.py +658 -0
- patito/duckdb.py +142 -179
- patito/polars.py +36 -44
- patito/pydantic.py +96 -85
- patito/sql.py +1 -2
- patito/validators.py +87 -1
- patito/xdg.py +22 -0
- {patito-0.4.4.dist-info → patito-0.5.0.dist-info}/LICENSE +1 -0
- {patito-0.4.4.dist-info → patito-0.5.0.dist-info}/METADATA +16 -16
- patito-0.5.0.dist-info/RECORD +14 -0
- {patito-0.4.4.dist-info → patito-0.5.0.dist-info}/WHEEL +1 -1
- patito-0.4.4.dist-info/RECORD +0 -12
patito/duckdb.py
CHANGED
|
@@ -104,7 +104,7 @@ def create_pydantic_model(relation: "duckdb.DuckDBPyRelation") -> Type[Model]:
|
|
|
104
104
|
return create_model( # type: ignore
|
|
105
105
|
relation.alias,
|
|
106
106
|
__base__=Model,
|
|
107
|
-
**pydantic_annotations,
|
|
107
|
+
**pydantic_annotations, # pyright: ignore
|
|
108
108
|
)
|
|
109
109
|
|
|
110
110
|
|
|
@@ -170,24 +170,24 @@ class Relation(Generic[ModelType]):
|
|
|
170
170
|
The path must point to an existing file with either a ``.csv``
|
|
171
171
|
or ``.parquet`` file extension.
|
|
172
172
|
- A native DuckDB relation object (``duckdb.DuckDBPyRelation``).
|
|
173
|
-
- A ``patito.Relation`` object.
|
|
173
|
+
- A ``patito.duckdb.Relation`` object.
|
|
174
174
|
|
|
175
175
|
database: Which database to load the relation into. If not provided,
|
|
176
176
|
the default DuckDB database will be used.
|
|
177
177
|
|
|
178
178
|
model: Sub-class of ``patito.Model`` which specifies how to deserialize rows
|
|
179
|
-
when fetched with methods such as
|
|
180
|
-
and ``__iter__()``.
|
|
179
|
+
when fetched with methods such as
|
|
180
|
+
:ref:`Relation.get()<duckdb.Relation.get>` and ``__iter__()``.
|
|
181
181
|
|
|
182
182
|
Will also be used to create a strict table schema if
|
|
183
|
-
:ref:`Relation.create_table()<Relation.create_table>`.
|
|
183
|
+
:ref:`Relation.create_table()<duckdb.Relation.create_table>`.
|
|
184
184
|
schema should be constructed.
|
|
185
185
|
|
|
186
|
-
If not provided, a dynamic model fitting the relation schema will be
|
|
187
|
-
when required.
|
|
186
|
+
If not provided, a dynamic model fitting the relation schema will be
|
|
187
|
+
created when required.
|
|
188
188
|
|
|
189
189
|
Can also be set later dynamically by invoking
|
|
190
|
-
:ref:`Relation.set_model()<Relation.set_model>`.
|
|
190
|
+
:ref:`Relation.set_model()<duckdb.Relation.set_model>`.
|
|
191
191
|
|
|
192
192
|
Raises:
|
|
193
193
|
ValueError: If any one of the following cases are encountered:
|
|
@@ -204,7 +204,7 @@ class Relation(Generic[ModelType]):
|
|
|
204
204
|
|
|
205
205
|
>>> import patito as pt
|
|
206
206
|
>>> df = pt.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
|
|
207
|
-
>>> pt.Relation(df).filter("a > 2").to_df()
|
|
207
|
+
>>> pt.duckdb.Relation(df).filter("a > 2").to_df()
|
|
208
208
|
shape: (1, 2)
|
|
209
209
|
┌─────┬─────┐
|
|
210
210
|
│ a ┆ b │
|
|
@@ -216,7 +216,7 @@ class Relation(Generic[ModelType]):
|
|
|
216
216
|
|
|
217
217
|
Instantiated from an SQL query:
|
|
218
218
|
|
|
219
|
-
>>> pt.Relation("select 1 as a, 2 as b").to_df()
|
|
219
|
+
>>> pt.duckdb.Relation("select 1 as a, 2 as b").to_df()
|
|
220
220
|
shape: (1, 2)
|
|
221
221
|
┌─────┬─────┐
|
|
222
222
|
│ a ┆ b │
|
|
@@ -296,7 +296,7 @@ class Relation(Generic[ModelType]):
|
|
|
296
296
|
Examples:
|
|
297
297
|
>>> import patito as pt
|
|
298
298
|
>>> df = pt.DataFrame({"a": [1, 2, 3], "b": ["X", "Y", "X"]})
|
|
299
|
-
>>> relation = pt.Relation(df)
|
|
299
|
+
>>> relation = pt.duckdb.Relation(df)
|
|
300
300
|
>>> relation.aggregate(
|
|
301
301
|
... "b",
|
|
302
302
|
... "sum(a)",
|
|
@@ -311,7 +311,6 @@ class Relation(Generic[ModelType]):
|
|
|
311
311
|
│ str ┆ f64 ┆ str ┆ i64 │
|
|
312
312
|
╞═════╪════════╪═════════════╪═══════╡
|
|
313
313
|
│ X ┆ 4.0 ┆ X ┆ 3 │
|
|
314
|
-
├╌╌╌╌╌┼╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌┤
|
|
315
314
|
│ Y ┆ 2.0 ┆ Y ┆ 2 │
|
|
316
315
|
└─────┴────────┴─────────────┴───────┘
|
|
317
316
|
"""
|
|
@@ -347,7 +346,7 @@ class Relation(Generic[ModelType]):
|
|
|
347
346
|
|
|
348
347
|
Examples:
|
|
349
348
|
>>> import patito as pt
|
|
350
|
-
>>> relation = pt.Relation("select 1 as column_1, 2 as column_2")
|
|
349
|
+
>>> relation = pt.duckdb.Relation("select 1 as column_1, 2 as column_2")
|
|
351
350
|
>>> relation.add_suffix("_renamed").to_df()
|
|
352
351
|
shape: (1, 2)
|
|
353
352
|
┌──────────────────┬──────────────────┐
|
|
@@ -413,7 +412,7 @@ class Relation(Generic[ModelType]):
|
|
|
413
412
|
|
|
414
413
|
Examples:
|
|
415
414
|
>>> import patito as pt
|
|
416
|
-
>>> relation = pt.Relation("select 1 as column_1, 2 as column_2")
|
|
415
|
+
>>> relation = pt.duckdb.Relation("select 1 as column_1, 2 as column_2")
|
|
417
416
|
>>> relation.add_prefix("renamed_").to_df()
|
|
418
417
|
shape: (1, 2)
|
|
419
418
|
┌──────────────────┬──────────────────┐
|
|
@@ -464,8 +463,8 @@ class Relation(Generic[ModelType]):
|
|
|
464
463
|
"""
|
|
465
464
|
Return ``True`` if the given predicate(s) are true for all rows in the relation.
|
|
466
465
|
|
|
467
|
-
See :
|
|
468
|
-
|
|
466
|
+
See :func:`Relation.filter()` for additional information regarding the
|
|
467
|
+
parameters.
|
|
469
468
|
|
|
470
469
|
Args:
|
|
471
470
|
filters: SQL predicates to satisfy.
|
|
@@ -480,7 +479,7 @@ class Relation(Generic[ModelType]):
|
|
|
480
479
|
... "zero": [0, 0, 0],
|
|
481
480
|
... }
|
|
482
481
|
... )
|
|
483
|
-
>>> relation = pt.Relation(df)
|
|
482
|
+
>>> relation = pt.duckdb.Relation(df)
|
|
484
483
|
>>> relation.all(zero=0)
|
|
485
484
|
True
|
|
486
485
|
>>> relation.all(
|
|
@@ -520,7 +519,7 @@ class Relation(Generic[ModelType]):
|
|
|
520
519
|
The following case statement...
|
|
521
520
|
|
|
522
521
|
>>> import patito as pt
|
|
523
|
-
>>> db = pt.Database()
|
|
522
|
+
>>> db = pt.duckdb.Database()
|
|
524
523
|
>>> relation = db.to_relation("select 1 as a union select 2 as a")
|
|
525
524
|
>>> relation.case(
|
|
526
525
|
... from_column="a",
|
|
@@ -535,7 +534,6 @@ class Relation(Generic[ModelType]):
|
|
|
535
534
|
│ i64 ┆ str │
|
|
536
535
|
╞═════╪═════╡
|
|
537
536
|
│ 1 ┆ one │
|
|
538
|
-
├╌╌╌╌╌┼╌╌╌╌╌┤
|
|
539
537
|
│ 2 ┆ two │
|
|
540
538
|
└─────┴─────┘
|
|
541
539
|
|
|
@@ -555,7 +553,6 @@ class Relation(Generic[ModelType]):
|
|
|
555
553
|
│ i64 ┆ str │
|
|
556
554
|
╞═════╪═════╡
|
|
557
555
|
│ 1 ┆ one │
|
|
558
|
-
├╌╌╌╌╌┼╌╌╌╌╌┤
|
|
559
556
|
│ 2 ┆ two │
|
|
560
557
|
└─────┴─────┘
|
|
561
558
|
"""
|
|
@@ -580,15 +577,15 @@ class Relation(Generic[ModelType]):
|
|
|
580
577
|
Cast the columns of the relation to types compatible with the associated model.
|
|
581
578
|
|
|
582
579
|
The associated model must either be set by invoking
|
|
583
|
-
:ref:`Relation.set_model() <Relation.set_model>` or provided with the
|
|
584
|
-
parameter.
|
|
580
|
+
:ref:`Relation.set_model() <duckdb.Relation.set_model>` or provided with the
|
|
581
|
+
``model`` parameter.
|
|
585
582
|
|
|
586
583
|
Any columns of the relation that are not part of the given model schema will be
|
|
587
584
|
left as-is.
|
|
588
585
|
|
|
589
586
|
Args:
|
|
590
|
-
model: If :ref:`Relation.set_model() <Relation.set_model>` has not
|
|
591
|
-
invoked or is intended to be overwritten.
|
|
587
|
+
model: If :ref:`Relation.set_model() <duckdb.Relation.set_model>` has not
|
|
588
|
+
been invoked or is intended to be overwritten.
|
|
592
589
|
strict: If set to ``False``, columns which are technically compliant with
|
|
593
590
|
the specified field type, will not be casted. For example, a column
|
|
594
591
|
annotated with ``int`` is technically compliant with ``SMALLINT``, even
|
|
@@ -607,31 +604,31 @@ class Relation(Generic[ModelType]):
|
|
|
607
604
|
>>> class Schema(pt.Model):
|
|
608
605
|
... float_column: float
|
|
609
606
|
...
|
|
610
|
-
>>> relation = pt.Relation("select 1 as float_column")
|
|
607
|
+
>>> relation = pt.duckdb.Relation("select 1 as float_column")
|
|
611
608
|
>>> relation.types["float_column"]
|
|
612
|
-
|
|
609
|
+
INTEGER
|
|
613
610
|
>>> relation.cast(model=Schema).types["float_column"]
|
|
614
|
-
|
|
611
|
+
DOUBLE
|
|
615
612
|
|
|
616
|
-
>>> relation = pt.Relation("select 1::FLOAT as float_column")
|
|
613
|
+
>>> relation = pt.duckdb.Relation("select 1::FLOAT as float_column")
|
|
617
614
|
>>> relation.cast(model=Schema).types["float_column"]
|
|
618
|
-
|
|
615
|
+
FLOAT
|
|
619
616
|
>>> relation.cast(model=Schema, strict=True).types["float_column"]
|
|
620
|
-
|
|
617
|
+
DOUBLE
|
|
621
618
|
|
|
622
619
|
>>> class Schema(pt.Model):
|
|
623
620
|
... column_1: float
|
|
624
621
|
... column_2: float
|
|
625
622
|
...
|
|
626
|
-
>>> relation = pt.Relation(
|
|
627
|
-
...
|
|
628
|
-
... )
|
|
623
|
+
>>> relation = pt.duckdb.Relation(
|
|
624
|
+
... "select 1 as column_1, 2 as column_2"
|
|
625
|
+
... ).set_model(Schema)
|
|
629
626
|
>>> relation.types
|
|
630
|
-
{'column_1':
|
|
627
|
+
{'column_1': INTEGER, 'column_2': INTEGER}
|
|
631
628
|
>>> relation.cast(include=["column_1"]).types
|
|
632
|
-
{'column_1':
|
|
629
|
+
{'column_1': DOUBLE, 'column_2': INTEGER}
|
|
633
630
|
>>> relation.cast(exclude=["column_1"]).types
|
|
634
|
-
{'column_1':
|
|
631
|
+
{'column_1': INTEGER, 'column_2': DOUBLE}
|
|
635
632
|
"""
|
|
636
633
|
if model is not None:
|
|
637
634
|
relation = self.set_model(model)
|
|
@@ -650,7 +647,8 @@ class Relation(Generic[ModelType]):
|
|
|
650
647
|
|
|
651
648
|
if include is not None and exclude is not None:
|
|
652
649
|
raise ValueError(
|
|
653
|
-
|
|
650
|
+
"Both include and exclude provided to "
|
|
651
|
+
f"{self.__class__.__name__}.cast()!"
|
|
654
652
|
)
|
|
655
653
|
elif include is not None:
|
|
656
654
|
include = set(include)
|
|
@@ -701,7 +699,7 @@ class Relation(Generic[ModelType]):
|
|
|
701
699
|
... "c": [None, 8.0, 9.0],
|
|
702
700
|
... }
|
|
703
701
|
... )
|
|
704
|
-
>>> relation = pt.Relation(df)
|
|
702
|
+
>>> relation = pt.duckdb.Relation(df)
|
|
705
703
|
>>> relation.coalesce(a=2, b="six").to_df()
|
|
706
704
|
shape: (3, 3)
|
|
707
705
|
┌─────┬──────┬──────┐
|
|
@@ -710,9 +708,7 @@ class Relation(Generic[ModelType]):
|
|
|
710
708
|
│ i64 ┆ str ┆ f64 │
|
|
711
709
|
╞═════╪══════╪══════╡
|
|
712
710
|
│ 1 ┆ four ┆ null │
|
|
713
|
-
├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
714
711
|
│ 2 ┆ five ┆ 8.0 │
|
|
715
|
-
├╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌┤
|
|
716
712
|
│ 3 ┆ six ┆ 9.0 │
|
|
717
713
|
└─────┴──────┴──────┘
|
|
718
714
|
"""
|
|
@@ -732,7 +728,7 @@ class Relation(Generic[ModelType]):
|
|
|
732
728
|
|
|
733
729
|
Examples:
|
|
734
730
|
>>> import patito as pt
|
|
735
|
-
>>> pt.Relation("select 1 as a, 2 as b").columns
|
|
731
|
+
>>> pt.duckdb.Relation("select 1 as a, 2 as b").columns
|
|
736
732
|
['a', 'b']
|
|
737
733
|
"""
|
|
738
734
|
# Under certain specific circumstances columns are suffixed with
|
|
@@ -748,13 +744,13 @@ class Relation(Generic[ModelType]):
|
|
|
748
744
|
|
|
749
745
|
Examples:
|
|
750
746
|
>>> import patito as pt
|
|
751
|
-
>>> relation = pt.Relation("select 1 as a")
|
|
747
|
+
>>> relation = pt.duckdb.Relation("select 1 as a")
|
|
752
748
|
>>> relation.count()
|
|
753
749
|
1
|
|
754
750
|
>>> (relation + relation).count()
|
|
755
751
|
2
|
|
756
752
|
|
|
757
|
-
The :ref:`Relation.__len__()<Relation.__len__>` method invokes
|
|
753
|
+
The :ref:`Relation.__len__()<duckdb.Relation.__len__>` method invokes
|
|
758
754
|
``Relation.count()`` under the hood, and is equivalent:
|
|
759
755
|
|
|
760
756
|
>>> len(relation)
|
|
@@ -768,9 +764,10 @@ class Relation(Generic[ModelType]):
|
|
|
768
764
|
"""
|
|
769
765
|
Create new database table based on relation.
|
|
770
766
|
|
|
771
|
-
If ``self.model`` is set with
|
|
772
|
-
then the model is used
|
|
773
|
-
Otherwise, a permissive table schema is created based
|
|
767
|
+
If ``self.model`` is set with
|
|
768
|
+
:ref:`Relation.set_model()<duckdb.Relation.set_model>`, then the model is used
|
|
769
|
+
to infer the table schema. Otherwise, a permissive table schema is created based
|
|
770
|
+
on the relation data.
|
|
774
771
|
|
|
775
772
|
Returns:
|
|
776
773
|
Relation: A relation pointing to the newly created table.
|
|
@@ -780,15 +777,15 @@ class Relation(Generic[ModelType]):
|
|
|
780
777
|
>>> import patito as pt
|
|
781
778
|
|
|
782
779
|
>>> df = pt.DataFrame({"enum_column": ["A", "A", "B"]})
|
|
783
|
-
>>> relation = pt.Relation(df)
|
|
780
|
+
>>> relation = pt.duckdb.Relation(df)
|
|
784
781
|
>>> relation.create_table("permissive_table").types
|
|
785
|
-
{'enum_column':
|
|
782
|
+
{'enum_column': VARCHAR}
|
|
786
783
|
|
|
787
784
|
>>> class TableSchema(pt.Model):
|
|
788
785
|
... enum_column: Literal["A", "B", "C"]
|
|
789
786
|
...
|
|
790
787
|
>>> relation.set_model(TableSchema).create_table("strict_table").types
|
|
791
|
-
{'enum_column':
|
|
788
|
+
{'enum_column': enum__7ba49365cc1b0fd57e61088b3bc9aa25}
|
|
792
789
|
"""
|
|
793
790
|
if self.model is not None:
|
|
794
791
|
self.database.create_table(name=name, model=self.model)
|
|
@@ -810,7 +807,7 @@ class Relation(Generic[ModelType]):
|
|
|
810
807
|
|
|
811
808
|
Examples:
|
|
812
809
|
>>> import patito as pt
|
|
813
|
-
>>> db = pt.Database()
|
|
810
|
+
>>> db = pt.duckdb.Database()
|
|
814
811
|
>>> df = pt.DataFrame({"column": ["A", "A", "B"]})
|
|
815
812
|
>>> relation = db.to_relation(df)
|
|
816
813
|
>>> relation.create_view("my_view")
|
|
@@ -822,9 +819,7 @@ class Relation(Generic[ModelType]):
|
|
|
822
819
|
│ str │
|
|
823
820
|
╞════════╡
|
|
824
821
|
│ A │
|
|
825
|
-
├╌╌╌╌╌╌╌╌┤
|
|
826
822
|
│ A │
|
|
827
|
-
├╌╌╌╌╌╌╌╌┤
|
|
828
823
|
│ B │
|
|
829
824
|
└────────┘
|
|
830
825
|
"""
|
|
@@ -840,7 +835,7 @@ class Relation(Generic[ModelType]):
|
|
|
840
835
|
|
|
841
836
|
Examples:
|
|
842
837
|
>>> import patito as pt
|
|
843
|
-
>>> relation = pt.Relation("select 1 as a, 2 as b, 3 as c")
|
|
838
|
+
>>> relation = pt.duckdb.Relation("select 1 as a, 2 as b, 3 as c")
|
|
844
839
|
>>> relation.columns
|
|
845
840
|
['a', 'b', 'c']
|
|
846
841
|
>>> relation.drop("c").columns
|
|
@@ -861,10 +856,10 @@ class Relation(Generic[ModelType]):
|
|
|
861
856
|
>>> import patito as pt
|
|
862
857
|
>>> df = pt.DataFrame(
|
|
863
858
|
... [[1, 2, 3], [1, 2, 3], [3, 2, 1]],
|
|
864
|
-
...
|
|
859
|
+
... schema=["a", "b", "c"],
|
|
865
860
|
... orient="row",
|
|
866
861
|
... )
|
|
867
|
-
>>> relation = pt.Relation(df)
|
|
862
|
+
>>> relation = pt.duckdb.Relation(df)
|
|
868
863
|
>>> relation.to_df()
|
|
869
864
|
shape: (3, 3)
|
|
870
865
|
┌─────┬─────┬─────┐
|
|
@@ -873,9 +868,7 @@ class Relation(Generic[ModelType]):
|
|
|
873
868
|
│ i64 ┆ i64 ┆ i64 │
|
|
874
869
|
╞═════╪═════╪═════╡
|
|
875
870
|
│ 1 ┆ 2 ┆ 3 │
|
|
876
|
-
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
877
871
|
│ 1 ┆ 2 ┆ 3 │
|
|
878
|
-
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
879
872
|
│ 3 ┆ 2 ┆ 1 │
|
|
880
873
|
└─────┴─────┴─────┘
|
|
881
874
|
>>> relation.distinct().to_df()
|
|
@@ -886,7 +879,6 @@ class Relation(Generic[ModelType]):
|
|
|
886
879
|
│ i64 ┆ i64 ┆ i64 │
|
|
887
880
|
╞═════╪═════╪═════╡
|
|
888
881
|
│ 1 ┆ 2 ┆ 3 │
|
|
889
|
-
├╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌┤
|
|
890
882
|
│ 3 ┆ 2 ┆ 1 │
|
|
891
883
|
└─────┴─────┴─────┘
|
|
892
884
|
"""
|
|
@@ -904,7 +896,9 @@ class Relation(Generic[ModelType]):
|
|
|
904
896
|
|
|
905
897
|
Example:
|
|
906
898
|
>>> import patito as pt
|
|
907
|
-
>>> relation_123 = pt.Relation(
|
|
899
|
+
>>> relation_123 = pt.duckdb.Relation(
|
|
900
|
+
... "select 1 union select 2 union select 3"
|
|
901
|
+
... )
|
|
908
902
|
>>> relation_123.order(by="1").to_df()
|
|
909
903
|
shape: (3, 1)
|
|
910
904
|
┌─────┐
|
|
@@ -913,12 +907,10 @@ class Relation(Generic[ModelType]):
|
|
|
913
907
|
│ i64 │
|
|
914
908
|
╞═════╡
|
|
915
909
|
│ 1 │
|
|
916
|
-
├╌╌╌╌╌┤
|
|
917
910
|
│ 2 │
|
|
918
|
-
├╌╌╌╌╌┤
|
|
919
911
|
│ 3 │
|
|
920
912
|
└─────┘
|
|
921
|
-
>>> relation_2 = pt.Relation("select 2")
|
|
913
|
+
>>> relation_2 = pt.duckdb.Relation("select 2")
|
|
922
914
|
>>> relation_2.to_df()
|
|
923
915
|
shape: (1, 1)
|
|
924
916
|
┌─────┐
|
|
@@ -936,7 +928,6 @@ class Relation(Generic[ModelType]):
|
|
|
936
928
|
│ i64 │
|
|
937
929
|
╞═════╡
|
|
938
930
|
│ 1 │
|
|
939
|
-
├╌╌╌╌╌┤
|
|
940
931
|
│ 3 │
|
|
941
932
|
└─────┘
|
|
942
933
|
"""
|
|
@@ -945,7 +936,7 @@ class Relation(Generic[ModelType]):
|
|
|
945
936
|
schema_change=False,
|
|
946
937
|
)
|
|
947
938
|
|
|
948
|
-
def execute(self) -> duckdb.
|
|
939
|
+
def execute(self) -> duckdb.DuckDBPyRelation:
|
|
949
940
|
"""
|
|
950
941
|
Execute built relation query and return result object.
|
|
951
942
|
|
|
@@ -954,11 +945,11 @@ class Relation(Generic[ModelType]):
|
|
|
954
945
|
|
|
955
946
|
Examples:
|
|
956
947
|
>>> import patito as pt
|
|
957
|
-
>>> relation = pt.Relation(
|
|
948
|
+
>>> relation = pt.duckdb.Relation(
|
|
958
949
|
... "select 1 as a, 2 as b union select 3 as a, 4 as b"
|
|
959
950
|
... )
|
|
960
951
|
>>> result = relation.aggregate("sum(a)", group_by="").execute()
|
|
961
|
-
>>> result.description
|
|
952
|
+
>>> result.description
|
|
962
953
|
[('sum(a)', 'NUMBER', None, None, None, None, None)]
|
|
963
954
|
>>> result.fetchall()
|
|
964
955
|
[(4,)]
|
|
@@ -989,7 +980,7 @@ class Relation(Generic[ModelType]):
|
|
|
989
980
|
>>> import patito as pt
|
|
990
981
|
>>> import polars as pl
|
|
991
982
|
>>> df = pt.DataFrame({"product_id": [1, 2, 3], "price": [10, 10, 20]})
|
|
992
|
-
>>> relation = pt.Relation(df).set_alias("my_relation")
|
|
983
|
+
>>> relation = pt.duckdb.Relation(df).set_alias("my_relation")
|
|
993
984
|
|
|
994
985
|
The ``.get()`` method will by default return a dynamically constructed
|
|
995
986
|
Patito model if no model has been associated with the given relation:
|
|
@@ -998,8 +989,8 @@ class Relation(Generic[ModelType]):
|
|
|
998
989
|
my_relation(product_id=1, price=10)
|
|
999
990
|
|
|
1000
991
|
If a Patito model has been associated with the relation, by the use of
|
|
1001
|
-
:ref:`Relation.set_model()<Relation.set_model>`, then the given model
|
|
1002
|
-
be used to represent the return type:
|
|
992
|
+
:ref:`Relation.set_model()<duckdb.Relation.set_model>`, then the given model
|
|
993
|
+
will be used to represent the return type:
|
|
1003
994
|
|
|
1004
995
|
>>> class Product(pt.Model):
|
|
1005
996
|
... product_id: int = pt.Field(unique=True)
|
|
@@ -1039,7 +1030,7 @@ class Relation(Generic[ModelType]):
|
|
|
1039
1030
|
else:
|
|
1040
1031
|
relation = self
|
|
1041
1032
|
result = relation.execute()
|
|
1042
|
-
row =
|
|
1033
|
+
row = result.fetchone()
|
|
1043
1034
|
if row is None or result.fetchone() is not None:
|
|
1044
1035
|
args = [repr(f) for f in filters]
|
|
1045
1036
|
args.extend(f"{key}={value!r}" for key, value in equalities.items())
|
|
@@ -1099,7 +1090,7 @@ class Relation(Generic[ModelType]):
|
|
|
1099
1090
|
... "string": ["A", "A", "B", "B"],
|
|
1100
1091
|
... }
|
|
1101
1092
|
... )
|
|
1102
|
-
>>> relation = pt.Relation(df)
|
|
1093
|
+
>>> relation = pt.duckdb.Relation(df)
|
|
1103
1094
|
>>> relation.filter("number % 2 = 0").to_df()
|
|
1104
1095
|
shape: (2, 2)
|
|
1105
1096
|
┌────────┬────────┐
|
|
@@ -1108,7 +1099,6 @@ class Relation(Generic[ModelType]):
|
|
|
1108
1099
|
│ i64 ┆ str │
|
|
1109
1100
|
╞════════╪════════╡
|
|
1110
1101
|
│ 2 ┆ A │
|
|
1111
|
-
├╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌┤
|
|
1112
1102
|
│ 4 ┆ B │
|
|
1113
1103
|
└────────┴────────┘
|
|
1114
1104
|
|
|
@@ -1143,8 +1133,8 @@ class Relation(Generic[ModelType]):
|
|
|
1143
1133
|
"""
|
|
1144
1134
|
Join relation with other relation source based on condition.
|
|
1145
1135
|
|
|
1146
|
-
See :ref:`Relation.inner_join() <Relation.inner_join>` and
|
|
1147
|
-
:ref:`Relation.left_join() <Relation.left_join>` for alternative method
|
|
1136
|
+
See :ref:`duckdb.Relation.inner_join() <duckdb.Relation.inner_join>` and
|
|
1137
|
+
:ref:`Relation.left_join() <duckdb.Relation.left_join>` for alternative method
|
|
1148
1138
|
shortcuts instead of using ``how``.
|
|
1149
1139
|
|
|
1150
1140
|
Args:
|
|
@@ -1165,14 +1155,14 @@ class Relation(Generic[ModelType]):
|
|
|
1165
1155
|
... "supplier_id": [2, 1, 3],
|
|
1166
1156
|
... }
|
|
1167
1157
|
... )
|
|
1168
|
-
>>> products = pt.Relation(products_df)
|
|
1158
|
+
>>> products = pt.duckdb.Relation(products_df)
|
|
1169
1159
|
>>> supplier_df = pt.DataFrame(
|
|
1170
1160
|
... {
|
|
1171
1161
|
... "id": [1, 2],
|
|
1172
1162
|
... "supplier_name": ["Banana Republic", "Applies Inc."],
|
|
1173
1163
|
... }
|
|
1174
1164
|
... )
|
|
1175
|
-
>>> suppliers = pt.Relation(supplier_df)
|
|
1165
|
+
>>> suppliers = pt.duckdb.Relation(supplier_df)
|
|
1176
1166
|
>>> products.set_alias("p").join(
|
|
1177
1167
|
... suppliers.set_alias("s"),
|
|
1178
1168
|
... on="p.supplier_id = s.id",
|
|
@@ -1185,7 +1175,6 @@ class Relation(Generic[ModelType]):
|
|
|
1185
1175
|
│ str ┆ i64 ┆ i64 ┆ str │
|
|
1186
1176
|
╞══════════════╪═════════════╪═════╪═════════════════╡
|
|
1187
1177
|
│ apple ┆ 2 ┆ 2 ┆ Applies Inc. │
|
|
1188
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1189
1178
|
│ banana ┆ 1 ┆ 1 ┆ Banana Republic │
|
|
1190
1179
|
└──────────────┴─────────────┴─────┴─────────────────┘
|
|
1191
1180
|
|
|
@@ -1201,9 +1190,7 @@ class Relation(Generic[ModelType]):
|
|
|
1201
1190
|
│ str ┆ i64 ┆ i64 ┆ str │
|
|
1202
1191
|
╞══════════════╪═════════════╪══════╪═════════════════╡
|
|
1203
1192
|
│ apple ┆ 2 ┆ 2 ┆ Applies Inc. │
|
|
1204
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1205
1193
|
│ banana ┆ 1 ┆ 1 ┆ Banana Republic │
|
|
1206
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1207
1194
|
│ oranges ┆ 3 ┆ null ┆ null │
|
|
1208
1195
|
└──────────────┴─────────────┴──────┴─────────────────┘
|
|
1209
1196
|
"""
|
|
@@ -1234,14 +1221,14 @@ class Relation(Generic[ModelType]):
|
|
|
1234
1221
|
... "supplier_id": [2, 1, 3],
|
|
1235
1222
|
... }
|
|
1236
1223
|
... )
|
|
1237
|
-
>>> products = pt.Relation(products_df)
|
|
1224
|
+
>>> products = pt.duckdb.Relation(products_df)
|
|
1238
1225
|
>>> supplier_df = pt.DataFrame(
|
|
1239
1226
|
... {
|
|
1240
1227
|
... "id": [1, 2],
|
|
1241
1228
|
... "supplier_name": ["Banana Republic", "Applies Inc."],
|
|
1242
1229
|
... }
|
|
1243
1230
|
... )
|
|
1244
|
-
>>> suppliers = pt.Relation(supplier_df)
|
|
1231
|
+
>>> suppliers = pt.duckdb.Relation(supplier_df)
|
|
1245
1232
|
>>> products.set_alias("p").inner_join(
|
|
1246
1233
|
... suppliers.set_alias("s"),
|
|
1247
1234
|
... on="p.supplier_id = s.id",
|
|
@@ -1253,7 +1240,6 @@ class Relation(Generic[ModelType]):
|
|
|
1253
1240
|
│ str ┆ i64 ┆ i64 ┆ str │
|
|
1254
1241
|
╞══════════════╪═════════════╪═════╪═════════════════╡
|
|
1255
1242
|
│ apple ┆ 2 ┆ 2 ┆ Applies Inc. │
|
|
1256
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1257
1243
|
│ banana ┆ 1 ┆ 1 ┆ Banana Republic │
|
|
1258
1244
|
└──────────────┴─────────────┴─────┴─────────────────┘
|
|
1259
1245
|
"""
|
|
@@ -1286,14 +1272,14 @@ class Relation(Generic[ModelType]):
|
|
|
1286
1272
|
... "supplier_id": [2, 1, 3],
|
|
1287
1273
|
... }
|
|
1288
1274
|
... )
|
|
1289
|
-
>>> products = pt.Relation(products_df)
|
|
1275
|
+
>>> products = pt.duckdb.Relation(products_df)
|
|
1290
1276
|
>>> supplier_df = pt.DataFrame(
|
|
1291
1277
|
... {
|
|
1292
1278
|
... "id": [1, 2],
|
|
1293
1279
|
... "supplier_name": ["Banana Republic", "Applies Inc."],
|
|
1294
1280
|
... }
|
|
1295
1281
|
... )
|
|
1296
|
-
>>> suppliers = pt.Relation(supplier_df)
|
|
1282
|
+
>>> suppliers = pt.duckdb.Relation(supplier_df)
|
|
1297
1283
|
>>> products.set_alias("p").left_join(
|
|
1298
1284
|
... suppliers.set_alias("s"),
|
|
1299
1285
|
... on="p.supplier_id = s.id",
|
|
@@ -1305,9 +1291,7 @@ class Relation(Generic[ModelType]):
|
|
|
1305
1291
|
│ str ┆ i64 ┆ i64 ┆ str │
|
|
1306
1292
|
╞══════════════╪═════════════╪══════╪═════════════════╡
|
|
1307
1293
|
│ apple ┆ 2 ┆ 2 ┆ Applies Inc. │
|
|
1308
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1309
1294
|
│ banana ┆ 1 ┆ 1 ┆ Banana Republic │
|
|
1310
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1311
1295
|
│ oranges ┆ 3 ┆ null ┆ null │
|
|
1312
1296
|
└──────────────┴─────────────┴──────┴─────────────────┘
|
|
1313
1297
|
"""
|
|
@@ -1335,10 +1319,10 @@ class Relation(Generic[ModelType]):
|
|
|
1335
1319
|
Example:
|
|
1336
1320
|
>>> import patito as pt
|
|
1337
1321
|
>>> relation = (
|
|
1338
|
-
... pt.Relation("select 1 as column")
|
|
1339
|
-
... + pt.Relation("select 2 as column")
|
|
1340
|
-
... + pt.Relation("select 3 as column")
|
|
1341
|
-
... + pt.Relation("select 4 as column")
|
|
1322
|
+
... pt.duckdb.Relation("select 1 as column")
|
|
1323
|
+
... + pt.duckdb.Relation("select 2 as column")
|
|
1324
|
+
... + pt.duckdb.Relation("select 3 as column")
|
|
1325
|
+
... + pt.duckdb.Relation("select 4 as column")
|
|
1342
1326
|
... )
|
|
1343
1327
|
>>> relation.limit(2).to_df()
|
|
1344
1328
|
shape: (2, 1)
|
|
@@ -1348,7 +1332,6 @@ class Relation(Generic[ModelType]):
|
|
|
1348
1332
|
│ i64 │
|
|
1349
1333
|
╞════════╡
|
|
1350
1334
|
│ 1 │
|
|
1351
|
-
├╌╌╌╌╌╌╌╌┤
|
|
1352
1335
|
│ 2 │
|
|
1353
1336
|
└────────┘
|
|
1354
1337
|
>>> relation.limit(2, offset=2).to_df()
|
|
@@ -1359,7 +1342,6 @@ class Relation(Generic[ModelType]):
|
|
|
1359
1342
|
│ i64 │
|
|
1360
1343
|
╞════════╡
|
|
1361
1344
|
│ 3 │
|
|
1362
|
-
├╌╌╌╌╌╌╌╌┤
|
|
1363
1345
|
│ 4 │
|
|
1364
1346
|
└────────┘
|
|
1365
1347
|
"""
|
|
@@ -1392,14 +1374,11 @@ class Relation(Generic[ModelType]):
|
|
|
1392
1374
|
│ str ┆ i64 │
|
|
1393
1375
|
╞═════════╪═════╡
|
|
1394
1376
|
│ Alice ┆ 20 │
|
|
1395
|
-
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1396
1377
|
│ Bob ┆ 20 │
|
|
1397
|
-
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1398
1378
|
│ Charles ┆ 30 │
|
|
1399
|
-
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1400
1379
|
│ Diana ┆ 35 │
|
|
1401
1380
|
└─────────┴─────┘
|
|
1402
|
-
>>> relation = pt.Relation(df)
|
|
1381
|
+
>>> relation = pt.duckdb.Relation(df)
|
|
1403
1382
|
>>> relation.order(by="age desc").to_df()
|
|
1404
1383
|
shape: (4, 2)
|
|
1405
1384
|
┌─────────┬─────┐
|
|
@@ -1408,11 +1387,8 @@ class Relation(Generic[ModelType]):
|
|
|
1408
1387
|
│ str ┆ i64 │
|
|
1409
1388
|
╞═════════╪═════╡
|
|
1410
1389
|
│ Diana ┆ 35 │
|
|
1411
|
-
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1412
1390
|
│ Charles ┆ 30 │
|
|
1413
|
-
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1414
1391
|
│ Alice ┆ 20 │
|
|
1415
|
-
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1416
1392
|
│ Bob ┆ 20 │
|
|
1417
1393
|
└─────────┴─────┘
|
|
1418
1394
|
>>> relation.order(by=["age desc", "name desc"]).to_df()
|
|
@@ -1423,11 +1399,8 @@ class Relation(Generic[ModelType]):
|
|
|
1423
1399
|
│ str ┆ i64 │
|
|
1424
1400
|
╞═════════╪═════╡
|
|
1425
1401
|
│ Diana ┆ 35 │
|
|
1426
|
-
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1427
1402
|
│ Charles ┆ 30 │
|
|
1428
|
-
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1429
1403
|
│ Bob ┆ 20 │
|
|
1430
|
-
├╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌┤
|
|
1431
1404
|
│ Alice ┆ 20 │
|
|
1432
1405
|
└─────────┴─────┘
|
|
1433
1406
|
"""
|
|
@@ -1456,7 +1429,7 @@ class Relation(Generic[ModelType]):
|
|
|
1456
1429
|
|
|
1457
1430
|
Examples:
|
|
1458
1431
|
>>> import patito as pt
|
|
1459
|
-
>>> db = pt.Database()
|
|
1432
|
+
>>> db = pt.duckdb.Database()
|
|
1460
1433
|
>>> db.to_relation("select 1 as a").create_table("my_table")
|
|
1461
1434
|
>>> db.table("my_table").to_df()
|
|
1462
1435
|
shape: (1, 1)
|
|
@@ -1476,7 +1449,6 @@ class Relation(Generic[ModelType]):
|
|
|
1476
1449
|
│ i64 │
|
|
1477
1450
|
╞═════╡
|
|
1478
1451
|
│ 1 │
|
|
1479
|
-
├╌╌╌╌╌┤
|
|
1480
1452
|
│ 2 │
|
|
1481
1453
|
└─────┘
|
|
1482
1454
|
"""
|
|
@@ -1509,7 +1481,7 @@ class Relation(Generic[ModelType]):
|
|
|
1509
1481
|
>>> import patito as pt
|
|
1510
1482
|
>>> df1 = pt.DataFrame({"a": [1, 1, 2], "b": [1, 1, 2]})
|
|
1511
1483
|
>>> df2 = pt.DataFrame({"a": [1, 1, 3], "b": [1, 1, 3]})
|
|
1512
|
-
>>> pt.Relation(df1).intersect(pt.Relation(df2)).to_df()
|
|
1484
|
+
>>> pt.duckdb.Relation(df1).intersect(pt.duckdb.Relation(df2)).to_df()
|
|
1513
1485
|
shape: (1, 2)
|
|
1514
1486
|
┌─────┬─────┐
|
|
1515
1487
|
│ a ┆ b │
|
|
@@ -1546,7 +1518,7 @@ class Relation(Generic[ModelType]):
|
|
|
1546
1518
|
|
|
1547
1519
|
Examples:
|
|
1548
1520
|
>>> import patito as pt
|
|
1549
|
-
>>> db = pt.Database()
|
|
1521
|
+
>>> db = pt.duckdb.Database()
|
|
1550
1522
|
>>> relation = db.to_relation(pt.DataFrame({"original_column": [1, 2, 3]}))
|
|
1551
1523
|
>>> relation.select("*").to_df()
|
|
1552
1524
|
shape: (3, 1)
|
|
@@ -1556,9 +1528,7 @@ class Relation(Generic[ModelType]):
|
|
|
1556
1528
|
│ i64 │
|
|
1557
1529
|
╞═════════════════╡
|
|
1558
1530
|
│ 1 │
|
|
1559
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1560
1531
|
│ 2 │
|
|
1561
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1562
1532
|
│ 3 │
|
|
1563
1533
|
└─────────────────┘
|
|
1564
1534
|
>>> relation.select("*", multiplied_column="2 * original_column").to_df()
|
|
@@ -1569,9 +1539,7 @@ class Relation(Generic[ModelType]):
|
|
|
1569
1539
|
│ i64 ┆ i64 │
|
|
1570
1540
|
╞═════════════════╪═══════════════════╡
|
|
1571
1541
|
│ 1 ┆ 2 │
|
|
1572
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1573
1542
|
│ 2 ┆ 4 │
|
|
1574
|
-
├╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┼╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┤
|
|
1575
1543
|
│ 3 ┆ 6 │
|
|
1576
1544
|
└─────────────────┴───────────────────┘
|
|
1577
1545
|
"""
|
|
@@ -1624,7 +1592,7 @@ class Relation(Generic[ModelType]):
|
|
|
1624
1592
|
|
|
1625
1593
|
Examples:
|
|
1626
1594
|
>>> import patito as pt
|
|
1627
|
-
>>> relation = pt.Relation("select 1 as a, 2 as b")
|
|
1595
|
+
>>> relation = pt.duckdb.Relation("select 1 as a, 2 as b")
|
|
1628
1596
|
>>> relation.rename(b="c").to_df().select(["a", "c"])
|
|
1629
1597
|
shape: (1, 2)
|
|
1630
1598
|
┌─────┬─────┐
|
|
@@ -1666,8 +1634,8 @@ class Relation(Generic[ModelType]):
|
|
|
1666
1634
|
|
|
1667
1635
|
Example:
|
|
1668
1636
|
>>> import patito as pt
|
|
1669
|
-
>>> relation_1 = pt.Relation("select 1 as a, 2 as b")
|
|
1670
|
-
>>> relation_2 = pt.Relation("select 1 as a, 3 as c")
|
|
1637
|
+
>>> relation_1 = pt.duckdb.Relation("select 1 as a, 2 as b")
|
|
1638
|
+
>>> relation_2 = pt.duckdb.Relation("select 1 as a, 3 as c")
|
|
1671
1639
|
>>> relation_1.set_alias("x").inner_join(
|
|
1672
1640
|
... relation_2.set_alias("y"),
|
|
1673
1641
|
... on="x.a = y.a",
|
|
@@ -1691,9 +1659,9 @@ class Relation(Generic[ModelType]):
|
|
|
1691
1659
|
Associate a give Patito model with the relation.
|
|
1692
1660
|
|
|
1693
1661
|
The returned relation has an associated ``.model`` attribute which can in turn
|
|
1694
|
-
be used by several methods such as :ref:`Relation.get()<Relation.get>`,
|
|
1695
|
-
:ref:`Relation.create_table()<Relation.create_table>`, and
|
|
1696
|
-
:ref:`Relation.__iter__<Relation.__iter__>`.
|
|
1662
|
+
be used by several methods such as :ref:`Relation.get()<duckdb.Relation.get>`,
|
|
1663
|
+
:ref:`Relation.create_table()<duckdb.Relation.create_table>`, and
|
|
1664
|
+
:ref:`Relation.__iter__<duckdb.Relation.__iter__>`.
|
|
1697
1665
|
|
|
1698
1666
|
Args:
|
|
1699
1667
|
model: A Patito Model class specifying the intended schema of the relation.
|
|
@@ -1708,16 +1676,18 @@ class Relation(Generic[ModelType]):
|
|
|
1708
1676
|
... float_column: float
|
|
1709
1677
|
... enum_column: Literal["A", "B", "C"]
|
|
1710
1678
|
...
|
|
1711
|
-
>>> relation = pt.Relation(
|
|
1679
|
+
>>> relation = pt.duckdb.Relation(
|
|
1680
|
+
... "select 1 as float_column, 'A' as enum_column"
|
|
1681
|
+
... )
|
|
1712
1682
|
>>> relation.get()
|
|
1713
1683
|
query_relation(float_column=1, enum_column='A')
|
|
1714
1684
|
>>> relation.set_model(MySchema).get()
|
|
1715
1685
|
MySchema(float_column=1.0, enum_column='A')
|
|
1716
1686
|
>>> relation.create_table("unmodeled_table").types
|
|
1717
|
-
{'float_column':
|
|
1687
|
+
{'float_column': INTEGER, 'enum_column': VARCHAR}
|
|
1718
1688
|
>>> relation.set_model(MySchema).create_table("modeled_table").types
|
|
1719
|
-
{'float_column':
|
|
1720
|
-
'enum_column':
|
|
1689
|
+
{'float_column': DOUBLE,
|
|
1690
|
+
'enum_column': enum__7ba49365cc1b0fd57e61088b3bc9aa25}
|
|
1721
1691
|
"""
|
|
1722
1692
|
# We are not able to annotate the generic instance of type(self)[type(model)]
|
|
1723
1693
|
# due to the lack of higher-kinded generics in python as of this writing.
|
|
@@ -1733,7 +1703,7 @@ class Relation(Generic[ModelType]):
|
|
|
1733
1703
|
)
|
|
1734
1704
|
|
|
1735
1705
|
@property
|
|
1736
|
-
def types(self)
|
|
1706
|
+
def types(self): # type: ignore[no-untyped-def] # noqa
|
|
1737
1707
|
"""
|
|
1738
1708
|
Return the SQL types of all the columns of the given relation.
|
|
1739
1709
|
|
|
@@ -1743,8 +1713,8 @@ class Relation(Generic[ModelType]):
|
|
|
1743
1713
|
|
|
1744
1714
|
Examples:
|
|
1745
1715
|
>>> import patito as pt
|
|
1746
|
-
>>> pt.Relation("select 1 as a, 'my_value' as b").types
|
|
1747
|
-
{'a':
|
|
1716
|
+
>>> pt.duckdb.Relation("select 1 as a, 'my_value' as b").types
|
|
1717
|
+
{'a': INTEGER, 'b': VARCHAR}
|
|
1748
1718
|
"""
|
|
1749
1719
|
return dict(zip(self.columns, self._relation.types))
|
|
1750
1720
|
|
|
@@ -1756,7 +1726,7 @@ class Relation(Generic[ModelType]):
|
|
|
1756
1726
|
|
|
1757
1727
|
Example:
|
|
1758
1728
|
>>> import patito as pt
|
|
1759
|
-
>>> pt.Relation("select 1 as column union select 2 as column").order(
|
|
1729
|
+
>>> pt.duckdb.Relation("select 1 as column union select 2 as column").order(
|
|
1760
1730
|
... by="1"
|
|
1761
1731
|
... ).to_pandas()
|
|
1762
1732
|
column
|
|
@@ -1773,7 +1743,7 @@ class Relation(Generic[ModelType]):
|
|
|
1773
1743
|
|
|
1774
1744
|
Example:
|
|
1775
1745
|
>>> import patito as pt
|
|
1776
|
-
>>> pt.Relation("select 1 as column union select 2 as column").order(
|
|
1746
|
+
>>> pt.duckdb.Relation("select 1 as column union select 2 as column").order(
|
|
1777
1747
|
... by="1"
|
|
1778
1748
|
... ).to_df()
|
|
1779
1749
|
shape: (2, 1)
|
|
@@ -1783,7 +1753,6 @@ class Relation(Generic[ModelType]):
|
|
|
1783
1753
|
│ i64 │
|
|
1784
1754
|
╞════════╡
|
|
1785
1755
|
│ 1 │
|
|
1786
|
-
├╌╌╌╌╌╌╌╌┤
|
|
1787
1756
|
│ 2 │
|
|
1788
1757
|
└────────┘
|
|
1789
1758
|
"""
|
|
@@ -1795,10 +1764,10 @@ class Relation(Generic[ModelType]):
|
|
|
1795
1764
|
# because polars is much more eager to store integer Series as 64-bit
|
|
1796
1765
|
# integers. Otherwise there must be done a lot of manual casting whenever
|
|
1797
1766
|
# you cross the boundary between DuckDB and polars.
|
|
1798
|
-
return DataFrame._from_arrow(arrow_table).
|
|
1767
|
+
return DataFrame._from_arrow(arrow_table).with_columns(
|
|
1799
1768
|
pl.col(pl.Int32).cast(pl.Int64)
|
|
1800
1769
|
)
|
|
1801
|
-
except pa.ArrowInvalid: # pragma: no cover
|
|
1770
|
+
except (pa.ArrowInvalid, pl.ArrowError): # pragma: no cover
|
|
1802
1771
|
# Empty relations with enum columns can sometimes produce errors.
|
|
1803
1772
|
# As a last-ditch effort, we convert such columns to VARCHAR.
|
|
1804
1773
|
casted_columns = [
|
|
@@ -1809,7 +1778,7 @@ class Relation(Generic[ModelType]):
|
|
|
1809
1778
|
]
|
|
1810
1779
|
non_enum_relation = self._relation.project(", ".join(casted_columns))
|
|
1811
1780
|
arrow_table = non_enum_relation.to_arrow_table()
|
|
1812
|
-
return DataFrame._from_arrow(arrow_table).
|
|
1781
|
+
return DataFrame._from_arrow(arrow_table).with_columns(
|
|
1813
1782
|
pl.col(pl.Int32).cast(pl.Int64)
|
|
1814
1783
|
)
|
|
1815
1784
|
|
|
@@ -1824,7 +1793,7 @@ class Relation(Generic[ModelType]):
|
|
|
1824
1793
|
|
|
1825
1794
|
Example:
|
|
1826
1795
|
>>> import patito as pt
|
|
1827
|
-
>>> relation = pt.Relation("select 1 as a union select 2 as a")
|
|
1796
|
+
>>> relation = pt.duckdb.Relation("select 1 as a union select 2 as a")
|
|
1828
1797
|
>>> relation.order(by="a").to_series()
|
|
1829
1798
|
shape: (2,)
|
|
1830
1799
|
Series: 'a' [i32]
|
|
@@ -1854,8 +1823,9 @@ class Relation(Generic[ModelType]):
|
|
|
1854
1823
|
Duplicates are `not` dropped.
|
|
1855
1824
|
|
|
1856
1825
|
Args:
|
|
1857
|
-
other: A ``patito.Relation`` object or something that can be
|
|
1858
|
-
``patito.Relation``.
|
|
1826
|
+
other: A ``patito.duckdb.Relation`` object or something that can be
|
|
1827
|
+
*casted* to ``patito.duckdb.Relation``.
|
|
1828
|
+
See :ref:`Relation<duckdb.Relation.__init__>`.
|
|
1859
1829
|
|
|
1860
1830
|
Returns:
|
|
1861
1831
|
New relation containing the rows of both ``self`` and ``other``.
|
|
@@ -1865,8 +1835,8 @@ class Relation(Generic[ModelType]):
|
|
|
1865
1835
|
|
|
1866
1836
|
Examples:
|
|
1867
1837
|
>>> import patito as pt
|
|
1868
|
-
>>> relation_1 = pt.Relation("select 1 as a")
|
|
1869
|
-
>>> relation_2 = pt.Relation("select 2 as a")
|
|
1838
|
+
>>> relation_1 = pt.duckdb.Relation("select 1 as a")
|
|
1839
|
+
>>> relation_2 = pt.duckdb.Relation("select 2 as a")
|
|
1870
1840
|
>>> relation_1.union(relation_2).to_df()
|
|
1871
1841
|
shape: (2, 1)
|
|
1872
1842
|
┌─────┐
|
|
@@ -1875,7 +1845,6 @@ class Relation(Generic[ModelType]):
|
|
|
1875
1845
|
│ i64 │
|
|
1876
1846
|
╞═════╡
|
|
1877
1847
|
│ 1 │
|
|
1878
|
-
├╌╌╌╌╌┤
|
|
1879
1848
|
│ 2 │
|
|
1880
1849
|
└─────┘
|
|
1881
1850
|
|
|
@@ -1887,7 +1856,6 @@ class Relation(Generic[ModelType]):
|
|
|
1887
1856
|
│ i64 │
|
|
1888
1857
|
╞═════╡
|
|
1889
1858
|
│ 1 │
|
|
1890
|
-
├╌╌╌╌╌┤
|
|
1891
1859
|
│ 2 │
|
|
1892
1860
|
└─────┘
|
|
1893
1861
|
"""
|
|
@@ -1928,7 +1896,7 @@ class Relation(Generic[ModelType]):
|
|
|
1928
1896
|
|
|
1929
1897
|
Examples:
|
|
1930
1898
|
>>> import patito as pt
|
|
1931
|
-
>>> db = pt.Database()
|
|
1899
|
+
>>> db = pt.duckdb.Database()
|
|
1932
1900
|
>>> relation = db.to_relation("select 1 as a, 2 as b")
|
|
1933
1901
|
>>> relation.with_columns(c="a + b").to_df()
|
|
1934
1902
|
shape: (1, 3)
|
|
@@ -1950,8 +1918,8 @@ class Relation(Generic[ModelType]):
|
|
|
1950
1918
|
"""
|
|
1951
1919
|
Add missing defaultable columns filled with the default values of correct type.
|
|
1952
1920
|
|
|
1953
|
-
Make sure to invoke :ref:`Relation.set_model()<Relation.set_model>` with
|
|
1954
|
-
correct model schema before executing
|
|
1921
|
+
Make sure to invoke :ref:`Relation.set_model()<duckdb.Relation.set_model>` with
|
|
1922
|
+
the correct model schema before executing
|
|
1955
1923
|
``Relation.with_missing_default_columns()``.
|
|
1956
1924
|
|
|
1957
1925
|
Args:
|
|
@@ -1972,7 +1940,7 @@ class Relation(Generic[ModelType]):
|
|
|
1972
1940
|
... default_column: int = 42
|
|
1973
1941
|
... another_default_column: int = 42
|
|
1974
1942
|
...
|
|
1975
|
-
>>> relation = pt.Relation(
|
|
1943
|
+
>>> relation = pt.duckdb.Relation(
|
|
1976
1944
|
... "select 1 as non_default_column, 2 as default_column"
|
|
1977
1945
|
... )
|
|
1978
1946
|
>>> relation.to_df()
|
|
@@ -2040,8 +2008,8 @@ class Relation(Generic[ModelType]):
|
|
|
2040
2008
|
"""
|
|
2041
2009
|
Add missing nullable columns filled with correctly typed nulls.
|
|
2042
2010
|
|
|
2043
|
-
Make sure to invoke :ref:`Relation.set_model()<Relation.set_model>` with
|
|
2044
|
-
correct model schema before executing
|
|
2011
|
+
Make sure to invoke :ref:`Relation.set_model()<duckdb.Relation.set_model>` with
|
|
2012
|
+
the correct model schema before executing
|
|
2045
2013
|
``Relation.with_missing_nullable_columns()``.
|
|
2046
2014
|
|
|
2047
2015
|
Args:
|
|
@@ -2062,7 +2030,7 @@ class Relation(Generic[ModelType]):
|
|
|
2062
2030
|
... nullable_column: Optional[int]
|
|
2063
2031
|
... another_nullable_column: Optional[int]
|
|
2064
2032
|
...
|
|
2065
|
-
>>> relation = pt.Relation("select 1 as nullable_column")
|
|
2033
|
+
>>> relation = pt.duckdb.Relation("select 1 as nullable_column")
|
|
2066
2034
|
>>> relation.to_df()
|
|
2067
2035
|
shape: (1, 1)
|
|
2068
2036
|
┌─────────────────┐
|
|
@@ -2122,7 +2090,7 @@ class Relation(Generic[ModelType]):
|
|
|
2122
2090
|
"""
|
|
2123
2091
|
Execute ``self.union(other)``.
|
|
2124
2092
|
|
|
2125
|
-
See :ref:`Relation.union()<Relation.union>` for full documentation.
|
|
2093
|
+
See :ref:`Relation.union()<duckdb.Relation.union>` for full documentation.
|
|
2126
2094
|
"""
|
|
2127
2095
|
return self.union(other)
|
|
2128
2096
|
|
|
@@ -2139,7 +2107,7 @@ class Relation(Generic[ModelType]):
|
|
|
2139
2107
|
"""
|
|
2140
2108
|
Return Relation with selected columns.
|
|
2141
2109
|
|
|
2142
|
-
Uses :ref:`Relation.select()<Relation.select>` under-the-hood in order to
|
|
2110
|
+
Uses :ref:`Relation.select()<duckdb.Relation.select>` under-the-hood in order to
|
|
2143
2111
|
perform the selection. Can technically be used to rename columns,
|
|
2144
2112
|
define derived columns, and so on, but prefer the use of Relation.select() for
|
|
2145
2113
|
such use cases.
|
|
@@ -2153,7 +2121,7 @@ class Relation(Generic[ModelType]):
|
|
|
2153
2121
|
|
|
2154
2122
|
Example:
|
|
2155
2123
|
>>> import patito as pt
|
|
2156
|
-
>>> relation = pt.Relation("select 1 as a, 2 as b, 3 as c")
|
|
2124
|
+
>>> relation = pt.duckdb.Relation("select 1 as a, 2 as b, 3 as c")
|
|
2157
2125
|
>>> relation.to_df()
|
|
2158
2126
|
shape: (1, 3)
|
|
2159
2127
|
┌─────┬─────┬─────┐
|
|
@@ -2192,9 +2160,9 @@ class Relation(Generic[ModelType]):
|
|
|
2192
2160
|
"""
|
|
2193
2161
|
Iterate over rows in relation.
|
|
2194
2162
|
|
|
2195
|
-
If :ref:`Relation.set_model()<Relation.set_model>` has been invoked
|
|
2196
|
-
given model will be used to deserialize each row. Otherwise a Patito
|
|
2197
|
-
is dynamically constructed which fits the schema of the relation.
|
|
2163
|
+
If :ref:`Relation.set_model()<duckdb.Relation.set_model>` has been invoked
|
|
2164
|
+
first, the given model will be used to deserialize each row. Otherwise a Patito
|
|
2165
|
+
model is dynamically constructed which fits the schema of the relation.
|
|
2198
2166
|
|
|
2199
2167
|
Returns:
|
|
2200
2168
|
Iterator[Model]: An iterator of patito Model objects representing each row.
|
|
@@ -2203,7 +2171,7 @@ class Relation(Generic[ModelType]):
|
|
|
2203
2171
|
>>> from typing import Literal
|
|
2204
2172
|
>>> import patito as pt
|
|
2205
2173
|
>>> df = pt.DataFrame({"float_column": [1, 2], "enum_column": ["A", "B"]})
|
|
2206
|
-
>>> relation = pt.Relation(df).set_alias("my_relation")
|
|
2174
|
+
>>> relation = pt.duckdb.Relation(df).set_alias("my_relation")
|
|
2207
2175
|
>>> for row in relation:
|
|
2208
2176
|
... print(row)
|
|
2209
2177
|
...
|
|
@@ -2239,7 +2207,7 @@ class Relation(Generic[ModelType]):
|
|
|
2239
2207
|
"""
|
|
2240
2208
|
Return the number of rows in the relation.
|
|
2241
2209
|
|
|
2242
|
-
See :ref:`Relation.count()<Relation.count>` for full documentation.
|
|
2210
|
+
See :ref:`Relation.count()<duckdb.Relation.count>` for full documentation.
|
|
2243
2211
|
"""
|
|
2244
2212
|
return self.count()
|
|
2245
2213
|
|
|
@@ -2251,7 +2219,7 @@ class Relation(Generic[ModelType]):
|
|
|
2251
2219
|
|
|
2252
2220
|
Example:
|
|
2253
2221
|
>>> import patito as pt
|
|
2254
|
-
>>> products = pt.Relation(
|
|
2222
|
+
>>> products = pt.duckdb.Relation(
|
|
2255
2223
|
... pt.DataFrame(
|
|
2256
2224
|
... {
|
|
2257
2225
|
... "product_name": ["apple", "red_apple", "banana", "oranges"],
|
|
@@ -2282,7 +2250,7 @@ class Relation(Generic[ModelType]):
|
|
|
2282
2250
|
banana 1
|
|
2283
2251
|
oranges 3
|
|
2284
2252
|
|
|
2285
|
-
>>> suppliers = pt.Relation(
|
|
2253
|
+
>>> suppliers = pt.duckdb.Relation(
|
|
2286
2254
|
... pt.DataFrame(
|
|
2287
2255
|
... {
|
|
2288
2256
|
... "id": [1, 2],
|
|
@@ -2370,7 +2338,7 @@ class Database:
|
|
|
2370
2338
|
|
|
2371
2339
|
Examples:
|
|
2372
2340
|
>>> import patito as pt
|
|
2373
|
-
>>> db = pt.Database()
|
|
2341
|
+
>>> db = pt.duckdb.Database()
|
|
2374
2342
|
>>> db.to_relation("select 1 as a, 2 as b").create_table("my_table")
|
|
2375
2343
|
>>> db.query("select * from my_table").to_df()
|
|
2376
2344
|
shape: (1, 2)
|
|
@@ -2398,12 +2366,12 @@ class Database:
|
|
|
2398
2366
|
Return the default DuckDB database.
|
|
2399
2367
|
|
|
2400
2368
|
Returns:
|
|
2401
|
-
A patito :ref:`Database<Database>` object wrapping around the given
|
|
2369
|
+
A patito :ref:`Database<duckdb.Database>` object wrapping around the given
|
|
2402
2370
|
connection.
|
|
2403
2371
|
|
|
2404
2372
|
Example:
|
|
2405
2373
|
>>> import patito as pt
|
|
2406
|
-
>>> db = pt.Database.default()
|
|
2374
|
+
>>> db = pt.duckdb.Database.default()
|
|
2407
2375
|
>>> db.query("select 1 as a, 2 as b").to_df()
|
|
2408
2376
|
shape: (1, 2)
|
|
2409
2377
|
┌─────┬─────┐
|
|
@@ -2428,13 +2396,14 @@ class Database:
|
|
|
2428
2396
|
``duckdb.connect()``.
|
|
2429
2397
|
|
|
2430
2398
|
Returns:
|
|
2431
|
-
A :ref:`Database<Database>` object wrapping around the given
|
|
2399
|
+
A :ref:`Database<duckdb.Database>` object wrapping around the given
|
|
2400
|
+
connection.
|
|
2432
2401
|
|
|
2433
2402
|
Example:
|
|
2434
2403
|
>>> import duckdb
|
|
2435
2404
|
>>> import patito as pt
|
|
2436
2405
|
>>> connection = duckdb.connect()
|
|
2437
|
-
>>> database = pt.Database.from_connection(connection)
|
|
2406
|
+
>>> database = pt.duckdb.Database.from_connection(connection)
|
|
2438
2407
|
"""
|
|
2439
2408
|
obj = cls.__new__(cls)
|
|
2440
2409
|
obj.connection = connection
|
|
@@ -2459,7 +2428,7 @@ class Database:
|
|
|
2459
2428
|
|
|
2460
2429
|
Example:
|
|
2461
2430
|
>>> import patito as pt
|
|
2462
|
-
>>> db = pt.Database()
|
|
2431
|
+
>>> db = pt.duckdb.Database()
|
|
2463
2432
|
>>> db.to_relation("select 1 as a, 2 as b").to_df()
|
|
2464
2433
|
shape: (1, 2)
|
|
2465
2434
|
┌─────┬─────┐
|
|
@@ -2477,7 +2446,6 @@ class Database:
|
|
|
2477
2446
|
│ i64 ┆ str │
|
|
2478
2447
|
╞═════╪═════╡
|
|
2479
2448
|
│ 3 ┆ 5 │
|
|
2480
|
-
├╌╌╌╌╌┼╌╌╌╌╌┤
|
|
2481
2449
|
│ 4 ┆ 6 │
|
|
2482
2450
|
└─────┴─────┘
|
|
2483
2451
|
"""
|
|
@@ -2503,7 +2471,7 @@ class Database:
|
|
|
2503
2471
|
|
|
2504
2472
|
Example:
|
|
2505
2473
|
>>> import patito as pt
|
|
2506
|
-
>>> db = pt.Database()
|
|
2474
|
+
>>> db = pt.duckdb.Database()
|
|
2507
2475
|
>>> db.execute("create table my_table (x bigint);")
|
|
2508
2476
|
>>> db.execute("insert into my_table values (1), (2), (3)")
|
|
2509
2477
|
>>> db.table("my_table").to_df()
|
|
@@ -2514,9 +2482,7 @@ class Database:
|
|
|
2514
2482
|
│ i64 │
|
|
2515
2483
|
╞═════╡
|
|
2516
2484
|
│ 1 │
|
|
2517
|
-
├╌╌╌╌╌┤
|
|
2518
2485
|
│ 2 │
|
|
2519
|
-
├╌╌╌╌╌┤
|
|
2520
2486
|
│ 3 │
|
|
2521
2487
|
└─────┘
|
|
2522
2488
|
|
|
@@ -2531,7 +2497,6 @@ class Database:
|
|
|
2531
2497
|
│ i64 │
|
|
2532
2498
|
╞═════╡
|
|
2533
2499
|
│ 1 │
|
|
2534
|
-
├╌╌╌╌╌┤
|
|
2535
2500
|
│ 3 │
|
|
2536
2501
|
└─────┘
|
|
2537
2502
|
|
|
@@ -2586,7 +2551,7 @@ class Database:
|
|
|
2586
2551
|
|
|
2587
2552
|
Example:
|
|
2588
2553
|
>>> import patito as pt
|
|
2589
|
-
>>> db = pt.Database()
|
|
2554
|
+
>>> db = pt.duckdb.Database()
|
|
2590
2555
|
>>> relation = db.query("select 1 as a, 2 as b, 3 as c")
|
|
2591
2556
|
>>> relation.to_df()
|
|
2592
2557
|
shape: (1, 3)
|
|
@@ -2628,7 +2593,7 @@ class Database:
|
|
|
2628
2593
|
... string_column: str
|
|
2629
2594
|
... bool_column: bool
|
|
2630
2595
|
...
|
|
2631
|
-
>>> db = pt.Database()
|
|
2596
|
+
>>> db = pt.duckdb.Database()
|
|
2632
2597
|
>>> empty_relation = db.empty_relation(Schema)
|
|
2633
2598
|
>>> empty_relation.to_df()
|
|
2634
2599
|
shape: (0, 2)
|
|
@@ -2663,7 +2628,7 @@ class Database:
|
|
|
2663
2628
|
Example:
|
|
2664
2629
|
>>> import patito as pt
|
|
2665
2630
|
>>> df = pt.DataFrame({"a": [1, 2], "b": [3, 4]})
|
|
2666
|
-
>>> db = pt.Database()
|
|
2631
|
+
>>> db = pt.duckdb.Database()
|
|
2667
2632
|
>>> relation = db.to_relation(df)
|
|
2668
2633
|
>>> relation.create_table(name="my_table")
|
|
2669
2634
|
>>> db.table("my_table").to_df()
|
|
@@ -2674,7 +2639,6 @@ class Database:
|
|
|
2674
2639
|
│ i64 ┆ i64 │
|
|
2675
2640
|
╞═════╪═════╡
|
|
2676
2641
|
│ 1 ┆ 3 │
|
|
2677
|
-
├╌╌╌╌╌┼╌╌╌╌╌┤
|
|
2678
2642
|
│ 2 ┆ 4 │
|
|
2679
2643
|
└─────┴─────┘
|
|
2680
2644
|
"""
|
|
@@ -2693,7 +2657,7 @@ class Database:
|
|
|
2693
2657
|
Example:
|
|
2694
2658
|
>>> import patito as pt
|
|
2695
2659
|
>>> df = pt.DataFrame({"a": [1, 2], "b": [3, 4]})
|
|
2696
|
-
>>> db = pt.Database()
|
|
2660
|
+
>>> db = pt.duckdb.Database()
|
|
2697
2661
|
>>> relation = db.to_relation(df)
|
|
2698
2662
|
>>> relation.create_view(name="my_view")
|
|
2699
2663
|
>>> db.view("my_view").to_df()
|
|
@@ -2704,7 +2668,6 @@ class Database:
|
|
|
2704
2668
|
│ i64 ┆ i64 │
|
|
2705
2669
|
╞═════╪═════╡
|
|
2706
2670
|
│ 1 ┆ 3 │
|
|
2707
|
-
├╌╌╌╌╌┼╌╌╌╌╌┤
|
|
2708
2671
|
│ 2 ┆ 4 │
|
|
2709
2672
|
└─────┴─────┘
|
|
2710
2673
|
"""
|
|
@@ -2721,11 +2684,11 @@ class Database:
|
|
|
2721
2684
|
"""
|
|
2722
2685
|
Create table with schema matching the provided Patito model.
|
|
2723
2686
|
|
|
2724
|
-
See :ref:`Relation.insert_into()<Relation.insert_into>` for how to insert
|
|
2725
|
-
into the table after creation.
|
|
2726
|
-
The :ref:`Relation.create_table()<Relation.create_table>` method can also
|
|
2727
|
-
used to create a table from a given relation `and` insert the data at the
|
|
2728
|
-
time.
|
|
2687
|
+
See :ref:`Relation.insert_into()<duckdb.Relation.insert_into>` for how to insert
|
|
2688
|
+
data into the table after creation.
|
|
2689
|
+
The :ref:`Relation.create_table()<duckdb.Relation.create_table>` method can also
|
|
2690
|
+
be used to create a table from a given relation `and` insert the data at the
|
|
2691
|
+
same time.
|
|
2729
2692
|
|
|
2730
2693
|
Args:
|
|
2731
2694
|
name: Name of new database table.
|
|
@@ -2741,10 +2704,10 @@ class Database:
|
|
|
2741
2704
|
... str_column: str
|
|
2742
2705
|
... nullable_string_column: Optional[str]
|
|
2743
2706
|
...
|
|
2744
|
-
>>> db = pt.Database()
|
|
2707
|
+
>>> db = pt.duckdb.Database()
|
|
2745
2708
|
>>> db.create_table(name="my_table", model=MyModel)
|
|
2746
2709
|
>>> db.table("my_table").types
|
|
2747
|
-
{'str_column':
|
|
2710
|
+
{'str_column': VARCHAR, 'nullable_string_column': VARCHAR}
|
|
2748
2711
|
"""
|
|
2749
2712
|
self.create_enum_types(model=model)
|
|
2750
2713
|
schema = model.schema()
|
|
@@ -2772,7 +2735,7 @@ class Database:
|
|
|
2772
2735
|
>>> class EnumModel(pt.Model):
|
|
2773
2736
|
... enum_column: Literal["A", "B", "C"]
|
|
2774
2737
|
...
|
|
2775
|
-
>>> db = pt.Database()
|
|
2738
|
+
>>> db = pt.duckdb.Database()
|
|
2776
2739
|
>>> db.create_enum_types(EnumModel)
|
|
2777
2740
|
>>> db.enum_types
|
|
2778
2741
|
{'enum__7ba49365cc1b0fd57e61088b3bc9aa25'}
|
|
@@ -2816,7 +2779,7 @@ class Database:
|
|
|
2816
2779
|
|
|
2817
2780
|
Examples:
|
|
2818
2781
|
>>> import patito as pt
|
|
2819
|
-
>>> db = pt.Database()
|
|
2782
|
+
>>> db = pt.duckdb.Database()
|
|
2820
2783
|
>>> "my_table" in db
|
|
2821
2784
|
False
|
|
2822
2785
|
>>> db.to_relation("select 1 as a, 2 as b").create_table(name="my_table")
|