detquantlib 5.0.1__tar.gz → 5.1.1__tar.gz
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.
- {detquantlib-5.0.1 → detquantlib-5.1.1}/PKG-INFO +1 -1
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/data/databases/detdatabase.py +20 -11
- {detquantlib-5.0.1 → detquantlib-5.1.1}/pyproject.toml +1 -1
- {detquantlib-5.0.1 → detquantlib-5.1.1}/LICENSE.txt +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/README.md +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/assets/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/assets/battery.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/assets/wind_turbine.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/converters/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/converters/definitions.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/converters/energy.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/converters/helpers.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/converters/price.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/data/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/data/databases/helpers.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/data/entsoe/entsoe.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/data/sftp/sftp.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/dates/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/dates/dates.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/figures/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/figures/plotly_figures.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/forecasting/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/forecasting/forecasting.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/outputs/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/outputs/outputs_interface.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/stats/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/stats/data_analysis.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/tradable_products/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/tradable_products/tradable_products.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/utils/__init__.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/utils/logging.py +0 -0
- {detquantlib-5.0.1 → detquantlib-5.1.1}/detquantlib/utils/utils.py +0 -0
|
@@ -35,26 +35,32 @@ class DetDatabase:
|
|
|
35
35
|
initialized.
|
|
36
36
|
driver: ODBC driver
|
|
37
37
|
"""
|
|
38
|
-
# Store database name if it is provided
|
|
39
|
-
if db_name:
|
|
40
|
-
os.environ["DET_DB_NAME"] = db_name
|
|
41
|
-
|
|
42
38
|
# Only allow object creation if mandatory environment variables exist
|
|
43
|
-
|
|
39
|
+
skip_db_name = db_name is not None
|
|
40
|
+
DetDatabase.check_environment_variables(skip_db_name)
|
|
44
41
|
|
|
42
|
+
self.db_name = db_name if db_name else os.environ["DET_DB_NAME"]
|
|
45
43
|
self.driver = driver
|
|
46
44
|
self.engine = engine if engine is not None else self.initialize_engine()
|
|
47
45
|
|
|
48
46
|
@staticmethod
|
|
49
|
-
def check_environment_variables():
|
|
47
|
+
def check_environment_variables(skip_db_name: bool):
|
|
50
48
|
"""
|
|
51
49
|
Checks if environment variables needed by the class are defined.
|
|
52
50
|
|
|
51
|
+
Args:
|
|
52
|
+
skip_db_name: If true, does not check if the environment variable containing the
|
|
53
|
+
database name is defined
|
|
54
|
+
|
|
53
55
|
Raises:
|
|
54
56
|
ConnectionError: Raises an error if environment variables are not defined.
|
|
55
57
|
"""
|
|
56
|
-
required_env_vars =
|
|
57
|
-
|
|
58
|
+
required_env_vars = (
|
|
59
|
+
[]
|
|
60
|
+
if skip_db_name
|
|
61
|
+
else [dict(name="DET_DB_NAME", value=None, description="Database name")]
|
|
62
|
+
)
|
|
63
|
+
required_env_vars += [
|
|
58
64
|
dict(name="DET_DB_SERVER", value=None, description="Server name"),
|
|
59
65
|
dict(name="DET_DB_USERNAME", value=None, description="Username"),
|
|
60
66
|
dict(name="DET_DB_PASSWORD", value=None, description="Password"),
|
|
@@ -81,7 +87,7 @@ class DetDatabase:
|
|
|
81
87
|
connection_str = (
|
|
82
88
|
f"DRIVER={self.driver};"
|
|
83
89
|
f"SERVER={os.getenv('DET_DB_SERVER')};"
|
|
84
|
-
f"DATABASE={
|
|
90
|
+
f"DATABASE={self.db_name};"
|
|
85
91
|
f"UID={os.getenv('DET_DB_USERNAME')};"
|
|
86
92
|
f"PWD={quote_plus(os.getenv('DET_DB_PASSWORD'))}"
|
|
87
93
|
)
|
|
@@ -93,12 +99,15 @@ class DetDatabase:
|
|
|
93
99
|
"""Disconnects the SQLAlchemy engine and releases all underlying resources."""
|
|
94
100
|
self.engine.dispose()
|
|
95
101
|
|
|
96
|
-
def query_db(self, query: str) -> pd.DataFrame:
|
|
102
|
+
def query_db(self, query: str, params: dict = None) -> pd.DataFrame:
|
|
97
103
|
"""
|
|
98
104
|
Short utility method to make an SQL query to the database.
|
|
99
105
|
|
|
100
106
|
Args:
|
|
101
107
|
query: SQL query
|
|
108
|
+
params: Dict of query parameters. Example:
|
|
109
|
+
>> query = text('''SELECT * FROM MyTable WHERE start_date > :start_date''')
|
|
110
|
+
>> df = obj.query_db(query, params={"start_date": start_date})
|
|
102
111
|
|
|
103
112
|
Returns:
|
|
104
113
|
Dataframe containing the queried data
|
|
@@ -107,7 +116,7 @@ class DetDatabase:
|
|
|
107
116
|
Exception: Raises an error if the SQL query fails.
|
|
108
117
|
"""
|
|
109
118
|
try:
|
|
110
|
-
df = pd.read_sql_query(query, con=self.engine)
|
|
119
|
+
df = pd.read_sql_query(query, params=params, con=self.engine)
|
|
111
120
|
except Exception:
|
|
112
121
|
# If query fails, close connection before raising the error
|
|
113
122
|
self.terminate_engine()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|