patito 0.5.1__py3-none-any.whl → 0.6.2__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/sql.py DELETED
@@ -1,88 +0,0 @@
1
- """Module containing SQL generation utilities."""
2
- from typing import Dict, Optional, Union
3
-
4
- from typing_extensions import TypeAlias
5
-
6
- SQLLiteral: TypeAlias = Union[str, float, int, None]
7
-
8
-
9
- def sql_repr(value: SQLLiteral) -> str:
10
- """
11
- Convert python value to equivalent SQL literal value representation.
12
-
13
- Args:
14
- value: Python object which is convertible to an equivalent SQL value type.
15
-
16
- Returns:
17
- A SQL literal representation of the given value as a string.
18
- """
19
- return "null" if value is None else repr(value)
20
-
21
-
22
- class Case:
23
- """Class representing an SQL case statement."""
24
-
25
- def __init__(
26
- self,
27
- on_column: str,
28
- mapping: Dict[SQLLiteral, SQLLiteral],
29
- default: SQLLiteral,
30
- as_column: Optional[str] = None,
31
- ) -> None:
32
- """
33
- Map values of one column over to a new column.
34
-
35
- Args:
36
- on_column: Name of column defining the domain of the mapping.
37
- mapping: Dictionary defining the mapping. The dictionary keys represent the
38
- input values, while the dictionary values represent the output values.
39
- Items are inserted into the SQL case statement by their repr() string
40
- value. None is converted to SQL NULL.
41
- default: Default output value for inputs which have no provided mapping.
42
- If set to None, SQL NULL will be inserted as the default value.
43
- as_column: Name of column to insert the mapped values into. If not provided
44
- the SQL string expression will not end with "AS <as_column>".
45
-
46
- Examples:
47
- >>> import patito as pt
48
- >>> db = pt.duckdb.Database()
49
- >>> relation = db.to_relation("select 1 as a union select 2 as a")
50
- >>> case_statement = pt.sql.Case(
51
- ... on_column="a",
52
- ... mapping={1: "one", 2: "two"},
53
- ... default="three",
54
- ... as_column="b",
55
- ... )
56
- >>> relation.select(f"*, {case_statement}").order(by="a").to_df()
57
- shape: (2, 2)
58
- ┌─────┬─────┐
59
- │ a ┆ b │
60
- │ --- ┆ --- │
61
- │ i64 ┆ str │
62
- ╞═════╪═════╡
63
- │ 1 ┆ one │
64
- │ 2 ┆ two │
65
- └─────┴─────┘
66
- """
67
- self.on_column = on_column
68
- self.as_column = as_column
69
- self.mapping = {
70
- sql_repr(key): sql_repr(value) for key, value in mapping.items()
71
- }
72
- self.default_value = sql_repr(default)
73
- self.sql_string = f"case {self.on_column} " + (
74
- " ".join(f"when {key} then {value}" for key, value in self.mapping.items())
75
- + f" else {self.default_value} end"
76
- )
77
- if self.as_column:
78
- self.sql_string += f" as {as_column}"
79
-
80
- def __str__(self) -> str:
81
- """
82
- Return string representation of SQL case statement.
83
-
84
- Returns:
85
- String representing the case expression which can be directly inserted into
86
- an SQL query.
87
- """
88
- return self.sql_string
patito/xdg.py DELETED
@@ -1,22 +0,0 @@
1
- """Module implementing the XDG directory standard."""
2
- import os
3
- from pathlib import Path
4
- from typing import Optional
5
-
6
-
7
- def cache_home(application: Optional[str] = None) -> Path:
8
- """
9
- Return path to directory containing user-specific non-essential data files.
10
-
11
- Args:
12
- application: An optional name of an application for which to return an
13
- application-specific cache directory for.
14
-
15
- Returns:
16
- A path object pointing to a directory to store cache files.
17
- """
18
- path = Path(os.environ.get("XDG_CACHE_HOME", "~/.cache")).resolve()
19
- if application:
20
- path = path / application
21
- path.mkdir(exist_ok=True, parents=True)
22
- return path
@@ -1,14 +0,0 @@
1
- patito/__init__.py,sha256=J-p3aBiyNGdsyHxViEsP1C6bE-OxtxAul7xSA1xXpIE,1169
2
- patito/_docs.py,sha256=bobkmo8-RRdz80_KY53y_i1Gcp1WWTH5-D5ZHGidpok,161
3
- patito/database.py,sha256=IaxbsmyQMzL3KzvJUq0tgVGUxdr55KEv-wd1X673U2o,27917
4
- patito/duckdb.py,sha256=MnC4C7m3epXODz_eYBLqb7dTAcOh2o1Y8BViPoPKTaA,111015
5
- patito/exceptions.py,sha256=4WuaQJoc5wLUehhBRQPvL59LVFLcn_K806Z9fg0KBss,1262
6
- patito/polars.py,sha256=oFS8In6cUiKQu-QclkJ1Egxbf2HF2SlbTF76bcyE4Vo,26161
7
- patito/pydantic.py,sha256=HKQ6dfeeJCq1xaVJbqfo5UpF-WI_jBEaDRAy2tLnvtM,54832
8
- patito/sql.py,sha256=_xmvVfC1kUUq2d8KTBPExJmfZ9ec6uoMfZv52naFFkY,3218
9
- patito/validators.py,sha256=tnrDcBez8NKm05iM-xX0KAWUMkRyb7MamLTmcOdaHWY,10670
10
- patito/xdg.py,sha256=3EcUGcYBBUX2Secegajb4DB2QgAHNPs6oi0tMsL--UQ,686
11
- patito-0.5.1.dist-info/LICENSE,sha256=3bc4YyuF0e5nd59E3CsR8QM1Ua7pqKfC9DD1LVBVMs4,1139
12
- patito-0.5.1.dist-info/METADATA,sha256=32RQTd3B0V_L41TFkOdtUOXG5T7pxDLgOO7i1l2zonU,14569
13
- patito-0.5.1.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
14
- patito-0.5.1.dist-info/RECORD,,
File without changes