py2ls 0.2.5.2__py3-none-any.whl → 0.2.5.4__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.
py2ls/ips.py
CHANGED
@@ -7242,6 +7242,46 @@ def preview(var):
|
|
7242
7242
|
# preview(pd.DataFrame({"Name": ["Alice", "Bob"], "Age": [25, 30]}))
|
7243
7243
|
# preview({"key": "value", "numbers": [1, 2, 3]})
|
7244
7244
|
|
7245
|
+
def df2db(df: pd.DataFrame, db_url: str, table_name: str, if_exists: str = "replace"):
|
7246
|
+
"""
|
7247
|
+
Save a pandas DataFrame to a SQL database (SQLite, MySQL, PostgreSQL).
|
7248
|
+
|
7249
|
+
Usage:
|
7250
|
+
case 1. SQLite:
|
7251
|
+
df2db(df, 'sqlite:///sample_manager.db', 'users', 'replace')
|
7252
|
+
case 2. MySQL:
|
7253
|
+
df2db(df, 'mysql+mysqlconnector://user:password@localhost/mydatabase', 'users', 'replace')
|
7254
|
+
case 3. PostgreSQL:
|
7255
|
+
df2db(df, 'postgresql://user:password@localhost/mydatabase', 'users', 'replace')
|
7256
|
+
|
7257
|
+
Parameters:
|
7258
|
+
- df (pd.DataFrame): The DataFrame to save.
|
7259
|
+
- db_url (str): The SQLAlchemy connection string to the database.
|
7260
|
+
- table_name (str): The name of the table to save the DataFrame to.
|
7261
|
+
- if_exists (str): What to do if the table already exists. Options:
|
7262
|
+
- 'replace': Drop the table before inserting new values.
|
7263
|
+
- 'append': Append new values to the table.
|
7264
|
+
- 'fail': Do nothing if the table exists. Default is 'replace'.
|
7265
|
+
"""
|
7266
|
+
from sqlalchemy import create_engine
|
7267
|
+
from sqlalchemy.exc import SQLAlchemyError
|
7268
|
+
|
7269
|
+
try:
|
7270
|
+
# Create the SQLAlchemy engine based on the provided db_url
|
7271
|
+
engine = create_engine(db_url)
|
7272
|
+
|
7273
|
+
# Save the DataFrame to the SQL database (table)
|
7274
|
+
df.to_sql(table_name, con=engine, index=False, if_exists=if_exists)
|
7275
|
+
|
7276
|
+
print(f"Data successfully saved to {db_url} in the {table_name} table.")
|
7277
|
+
|
7278
|
+
except SQLAlchemyError as e:
|
7279
|
+
# Handle SQLAlchemy-related errors (e.g., connection issues, query issues)
|
7280
|
+
print(f"Error saving DataFrame to database: {str(e)}")
|
7281
|
+
|
7282
|
+
except Exception as e:
|
7283
|
+
# Handle other unexpected errors
|
7284
|
+
print(f"An unexpected error occurred: {str(e)}")
|
7245
7285
|
|
7246
7286
|
def _df_outlier(
|
7247
7287
|
data,
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: py2ls
|
3
|
-
Version: 0.2.5.
|
3
|
+
Version: 0.2.5.4
|
4
4
|
Summary: py(thon)2(too)ls
|
5
5
|
Author: Jianfeng
|
6
6
|
Author-email: Jianfeng.Liu0413@gmail.com
|
@@ -14,7 +14,7 @@ Classifier: Programming Language :: Python :: 3.9
|
|
14
14
|
Classifier: Programming Language :: Python :: 3.10
|
15
15
|
Classifier: Programming Language :: Python :: 3.11
|
16
16
|
Classifier: Programming Language :: Python :: 3.12
|
17
|
-
Provides-Extra:
|
17
|
+
Provides-Extra: ml
|
18
18
|
Requires-Dist: CacheControl (>=0.13.1)
|
19
19
|
Requires-Dist: Cython (>=3.0.10)
|
20
20
|
Requires-Dist: Deprecated (>=1.2.14)
|
@@ -37,7 +37,7 @@ Requires-Dist: SciencePlots (>=2.1.1)
|
|
37
37
|
Requires-Dist: XlsxWriter (>=3.2.0)
|
38
38
|
Requires-Dist: asciitree (>=0.3.3)
|
39
39
|
Requires-Dist: asttokens (>=2.4.1)
|
40
|
-
Requires-Dist: autogluon (>=1.2)
|
40
|
+
Requires-Dist: autogluon (>=1.2) ; extra == "ml"
|
41
41
|
Requires-Dist: beautifulsoup4 (>=4.12.3)
|
42
42
|
Requires-Dist: bleach (>=6.1.0)
|
43
43
|
Requires-Dist: build (>=0.10.0)
|
@@ -65,7 +65,7 @@ Requires-Dist: docopt (>=0.6.2)
|
|
65
65
|
Requires-Dist: docx (>=0.2.4)
|
66
66
|
Requires-Dist: dulwich (>=0.21.7)
|
67
67
|
Requires-Dist: executing (>=2.0.1)
|
68
|
-
Requires-Dist: faiss-cpu (>=1.8.0.post1)
|
68
|
+
Requires-Dist: faiss-cpu (>=1.8.0.post1) ; extra == "ml"
|
69
69
|
Requires-Dist: fake-useragent (>=1.5.1)
|
70
70
|
Requires-Dist: fasteners (>=0.19)
|
71
71
|
Requires-Dist: fastjsonschema (>=2.20.0)
|
@@ -77,7 +77,7 @@ Requires-Dist: fpdf (>=1.7.2)
|
|
77
77
|
Requires-Dist: fsspec (>=2024.6.1)
|
78
78
|
Requires-Dist: fuzzywuzzy (>=0.18.0)
|
79
79
|
Requires-Dist: ghp-import (>=2.1.0)
|
80
|
-
Requires-Dist: gluoncv (>=0.10.5)
|
80
|
+
Requires-Dist: gluoncv (>=0.10.5) ; extra == "ml"
|
81
81
|
Requires-Dist: googletrans (>=4.0.0rc1)
|
82
82
|
Requires-Dist: h11 (>=0.9.0)
|
83
83
|
Requires-Dist: h2 (>=3.2.0)
|
@@ -199,7 +199,7 @@ Requires-Dist: responses (>=0.25.3)
|
|
199
199
|
Requires-Dist: rfc3986 (>=1.5.0)
|
200
200
|
Requires-Dist: rpds-py (>=0.18.1)
|
201
201
|
Requires-Dist: scikit-image (>=0.23.2)
|
202
|
-
Requires-Dist: scikit-learn (>=1.5.1)
|
202
|
+
Requires-Dist: scikit-learn (>=1.5.1) ; extra == "ml"
|
203
203
|
Requires-Dist: scipy (>=1.14.0)
|
204
204
|
Requires-Dist: scrapy (>=2.12.0)
|
205
205
|
Requires-Dist: seaborn (>=0.13.2)
|
@@ -207,7 +207,7 @@ Requires-Dist: selenium (>=4.23.1)
|
|
207
207
|
Requires-Dist: setuptools (>=70.3.0)
|
208
208
|
Requires-Dist: shellingham (>=1.5.4)
|
209
209
|
Requires-Dist: six (>=1.16.0)
|
210
|
-
Requires-Dist: skorch (>=1.0.0)
|
210
|
+
Requires-Dist: skorch (>=1.0.0) ; extra == "ml"
|
211
211
|
Requires-Dist: sniffio (>=1.3.1)
|
212
212
|
Requires-Dist: sortedcontainers (>=2.4.0)
|
213
213
|
Requires-Dist: soupsieve (>=2.5)
|
@@ -224,7 +224,7 @@ Requires-Dist: tifffile (>=2024.7.24)
|
|
224
224
|
Requires-Dist: tinycss2 (>=1.3.0)
|
225
225
|
Requires-Dist: tomlkit (>=0.13.0)
|
226
226
|
Requires-Dist: toolz (>=0.12.1)
|
227
|
-
Requires-Dist: torch (>=2.4.0)
|
227
|
+
Requires-Dist: torch (>=2.4.0) ; extra == "ml"
|
228
228
|
Requires-Dist: tornado (>=6.4.1)
|
229
229
|
Requires-Dist: tqdm (>=4.66.4)
|
230
230
|
Requires-Dist: traitlets (>=5.14.3)
|
@@ -244,7 +244,7 @@ Requires-Dist: webencodings (>=0.5.1)
|
|
244
244
|
Requires-Dist: websocket-client (>=1.8.0)
|
245
245
|
Requires-Dist: wrapt (>=1.16.0)
|
246
246
|
Requires-Dist: wsproto (>=1.2.0)
|
247
|
-
Requires-Dist: xarray (>=2024.6.0)
|
247
|
+
Requires-Dist: xarray (>=2024.6.0) ; extra == "ml"
|
248
248
|
Requires-Dist: zarr (>=2.17.2)
|
249
249
|
Description-Content-Type: text/markdown
|
250
250
|
|
@@ -243,7 +243,7 @@ py2ls/export_requirements.py,sha256=x2WgUF0jYKz9GfA1MVKN-MdsM-oQ8yUeC6Ua8oCymio,
|
|
243
243
|
py2ls/fetch_update.py,sha256=9LXj661GpCEFII2wx_99aINYctDiHni6DOruDs_fdt8,4752
|
244
244
|
py2ls/freqanalysis.py,sha256=F4218VSPbgL5tnngh6xNCYuNnfR-F_QjECUUxrPYZss,32594
|
245
245
|
py2ls/ich2ls.py,sha256=3E9R8oVpyYZXH5PiIQgT3CN5NxLe4Dwtm2LwaeacE6I,21381
|
246
|
-
py2ls/ips.py,sha256=
|
246
|
+
py2ls/ips.py,sha256=yvT-36hcx4f0-ezd7a8_azjjVq2u2Z0O2nn5uJegh00,434249
|
247
247
|
py2ls/ml2ls.py,sha256=I-JFPdikgEtfQjhv5gBz-QSeorpTJI_Pda_JwkTioBY,209732
|
248
248
|
py2ls/mol.py,sha256=AZnHzarIk_MjueKdChqn1V6e4tUle3X1NnHSFA6n3Nw,10645
|
249
249
|
py2ls/netfinder.py,sha256=OhqD3S9PuwweL2013D-q4GNP1WvJjuYfZzq5BZgGddE,68980
|
@@ -255,6 +255,6 @@ py2ls/sleep_events_detectors.py,sha256=bQA3HJqv5qnYKJJEIhCyhlDtkXQfIzqksnD0YRXso
|
|
255
255
|
py2ls/stats.py,sha256=qBn2rJmNa_QLLUqjwYqXUlGzqmW94sgA1bxJU2FC3r0,39175
|
256
256
|
py2ls/translator.py,sha256=77Tp_GjmiiwFbEIJD_q3VYpQ43XL9ZeJo6Mhl44mvh8,34284
|
257
257
|
py2ls/wb_detector.py,sha256=7y6TmBUj9exCZeIgBAJ_9hwuhkDh1x_-yg4dvNY1_GQ,6284
|
258
|
-
py2ls-0.2.5.
|
259
|
-
py2ls-0.2.5.
|
260
|
-
py2ls-0.2.5.
|
258
|
+
py2ls-0.2.5.4.dist-info/METADATA,sha256=WSAK_tO1EZLvsgCBM8u8YRZNOnAr5m4jdoRqhGZWEek,20550
|
259
|
+
py2ls-0.2.5.4.dist-info/WHEEL,sha256=FMvqSimYX_P7y0a7UY-_Mc83r5zkBZsCYPm7Lr0Bsq4,88
|
260
|
+
py2ls-0.2.5.4.dist-info/RECORD,,
|
File without changes
|