mtsql 1.9.202401091637__py3-none-any.whl → 1.10.202401161934__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.
- mt/sql/base.py +0 -1
- mt/sql/psql.py +19 -0
- mt/sql/redshift.py +60 -1
- mt/sql/version.py +6 -6
- {mtsql-1.9.202401091637.dist-info → mtsql-1.10.202401161934.dist-info}/METADATA +3 -3
- mtsql-1.10.202401161934.dist-info/RECORD +12 -0
- mtsql-1.9.202401091637.dist-info/RECORD +0 -12
- {mtsql-1.9.202401091637.dist-info → mtsql-1.10.202401161934.dist-info}/LICENSE +0 -0
- {mtsql-1.9.202401091637.dist-info → mtsql-1.10.202401161934.dist-info}/WHEEL +0 -0
- {mtsql-1.9.202401091637.dist-info → mtsql-1.10.202401161934.dist-info}/top_level.txt +0 -0
mt/sql/base.py
CHANGED
mt/sql/psql.py
CHANGED
|
@@ -2038,3 +2038,22 @@ def readsync_table(
|
|
|
2038
2038
|
else:
|
|
2039
2039
|
pd.dfsave(df, df_filepath, index=True)
|
|
2040
2040
|
return df
|
|
2041
|
+
|
|
2042
|
+
|
|
2043
|
+
def list_stored_procedure():
|
|
2044
|
+
query = """SELECT
|
|
2045
|
+
n.nspname,
|
|
2046
|
+
b.usename,
|
|
2047
|
+
p.proname,
|
|
2048
|
+
p.prosrc
|
|
2049
|
+
FROM
|
|
2050
|
+
pg_catalog.pg_namespace n
|
|
2051
|
+
JOIN pg_catalog.pg_proc p ON
|
|
2052
|
+
pronamespace = n.oid
|
|
2053
|
+
join pg_user b on
|
|
2054
|
+
b.usesysid = p.proowner
|
|
2055
|
+
where
|
|
2056
|
+
nspname not in ('information_schema',
|
|
2057
|
+
'pg_catalog')
|
|
2058
|
+
"""
|
|
2059
|
+
pass
|
mt/sql/redshift.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Useful modules for accessing Redshift"""
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import sqlalchemy as sa
|
|
4
|
+
from mt import tp, np, pd, logg
|
|
4
5
|
|
|
5
6
|
from .base import *
|
|
6
7
|
from .psql import compliance_check
|
|
@@ -19,6 +20,7 @@ __api__ = [
|
|
|
19
20
|
"drop_matview",
|
|
20
21
|
"rename_column",
|
|
21
22
|
"drop_column",
|
|
23
|
+
"conform",
|
|
22
24
|
]
|
|
23
25
|
|
|
24
26
|
|
|
@@ -525,3 +527,60 @@ def to_sql(
|
|
|
525
527
|
)
|
|
526
528
|
|
|
527
529
|
return retval
|
|
530
|
+
|
|
531
|
+
|
|
532
|
+
def conform(
|
|
533
|
+
df: pd.DataFrame,
|
|
534
|
+
table_decl: sa.sql.schema.Table,
|
|
535
|
+
) -> pd.DataFrame:
|
|
536
|
+
"""Conforms a dataframe to a declarative base so that the columns are properly represented.
|
|
537
|
+
|
|
538
|
+
The idea is so that the output dataframe can be used to upload data to a Redshift DB. Primary
|
|
539
|
+
keys and indices are ignored. But whether an integer column is nullable or not is inspected.
|
|
540
|
+
|
|
541
|
+
Parameters
|
|
542
|
+
----------
|
|
543
|
+
df : pandas.DataFrame
|
|
544
|
+
input dataframe
|
|
545
|
+
table_decl : sqlalchemy.sql.schema.Table
|
|
546
|
+
the table declaration to conform to. The output columns are converted where possible to the
|
|
547
|
+
right dtype declared by the base. If you have a declarative base `x`, an instance of
|
|
548
|
+
:class:`sqlalchemy.orm.decl_api.DeclarativeMeta`, you can pass `x.__table__`.
|
|
549
|
+
|
|
550
|
+
Returns
|
|
551
|
+
-------
|
|
552
|
+
out_df : pandas.DataFrame
|
|
553
|
+
the output dataframe, where columns of the input dataframe are copied and converted properly
|
|
554
|
+
"""
|
|
555
|
+
|
|
556
|
+
# extract relevant columns
|
|
557
|
+
columns = [x.name for x in table_decl.columns]
|
|
558
|
+
df = df[columns].copy()
|
|
559
|
+
|
|
560
|
+
for x in table_decl.columns:
|
|
561
|
+
if isinstance(x.type, sa.BigInteger):
|
|
562
|
+
dtype = pd.Int64Dtype() if x.nullable else np.int64
|
|
563
|
+
elif isinstance(x.type, sa.Integer):
|
|
564
|
+
dtype = pd.Int32Dtype() if x.nullable else np.int32
|
|
565
|
+
elif isinstance(x.type, sa.SmallInteger):
|
|
566
|
+
dtype = pd.Int16Dtype() if x.nullable else np.int16
|
|
567
|
+
elif isinstance(x.type, sa.String):
|
|
568
|
+
dtype = str
|
|
569
|
+
elif isinstance(x.type, sa.Float):
|
|
570
|
+
dtype = float
|
|
571
|
+
elif isinstance(x.type, sa.REAL):
|
|
572
|
+
dtype = np.float32
|
|
573
|
+
elif isinstance(x.type, sa.Boolean):
|
|
574
|
+
dtype = pd.BooleanDtype() if x.nullable else np.bool
|
|
575
|
+
elif isinstance(x.type, sa.DateTime):
|
|
576
|
+
dtype = pd.Timestamp
|
|
577
|
+
else:
|
|
578
|
+
raise NotImplementedError(
|
|
579
|
+
"Unable to conform table declaration '{table_decl.name}' column '{x.name}' with type '{type(x.type)}'."
|
|
580
|
+
)
|
|
581
|
+
if dtype is pd.Timestamp:
|
|
582
|
+
df[x.name] = pd.to_datetime(df[x.name])
|
|
583
|
+
else:
|
|
584
|
+
df[x.name] = df[x.name].astype(dtype)
|
|
585
|
+
|
|
586
|
+
return df
|
mt/sql/version.py
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
VERSION_YEAR = 2024
|
|
2
2
|
VERSION_MONTH = int('01')
|
|
3
|
-
VERSION_DAY = int('
|
|
4
|
-
VERSION_HOUR = int('
|
|
5
|
-
VERSION_MINUTE = int('
|
|
3
|
+
VERSION_DAY = int('16')
|
|
4
|
+
VERSION_HOUR = int('19')
|
|
5
|
+
VERSION_MINUTE = int('34')
|
|
6
6
|
MAJOR_VERSION = 1
|
|
7
|
-
MINOR_VERSION =
|
|
8
|
-
PATCH_VERSION =
|
|
9
|
-
version_date = '2024/01/
|
|
7
|
+
MINOR_VERSION = 10
|
|
8
|
+
PATCH_VERSION = 202401161934
|
|
9
|
+
version_date = '2024/01/16 19:34'
|
|
10
10
|
version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
|
|
11
11
|
__all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version_date', 'version']
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: mtsql
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.10.202401161934
|
|
4
4
|
Summary: Extra Python modules to deal with the interaction between pandas dataframes and remote SQL servers, for Minh-Tri Pham
|
|
5
5
|
Home-page: https://github.com/inteplus/mtsql
|
|
6
6
|
Author: ['Minh-Tri Pham']
|
|
@@ -11,6 +11,6 @@ Requires-Dist: sqlalchemy
|
|
|
11
11
|
Requires-Dist: tzlocal
|
|
12
12
|
Requires-Dist: tqdm
|
|
13
13
|
Requires-Dist: psycopg2-binary
|
|
14
|
-
Requires-Dist: mtbase (>=4.
|
|
15
|
-
Requires-Dist: mtpandas (>=1.
|
|
14
|
+
Requires-Dist: mtbase (>=4.21)
|
|
15
|
+
Requires-Dist: mtpandas (>=1.15)
|
|
16
16
|
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
mt/sql/__init__.py,sha256=b7zO50apZxt9Hg2eOkJhRLrXgACR8eS5b-Rphdn5qNQ,44
|
|
2
|
+
mt/sql/base.py,sha256=ifWObR5YUu0yFmx1j0rDWD_hwf_Hd_JI5bcfNkeQ3lg,10572
|
|
3
|
+
mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
|
|
4
|
+
mt/sql/psql.py,sha256=tzsIN2XyBJX8t7p0D2yXgEQwUTkTcDzllI4HunCfq3s,66345
|
|
5
|
+
mt/sql/redshift.py,sha256=k7AJVlb6z5IqyOTQcYh_DuNtHK0879Vm5Wmv8afRols,17037
|
|
6
|
+
mt/sql/sqlite.py,sha256=T2ak_hhNi_zRfpg_gp8JhNHn7D2kl4i-Ey6-9ANMtz0,8678
|
|
7
|
+
mt/sql/version.py,sha256=uUdi7ZQkpbbCuDBZLgsh62wVnw77RSZFoKvrkk-hGAM,397
|
|
8
|
+
mtsql-1.10.202401161934.dist-info/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
|
|
9
|
+
mtsql-1.10.202401161934.dist-info/METADATA,sha256=IOvXw5DDAlLP2ccwPFBzQwV6Hx5c_b0KuOCp9xvVugI,592
|
|
10
|
+
mtsql-1.10.202401161934.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
11
|
+
mtsql-1.10.202401161934.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
|
|
12
|
+
mtsql-1.10.202401161934.dist-info/RECORD,,
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
mt/sql/__init__.py,sha256=b7zO50apZxt9Hg2eOkJhRLrXgACR8eS5b-Rphdn5qNQ,44
|
|
2
|
-
mt/sql/base.py,sha256=GJLSQfz0GNXgFBzK6dSCVqQ4rjyTvFEBPmsM37d8eXc,10608
|
|
3
|
-
mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
|
|
4
|
-
mt/sql/psql.py,sha256=m41LsBQ57OVVtakUZ01o_YY-vBwY5Z3TVPvSUMylNaU,65964
|
|
5
|
-
mt/sql/redshift.py,sha256=EliV4C9E3VuNjqFXWnTrU8Dm_utQrVwht5DF4oHl7qY,14808
|
|
6
|
-
mt/sql/sqlite.py,sha256=T2ak_hhNi_zRfpg_gp8JhNHn7D2kl4i-Ey6-9ANMtz0,8678
|
|
7
|
-
mt/sql/version.py,sha256=nb0i2eAMsoLqFeLpvANq9ovAtp3TRIZsz2c02XZ4xBs,396
|
|
8
|
-
mtsql-1.9.202401091637.dist-info/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
|
|
9
|
-
mtsql-1.9.202401091637.dist-info/METADATA,sha256=0OS_X0KCiNKKzDFiiXTnttkBWJSeS6OoEsdmykC4JAc,589
|
|
10
|
-
mtsql-1.9.202401091637.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
|
|
11
|
-
mtsql-1.9.202401091637.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
|
|
12
|
-
mtsql-1.9.202401091637.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|