mtsql 1.12.10__py3-none-any.whl → 1.12.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.
mt/sql/base.py CHANGED
@@ -31,7 +31,7 @@ __all__ = [
31
31
 
32
32
 
33
33
  def frame_sql(frame_name, schema: tp.Optional[str] = None):
34
- return frame_name if schema is None else "{}.{}".format(schema, frame_name)
34
+ return frame_name if schema is None else f"{schema}.{frame_name}"
35
35
 
36
36
 
37
37
  def indices(df):
@@ -48,26 +48,26 @@ def run_func(
48
48
  *args,
49
49
  nb_trials: int = 3,
50
50
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
51
- **kwargs,
51
+ **kwds,
52
52
  ):
53
53
  """Attempt to run a function a number of times to overcome OperationalError exceptions.
54
54
 
55
55
  Parameters
56
56
  ----------
57
- func: function
57
+ func : function
58
58
  function to be invoked
59
- args: sequence
60
- arguments to be passed to the function
61
- nb_trials: int
59
+ nb_trials : int
62
60
  number of query trials
63
- logger: mt.logg.IndentedLoggerAdapter, optional
61
+ logger : mt.logg.IndentedLoggerAdapter, optional
64
62
  logger for debugging
65
- kwargs: dict
63
+ *args : iterable
64
+ arguments to be passed to the function
65
+ **kwds : dict
66
66
  keyword arguments to be passed to the function
67
67
  """
68
68
  for x in range(nb_trials):
69
69
  try:
70
- return func(*args, **kwargs)
70
+ return func(*args, **kwds)
71
71
  except (se.ProgrammingError, se.IntegrityError):
72
72
  raise
73
73
  except (
@@ -92,10 +92,10 @@ def conn_ctx(engine):
92
92
  return ctx.nullcontext(engine)
93
93
 
94
94
 
95
- def engine_execute(engine, sql, *args, **kwargs):
95
+ def engine_execute(engine, sql, *args, **kwds):
96
96
  text_sql = sa.text(sql) if isinstance(sql, str) else sql
97
97
  with conn_ctx(engine) as conn:
98
- return conn.execute(text_sql, *args, **kwargs)
98
+ return conn.execute(text_sql, *args, **kwds)
99
99
 
100
100
 
101
101
  def trim_sql_query(sql_query: str) -> str:
@@ -112,7 +112,7 @@ def read_sql(
112
112
  nb_trials: int = 3,
113
113
  exception_handling: str = "raise",
114
114
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
115
- **kwargs,
115
+ **kwds,
116
116
  ) -> pd.DataFrame:
117
117
  """Read an SQL query with a number of trials to overcome OperationalError.
118
118
 
@@ -165,7 +165,7 @@ def read_sql(
165
165
  text_sql = trim_sql_query(text_sql)
166
166
 
167
167
  if chunksize is not None:
168
- s = "read_sql: '{}'".format(text_sql)
168
+ s = f"read_sql: '{text_sql}'"
169
169
  spinner = halo.Halo(s, spinner="dots", enabled=bool(logger))
170
170
  spinner.start()
171
171
  ts = pd.Timestamp.now()
@@ -180,7 +180,7 @@ def read_sql(
180
180
  chunksize=chunksize,
181
181
  nb_trials=nb_trials,
182
182
  logger=logger,
183
- **kwargs,
183
+ **kwds,
184
184
  )
185
185
 
186
186
  if chunksize is None:
@@ -192,24 +192,21 @@ def read_sql(
192
192
  dfs.append(df)
193
193
  cnt += len(df)
194
194
  td = (pd.Timestamp.now() - ts).total_seconds() + 0.001
195
- s = "{} rows ({} rows/sec)".format(cnt, cnt / td)
195
+ s = f"{cnt} rows ({cnt / td} rows/sec)"
196
196
  spinner.text = s
197
197
  df = pd.concat(dfs)
198
- s = "{} rows".format(cnt)
198
+ s = f"{cnt} rows"
199
199
  spinner.succeed(s)
200
200
  except:
201
- s = "{} rows".format(cnt)
201
+ s = f"{cnt} rows"
202
202
  spinner.fail(s)
203
203
  if logger:
204
204
  logger.warn_last_exception()
205
205
  if exception_handling == "raise":
206
206
  raise
207
207
  if exception_handling != "warn":
208
- raise ValueError(
209
- "Unknown value for argument 'exception_handling': '{}'.".format(
210
- exception_handling
211
- )
212
- )
208
+ msg = f"Unknown value for argument 'exception_handling': '{exception_handling}'."
209
+ raise ValueError(msg)
213
210
  df = pd.concat(dfs)
214
211
 
215
212
  return df
@@ -220,7 +217,7 @@ def read_sql_table(
220
217
  engine,
221
218
  nb_trials: int = 3,
222
219
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
223
- **kwargs,
220
+ **kwds,
224
221
  ):
225
222
  """Read an SQL table with a number of trials to overcome OperationalError.
226
223
 
@@ -246,7 +243,7 @@ def read_sql_table(
246
243
  engine,
247
244
  nb_trials=nb_trials,
248
245
  logger=logger,
249
- **kwargs,
246
+ **kwds,
250
247
  )
251
248
 
252
249
 
@@ -256,7 +253,7 @@ def exec_sql(
256
253
  *args,
257
254
  nb_trials: int = 3,
258
255
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
259
- **kwargs,
256
+ **kwds,
260
257
  ):
261
258
  """Execute an SQL query with a number of trials to overcome OperationalError.
262
259
 
@@ -280,7 +277,7 @@ def exec_sql(
280
277
  """
281
278
 
282
279
  return run_func(
283
- engine_execute, engine, sql, *args, nb_trials=nb_trials, logger=logger, **kwargs
280
+ engine_execute, engine, sql, *args, nb_trials=nb_trials, logger=logger, **kwds
284
281
  )
285
282
 
286
283
 
mt/sql/psql.py CHANGED
@@ -197,7 +197,7 @@ def to_sql(
197
197
  if_exists="fail",
198
198
  nb_trials: int = 3,
199
199
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
200
- **kwargs,
200
+ **kwds,
201
201
  ):
202
202
  """Writes records stored in a DataFrame to a PostgreSQL database.
203
203
 
@@ -222,6 +222,8 @@ def to_sql(
222
222
  number of query trials
223
223
  logger: mt.logg.IndentedLoggerAdapter, optional
224
224
  logger for debugging
225
+ **kwds : dict
226
+ other keyword arguments to be passed as-is to :func:`pandas.DataFrame.to_sql`
225
227
 
226
228
  Raises
227
229
  ------
@@ -241,12 +243,12 @@ def to_sql(
241
243
 
242
244
  """
243
245
 
244
- if kwargs:
245
- if "index" in kwargs:
246
+ if kwds:
247
+ if "index" in kwds:
246
248
  raise ValueError(
247
249
  "The `mt.sql.psql.to_sql()` function does not accept `index` as a keyword."
248
250
  )
249
- if "index_label" in kwargs:
251
+ if "index_label" in kwds:
250
252
  raise ValueError(
251
253
  "This `mt.sql.psql.to_sql()` function does not accept `index_label` as a keyword."
252
254
  )
@@ -274,7 +276,7 @@ def to_sql(
274
276
  index_label=None,
275
277
  nb_trials=nb_trials,
276
278
  logger=logger,
277
- **kwargs,
279
+ **kwds,
278
280
  )
279
281
  retval = run_func(
280
282
  df.to_sql,
@@ -286,7 +288,7 @@ def to_sql(
286
288
  index_label=None,
287
289
  nb_trials=nb_trials,
288
290
  logger=logger,
289
- **kwargs,
291
+ **kwds,
290
292
  )
291
293
  if if_exists == "replace":
292
294
  query_str = "ALTER TABLE {} ADD PRIMARY KEY ({});".format(
@@ -346,7 +348,7 @@ def to_sql(
346
348
  index_label=None,
347
349
  nb_trials=nb_trials,
348
350
  logger=logger,
349
- **kwargs,
351
+ **kwds,
350
352
  )
351
353
 
352
354
 
@@ -485,7 +485,7 @@ class TIMESTAMPTZ(RedshiftTypeEngine, sa.dialects.postgresql.TIMESTAMP):
485
485
 
486
486
  def __init__(self, timezone=True, precision=None):
487
487
  # timezone param must be present as it's provided in base class so the
488
- # object can be instantiated with kwargs. see
488
+ # object can be instantiated with kwds. see
489
489
  # :meth:`~sqlalchemy.dialects.postgresql.base.PGDialect._get_column_info`
490
490
  super(TIMESTAMPTZ, self).__init__(timezone=True, precision=precision)
491
491
 
@@ -506,7 +506,7 @@ class TIMETZ(RedshiftTypeEngine, sa.dialects.postgresql.TIME):
506
506
 
507
507
  def __init__(self, timezone=True, precision=None):
508
508
  # timezone param must be present as it's provided in base class so the
509
- # object can be instantiated with kwargs. see
509
+ # object can be instantiated with kwds. see
510
510
  # :meth:`~sqlalchemy.dialects.postgresql.base.PGDialect._get_column_info`
511
511
  super(TIMETZ, self).__init__(timezone=True, precision=precision)
512
512
 
@@ -747,12 +747,12 @@ class RedshiftDDLCompiler(PGDDLCompiler):
747
747
  """
748
748
 
749
749
  def post_create_table(self, table):
750
- kwargs = ["diststyle", "distkey", "sortkey", "interleaved_sortkey"]
750
+ kwds = ["diststyle", "distkey", "sortkey", "interleaved_sortkey"]
751
751
  info = table.dialect_options["mtsql_redshift"]
752
- info = {key: info.get(key) for key in kwargs}
752
+ info = {key: info.get(key) for key in kwds}
753
753
  return get_table_attributes(self.preparer, **info)
754
754
 
755
- def get_column_specification(self, column, **kwargs):
755
+ def get_column_specification(self, column, **kwds):
756
756
  colspec = self.preparer.format_column(column)
757
757
 
758
758
  colspec += " " + self.dialect.type_compiler.process(column.type)
@@ -1156,8 +1156,8 @@ class RedshiftDialectMixin(DefaultDialect):
1156
1156
  relation_names.append(key.name)
1157
1157
  return relation_names
1158
1158
 
1159
- def _get_column_info(self, *args, **kwargs):
1160
- kw = kwargs.copy()
1159
+ def _get_column_info(self, *args, **kwds):
1160
+ kw = kwds.copy()
1161
1161
  encode = kw.pop("encode", None)
1162
1162
  if sa_version >= Version("1.3.16"):
1163
1163
  # SQLAlchemy 1.3.16 introduced generated columns,
@@ -1422,8 +1422,8 @@ class RedshiftDialect(RedshiftDialectMixin, PGDialect):
1422
1422
  supports_statement_cache = False
1423
1423
  use_setinputsizes = False # not implemented in redshift_connector
1424
1424
 
1425
- def __init__(self, client_encoding=None, **kwargs):
1426
- super(RedshiftDialect, self).__init__(client_encoding=client_encoding, **kwargs)
1425
+ def __init__(self, client_encoding=None, **kwds):
1426
+ super(RedshiftDialect, self).__init__(client_encoding=client_encoding, **kwds)
1427
1427
  self.client_encoding = client_encoding
1428
1428
 
1429
1429
  @classmethod
@@ -1523,7 +1523,7 @@ class RedshiftDialect(RedshiftDialectMixin, PGDialect):
1523
1523
  else:
1524
1524
  return None
1525
1525
 
1526
- def create_connect_args(self, *args, **kwargs):
1526
+ def create_connect_args(self, *args, **kwds):
1527
1527
  """
1528
1528
  Build DB-API compatible connection arguments.
1529
1529
 
@@ -1536,7 +1536,7 @@ class RedshiftDialect(RedshiftDialectMixin, PGDialect):
1536
1536
  "application_name": "sqlalchemy-redshift",
1537
1537
  }
1538
1538
  cargs, cparams = super(RedshiftDialectMixin, self).create_connect_args(
1539
- *args, **kwargs
1539
+ *args, **kwds
1540
1540
  )
1541
1541
  # set client_encoding so it is picked up by on_connect(), as
1542
1542
  # redshift_connector does not have client_encoding connection parameter
@@ -1570,7 +1570,7 @@ def gen_columns_from_children(root):
1570
1570
 
1571
1571
 
1572
1572
  @compiles(Delete, "redshift")
1573
- def visit_delete_stmt(element, compiler, **kwargs):
1573
+ def visit_delete_stmt(element, compiler, **kwds):
1574
1574
  """
1575
1575
  Adds redshift-dialect specific compilation rule for the
1576
1576
  delete statement.
@@ -1635,25 +1635,25 @@ def visit_delete_stmt(element, compiler, **kwargs):
1635
1635
  # note:
1636
1636
  # the tables in the using clause are sorted in the order in
1637
1637
  # which they first appear in the where clause.
1638
- delete_stmt_table = compiler.process(element.table, asfrom=True, **kwargs)
1638
+ delete_stmt_table = compiler.process(element.table, asfrom=True, **kwds)
1639
1639
 
1640
1640
  if sa_version >= Version("1.4.0"):
1641
1641
  if element.whereclause is not None:
1642
- clause = compiler.process(element.whereclause, **kwargs)
1642
+ clause = compiler.process(element.whereclause, **kwds)
1643
1643
  if clause:
1644
1644
  whereclause = " WHERE {clause}".format(clause=clause)
1645
1645
  else:
1646
1646
  whereclause_tuple = element.get_children()
1647
1647
  if whereclause_tuple:
1648
1648
  whereclause = " WHERE {clause}".format(
1649
- clause=compiler.process(*whereclause_tuple, **kwargs)
1649
+ clause=compiler.process(*whereclause_tuple, **kwds)
1650
1650
  )
1651
1651
 
1652
1652
  if whereclause:
1653
1653
  usingclause_tables = []
1654
1654
  whereclause_columns = gen_columns_from_children(element)
1655
1655
  for col in whereclause_columns:
1656
- table = compiler.process(col.table, asfrom=True, **kwargs)
1656
+ table = compiler.process(col.table, asfrom=True, **kwds)
1657
1657
  if table != delete_stmt_table and table not in usingclause_tables:
1658
1658
  usingclause_tables.append(table)
1659
1659
  if usingclause_tables:
mt/sql/redshift/main.py CHANGED
@@ -418,7 +418,7 @@ def to_sql(
418
418
  if_exists="fail",
419
419
  nb_trials: int = 3,
420
420
  logger: tp.Optional[logg.IndentedLoggerAdapter] = None,
421
- **kwargs,
421
+ **kwds,
422
422
  ):
423
423
  """Writes records stored in a DataFrame to a Redshift database.
424
424
 
@@ -440,7 +440,7 @@ def to_sql(
440
440
  number of query trials
441
441
  logger: mt.logg.IndentedLoggerAdapter, optional
442
442
  logger for debugging
443
- kwargs : dict
443
+ **kwds : dict
444
444
  keyword arguments passed as-is to :func:`pandas.DataFrame.to_sql`
445
445
 
446
446
  Raises
@@ -460,12 +460,12 @@ def to_sql(
460
460
 
461
461
  """
462
462
 
463
- if kwargs:
464
- if "index" in kwargs:
463
+ if kwds:
464
+ if "index" in kwds:
465
465
  raise ValueError(
466
466
  "The `mt.sql.psql.to_sql()` function does not accept `index` as a keyword."
467
467
  )
468
- if "index_label" in kwargs:
468
+ if "index_label" in kwds:
469
469
  raise ValueError(
470
470
  "This `mt.sql.psql.to_sql()` function does not accept `index_label` as a keyword."
471
471
  )
@@ -490,7 +490,7 @@ def to_sql(
490
490
  index_label=None,
491
491
  nb_trials=nb_trials,
492
492
  logger=logger,
493
- **kwargs,
493
+ **kwds,
494
494
  )
495
495
 
496
496
  if if_exists == "replace":
@@ -507,7 +507,7 @@ def to_sql(
507
507
  index_label=None,
508
508
  nb_trials=nb_trials,
509
509
  logger=logger,
510
- **kwargs,
510
+ **kwds,
511
511
  )
512
512
 
513
513
  return retval
mt/sql/version.py CHANGED
@@ -1,5 +1,5 @@
1
1
  MAJOR_VERSION = 1
2
2
  MINOR_VERSION = 12
3
- PATCH_VERSION = 10
3
+ PATCH_VERSION = 12
4
4
  version = '{}.{}.{}'.format(MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION)
5
5
  __all__ = ['MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_VERSION', 'version']
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mtsql
3
- Version: 1.12.10
3
+ Version: 1.12.12
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']
@@ -0,0 +1,17 @@
1
+ mt/sql/__init__.py,sha256=b7zO50apZxt9Hg2eOkJhRLrXgACR8eS5b-Rphdn5qNQ,44
2
+ mt/sql/base.py,sha256=rEDlXivxH06ZsdpSXkraiqBCDDYh3FLVZfuH-spVw8w,12976
3
+ mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
4
+ mt/sql/psql.py,sha256=w5klr_2lUZnAFee-Fzbn3G8jdYcf_iX4N_GfAGIdsMI,66670
5
+ mt/sql/sqlite.py,sha256=T2ak_hhNi_zRfpg_gp8JhNHn7D2kl4i-Ey6-9ANMtz0,8678
6
+ mt/sql/version.py,sha256=7Ierb-IwvIgb7So3QUVyOb206Eut5KTX02AND5UIhfc,208
7
+ mt/sql/redshift/__init__.py,sha256=S-eRxJWcrvncF7LZXuulCdPV-UERu9eiw6uyDb5aGsM,443
8
+ mt/sql/redshift/commands.py,sha256=xhGUBf3bL66EYdZI5HCUtOx-XqPCnXT_P-LnhPgtzrY,40193
9
+ mt/sql/redshift/ddl.py,sha256=eUcZj9oIajiE1wKKBAP-V64gYJ7cVnSAt8dLFfluOJA,9777
10
+ mt/sql/redshift/dialect.py,sha256=-0JjJubZZHRw0abhl6H6rKWaUE9pKtGwAuX-62T0e_c,53399
11
+ mt/sql/redshift/main.py,sha256=H8_5sjtJ7dzWoCMXzPNjYhrMQ18eLUQ9xg-aYl5QeTc,17104
12
+ mt/sql/redshift/redshift-ca-bundle.crt,sha256=532qYkOpQOstFE0mdXE1GVtL3v00XDKgZNTr6gK5-KE,8621
13
+ mtsql-1.12.12.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
14
+ mtsql-1.12.12.dist-info/METADATA,sha256=pDALCX7SklLIq1omFMmUKOx9cYkaBVXHTYXXDIFmaE8,740
15
+ mtsql-1.12.12.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
+ mtsql-1.12.12.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
17
+ mtsql-1.12.12.dist-info/RECORD,,
@@ -1,17 +0,0 @@
1
- mt/sql/__init__.py,sha256=b7zO50apZxt9Hg2eOkJhRLrXgACR8eS5b-Rphdn5qNQ,44
2
- mt/sql/base.py,sha256=k7yav8JVP-Z0hqlsSuKmzm_HKYtq7dFtpaLhyhgyc7k,13088
3
- mt/sql/mysql.py,sha256=n2ENDctdUqZuSaDAcrqZYtPtawq3Wx4dOPCRsCB5Q4w,4894
4
- mt/sql/psql.py,sha256=dNPOvJBxZ8S88uOmIKnfjo1ssRiMLDLwVeJcVcdcNco,66580
5
- mt/sql/sqlite.py,sha256=T2ak_hhNi_zRfpg_gp8JhNHn7D2kl4i-Ey6-9ANMtz0,8678
6
- mt/sql/version.py,sha256=BgX8JcjmUH-qTZ5xTJECQnYYXE0gZHb8rHFgiprkJMs,208
7
- mt/sql/redshift/__init__.py,sha256=S-eRxJWcrvncF7LZXuulCdPV-UERu9eiw6uyDb5aGsM,443
8
- mt/sql/redshift/commands.py,sha256=xhGUBf3bL66EYdZI5HCUtOx-XqPCnXT_P-LnhPgtzrY,40193
9
- mt/sql/redshift/ddl.py,sha256=eUcZj9oIajiE1wKKBAP-V64gYJ7cVnSAt8dLFfluOJA,9777
10
- mt/sql/redshift/dialect.py,sha256=oomLiQib0iMhotRY3GjDrQI3iWGXgcIQyK5WTbmj8kc,53431
11
- mt/sql/redshift/main.py,sha256=6dwnwNJ1F0_V9o2oqrSOkyN_pAMrgE01CCoqAjoyOME,17116
12
- mt/sql/redshift/redshift-ca-bundle.crt,sha256=532qYkOpQOstFE0mdXE1GVtL3v00XDKgZNTr6gK5-KE,8621
13
- mtsql-1.12.10.dist-info/licenses/LICENSE,sha256=PojkRlQzTT5Eg6Nj03XoIVEefN3u8iiIFf1p4rqe_t4,1070
14
- mtsql-1.12.10.dist-info/METADATA,sha256=jnU1oJtaT3iRrapN8HdlceCoqpaE6iIerQqSwndOoVI,740
15
- mtsql-1.12.10.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
16
- mtsql-1.12.10.dist-info/top_level.txt,sha256=WcqGFu9cV7iMZg09iam8eNxUvGpLSKKF2Iubf6SJVOo,3
17
- mtsql-1.12.10.dist-info/RECORD,,