-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #13 from pablominue/pablo-develop
Version 0.2.3
- Loading branch information
Showing
17 changed files
with
83 additions
and
15 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
""" | ||
Constant values for the queries package | ||
""" | ||
|
||
KEYWORDS = ["select", "from", "where", "group", "having", "order", "limit"] | ||
|
||
TYPE_MAPPING = { | ||
"object": "varchar", | ||
"int64": "int", | ||
"float64": "double", | ||
"bool": "bool", | ||
"datetime64": "timestamp", | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
""" | ||
This module allows to interact with tables in SQL (Create, Alter, etc) | ||
""" | ||
|
||
from typing import Any, Union | ||
|
||
import pandas as pd | ||
import sqlparse | ||
|
||
from .constants import TYPE_MAPPING | ||
|
||
|
||
class Table: | ||
def __init__(self, table: str, schema: Union[str, None] = None) -> None: | ||
self.table = table | ||
if schema: | ||
self.table = f"{schema}.{table}" | ||
|
||
def create_from_df(self, df: pd.DataFrame) -> str: | ||
columns = dict( | ||
zip( | ||
df.dtypes.index.to_list(), | ||
map( | ||
lambda x: TYPE_MAPPING[x], | ||
map(lambda x: str(x), df.dtypes.to_list()), | ||
), | ||
) | ||
) | ||
sql = f"CREATE TABLE {self.table} ( " | ||
for k, v in columns.items(): | ||
sql += f"{k} {v}, " | ||
sql = sql[:-2] + " )" | ||
return sqlparse.format(sql, encoding="utf-8") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters