fakesnow 0.9.11__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 +24 -10
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.12.dist-info}/METADATA +1 -1
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.12.dist-info}/RECORD +7 -7
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.12.dist-info}/LICENSE +0 -0
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.12.dist-info}/WHEEL +0 -0
- {fakesnow-0.9.11.dist-info → fakesnow-0.9.12.dist-info}/entry_points.txt +0 -0
- {fakesnow-0.9.11.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
|
@@ -630,12 +629,7 @@ class FakeSnowflakeConnection:
|
|
630
629
|
df[col] = df[col].apply(lambda x: json.dumps(x) if isinstance(x, (dict, list)) else x)
|
631
630
|
|
632
631
|
escaped_cols = ",".join(f'"{col}"' for col in df.columns.to_list())
|
633
|
-
|
634
|
-
if schema:
|
635
|
-
table_name = f"{schema}.{table_name}"
|
636
|
-
if database:
|
637
|
-
name = f"{database}.{table_name}"
|
638
|
-
self._duck_conn.execute(f"INSERT INTO {name}({escaped_cols}) SELECT * FROM df")
|
632
|
+
self._duck_conn.execute(f"INSERT INTO {table_name}({escaped_cols}) SELECT * FROM df")
|
639
633
|
|
640
634
|
return self._duck_conn.fetchall()[0][0]
|
641
635
|
|
@@ -685,6 +679,15 @@ WritePandasResult = tuple[
|
|
685
679
|
]
|
686
680
|
|
687
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
|
+
|
688
691
|
def write_pandas(
|
689
692
|
conn: FakeSnowflakeConnection,
|
690
693
|
df: pd.DataFrame,
|
@@ -702,7 +705,18 @@ def write_pandas(
|
|
702
705
|
table_type: Literal["", "temp", "temporary", "transient"] = "",
|
703
706
|
**kwargs: Any,
|
704
707
|
) -> WritePandasResult:
|
705
|
-
|
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
|
706
720
|
|
707
721
|
# mocks https://docs.snowflake.com/en/sql-reference/sql/copy-into-table.html#output
|
708
722
|
mock_copy_results = [("fakesnow/file0.txt", "LOADED", count, count, 1, 0, None, None, None, None)]
|
@@ -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
|