fakesnow 0.9.10__py3-none-any.whl → 0.9.12__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.
- fakesnow/fakes.py +23 -4
- {fakesnow-0.9.10.dist-info → fakesnow-0.9.12.dist-info}/METADATA +2 -2
- {fakesnow-0.9.10.dist-info → fakesnow-0.9.12.dist-info}/RECORD +7 -7
- {fakesnow-0.9.10.dist-info → fakesnow-0.9.12.dist-info}/LICENSE +0 -0
- {fakesnow-0.9.10.dist-info → fakesnow-0.9.12.dist-info}/WHEEL +0 -0
- {fakesnow-0.9.10.dist-info → fakesnow-0.9.12.dist-info}/entry_points.txt +0 -0
- {fakesnow-0.9.10.dist-info → fakesnow-0.9.12.dist-info}/top_level.txt +0 -0
fakesnow/fakes.py
CHANGED
@@ -16,6 +16,7 @@ from sqlglot import exp
|
|
16
16
|
if TYPE_CHECKING:
|
17
17
|
import pandas as pd
|
18
18
|
import pyarrow.lib
|
19
|
+
import numpy as np
|
19
20
|
import pyarrow
|
20
21
|
import snowflake.connector.converter
|
21
22
|
import snowflake.connector.errors
|
@@ -606,9 +607,7 @@ class FakeSnowflakeConnection:
|
|
606
607
|
def rollback(self) -> None:
|
607
608
|
self.cursor().execute("ROLLBACK")
|
608
609
|
|
609
|
-
def _insert_df(
|
610
|
-
self, df: pd.DataFrame, table_name: str, database: str | None = None, schema: str | None = None
|
611
|
-
) -> int:
|
610
|
+
def _insert_df(self, df: pd.DataFrame, table_name: str) -> int:
|
612
611
|
# Objects in dataframes are written as parquet structs, and snowflake loads parquet structs as json strings.
|
613
612
|
# Whereas duckdb analyses a dataframe see https://duckdb.org/docs/api/python/data_ingestion.html#pandas-dataframes--object-columns
|
614
613
|
# and converts a object to the most specific type possible, eg: dict -> STRUCT, MAP or varchar, and list -> LIST
|
@@ -680,6 +679,15 @@ WritePandasResult = tuple[
|
|
680
679
|
]
|
681
680
|
|
682
681
|
|
682
|
+
def sql_type(dtype: np.dtype) -> str:
|
683
|
+
if str(dtype) == "int64":
|
684
|
+
return "NUMBER"
|
685
|
+
elif str(dtype) == "object":
|
686
|
+
return "VARCHAR"
|
687
|
+
else:
|
688
|
+
raise NotImplementedError(f"sql_type {dtype=}")
|
689
|
+
|
690
|
+
|
683
691
|
def write_pandas(
|
684
692
|
conn: FakeSnowflakeConnection,
|
685
693
|
df: pd.DataFrame,
|
@@ -697,7 +705,18 @@ def write_pandas(
|
|
697
705
|
table_type: Literal["", "temp", "temporary", "transient"] = "",
|
698
706
|
**kwargs: Any,
|
699
707
|
) -> WritePandasResult:
|
700
|
-
|
708
|
+
name = table_name
|
709
|
+
if schema:
|
710
|
+
name = f"{schema}.{name}"
|
711
|
+
if database:
|
712
|
+
name = f"{database}.{name}"
|
713
|
+
|
714
|
+
if auto_create_table:
|
715
|
+
cols = [f"{c} {sql_type(t)}" for c, t in df.dtypes.to_dict().items()]
|
716
|
+
|
717
|
+
conn.cursor().execute(f"CREATE TABLE IF NOT EXISTS {name} ({','.join(cols)})")
|
718
|
+
|
719
|
+
count = conn._insert_df(df, name) # noqa: SLF001
|
701
720
|
|
702
721
|
# mocks https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html#output
|
703
722
|
mock_copy_results = [("fakesnow/file0.txt", "LOADED", count, count, 1, 0, None, None, None, None)]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: fakesnow
|
3
|
-
Version: 0.9.
|
3
|
+
Version: 0.9.12
|
4
4
|
Summary: Fake Snowflake Connector for Python. Run, mock and test Snowflake DB locally.
|
5
5
|
License: Apache License
|
6
6
|
Version 2.0, January 2004
|
@@ -357,7 +357,7 @@ For more detail see [tests/test_fakes.py](tests/test_fakes.py)
|
|
357
357
|
## Caveats
|
358
358
|
|
359
359
|
- The order of rows is non deterministic and may not match Snowflake unless ORDER BY is fully specified.
|
360
|
-
- A more liberal Snowflake SQL dialect than a real Snowflake instance is supported, ie: some queries might pass using fakesnow that a real Snowflake instance would reject.
|
360
|
+
- A more liberal Snowflake SQL dialect than used by a real Snowflake instance is supported, ie: some queries might pass using fakesnow that a real Snowflake instance would reject.
|
361
361
|
|
362
362
|
## Contributing
|
363
363
|
|
@@ -3,16 +3,16 @@ fakesnow/__main__.py,sha256=GDrGyNTvBFuqn_UfDjKs7b3LPtU6gDv1KwosVDrukIM,76
|
|
3
3
|
fakesnow/checks.py,sha256=-QMvdcrRbhN60rnzxLBJ0IkUBWyLR8gGGKKmCS0w9mA,2383
|
4
4
|
fakesnow/cli.py,sha256=9qfI-Ssr6mo8UmIlXkUAOz2z2YPBgDsrEVaZv9FjGFs,2201
|
5
5
|
fakesnow/expr.py,sha256=CAxuYIUkwI339DQIBzvFF0F-m1tcVGKEPA5rDTzmH9A,892
|
6
|
-
fakesnow/fakes.py,sha256=
|
6
|
+
fakesnow/fakes.py,sha256=khqErSc7WkMPC61swcWgL2BORkdVcOdLqYeHm9fB1qM,29951
|
7
7
|
fakesnow/fixtures.py,sha256=G-NkVeruSQAJ7fvSS2fR2oysUn0Yra1pohHlOvacKEk,455
|
8
8
|
fakesnow/global_database.py,sha256=WTVIP1VhNvdCeX7TQncX1TRpGQU5rBf5Pbxim40zeSU,1399
|
9
9
|
fakesnow/info_schema.py,sha256=CdIcGXHEQ_kmEAzdQKvA-PX41LA6wlK-4p1J45qgKYA,6266
|
10
10
|
fakesnow/macros.py,sha256=pX1YJDnQOkFJSHYUjQ6ErEkYIKvFI6Ncz_au0vv1csA,265
|
11
11
|
fakesnow/py.typed,sha256=B-DLSjYBi7pkKjwxCSdpVj2J02wgfJr-E7B1wOUyxYU,80
|
12
12
|
fakesnow/transforms.py,sha256=oFNMsWygVz5-B98HMnrWznlxJoxl-DwoVCTdwHSdK_0,50670
|
13
|
-
fakesnow-0.9.
|
14
|
-
fakesnow-0.9.
|
15
|
-
fakesnow-0.9.
|
16
|
-
fakesnow-0.9.
|
17
|
-
fakesnow-0.9.
|
18
|
-
fakesnow-0.9.
|
13
|
+
fakesnow-0.9.12.dist-info/LICENSE,sha256=kW-7NWIyaRMQiDpryfSmF2DObDZHGR1cJZ39s6B1Svg,11344
|
14
|
+
fakesnow-0.9.12.dist-info/METADATA,sha256=B4fmpS455wOlCj82eQ32bhqRPtEWzmvj3EZ9kgbk8lA,17841
|
15
|
+
fakesnow-0.9.12.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
|
16
|
+
fakesnow-0.9.12.dist-info/entry_points.txt,sha256=2riAUgu928ZIHawtO8EsfrMEJhi-EH-z_Vq7Q44xKPM,47
|
17
|
+
fakesnow-0.9.12.dist-info/top_level.txt,sha256=500evXI1IFX9so82cizGIEMHAb_dJNPaZvd2H9dcKTA,24
|
18
|
+
fakesnow-0.9.12.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|