Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
133 changes: 22 additions & 111 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions py_experimenter/database_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,3 +409,14 @@ def get_table(self, table_name: Optional[str] = None, condition:Optional[str] =
df = pd.read_sql(query, connection)
self.close_connection(connection)
return df

def execute_custom_query(self, query: str) -> pd.DataFrame:
connection = self.connect()
# suppress warning for pandas
import warnings

with warnings.catch_warnings():
warnings.filterwarnings("ignore", category=UserWarning)
df = pd.read_sql(query, connection)
self.close_connection(connection)
return df
13 changes: 12 additions & 1 deletion py_experimenter/experimenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def get_table(self, condition:Optional[str] = None) -> pd.DataFrame:
:return: The database table as `Pandas.DataFrame`.
:rtype: pd.DataFrame
"""
return self.db_connector.get_table()
return self.db_connector.get_table(condition=condition)

def get_logtable(self, logtable_name: str, condition:Optional[str] = None) -> pd.DataFrame:
"""
Expand All @@ -542,3 +542,14 @@ def get_codecarbon_table(self) -> pd.DataFrame:
return self.db_connector.get_codecarbon_table()
else:
raise ValueError("CodeCarbon is not used in this experiment.")

def execute_custom_query(self, query: str) -> pd.DataFrame:
"""
Executes the given custom query and returns the result as `Pandas.DataFrame`.

:raises ValueError: If no custom query is given in the configuration file.
:return: The result of the custom query as `Pandas.DataFrame`.
"""
if not query:
raise ValueError("No custom query given.")
return self.db_connector.execute_custom_query(query)
1 change: 0 additions & 1 deletion py_experimenter/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ def extract_codecarbon_columns() -> Dict[str, str]:
("ram_total_size", "DOUBLE"),
("tracking_mode", "VARCHAR(255)"),
("on_cloud", "VARCHAR(255)"),
("power_usage_efficiency", "DOUBLE"),
("offline_mode", "BOOL"),
]
)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ numpy = ">=1.15"
pandas = ">=1.0"
jupyterlab = "^3.5.0"
joblib = "^1.2.0"
codecarbon = ">=2.2.1"
codecarbon = "==2.2.1"
pymysql = "^1.0.3"
omegaconf = "^2.3.0"
sshtunnel = "^0.4.0"
Expand Down
3 changes: 1 addition & 2 deletions test/test_codecarbon/test_integration_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ def test_integration(experimenter: PyExperimenter):
"ram_total_size",
"tracking_mode",
"on_cloud",
"power_usage_efficiency",
"offline_mode",
]
assert table.shape == (12, 34)
assert table.shape == (12, 33)
assert set(table["experiment_id"]) == {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
3 changes: 1 addition & 2 deletions test/test_codecarbon/test_integration_sqlite.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,7 @@ def test_integration(experimenter: PyExperimenter):
"ram_total_size",
"tracking_mode",
"on_cloud",
"power_usage_efficiency",
"offline_mode",
]
assert table.shape == (12, 34)
assert table.shape == (12, 33)
assert set(table["experiment_id"]) == {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}