Skip to content

Commit

Permalink
Adopt pymysql
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasFehring committed May 26, 2023
1 parent 793bd89 commit d299bca
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 326 deletions.
630 changes: 310 additions & 320 deletions poetry.lock

Large diffs are not rendered by default.

6 changes: 5 additions & 1 deletion py_experimenter/database_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,10 @@ def get_codecarbon_table(self) -> pd.DataFrame:
def get_table(self, table_name: Optional[str] = None) -> pd.DataFrame:
connection = self.connect()
query = f"SELECT * FROM {self.table_name}" if table_name is None else f"SELECT * FROM {table_name}"
df = pd.read_sql(query, connection)
#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
5 changes: 3 additions & 2 deletions py_experimenter/database_connector_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from typing import List, Tuple

import numpy as np
from mysql.connector import Error, connect
from pymysql import Error, connect

from py_experimenter.database_connector import DatabaseConnector
from py_experimenter.exceptions import DatabaseConnectionError, DatabaseCreationError
Expand Down Expand Up @@ -62,7 +62,8 @@ def connect(self, credentials=None):
raise DatabaseConnectionError(err)

def _start_transaction(self, connection, readonly=False):
connection.start_transaction(readonly=readonly)
if not readonly:
connection.begin()

def _table_exists(self, cursor, table_name:str = None) -> bool:
table_name = table_name if table_name is not None else self.table_name
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ classifiers = [
python = "^3.9"
numpy = ">=1.15"
pandas = ">=1.0"
mysql-connector-python = ">=8.0"
jupyterlab = "^3.5.0"
joblib = "^1.2.0"
codecarbon = "^2.2.1"
pymysql = "^1.0.3"

[tool.poetry.group.dev.dependencies]
pytest = ">=7.0"
Expand Down
2 changes: 1 addition & 1 deletion test/test_run_experiments/test_run_mysql_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from math import cos, sin

import pandas as pd
from mysql.connector.errors import ProgrammingError
from pymysql.err import ProgrammingError

from py_experimenter.experimenter import PyExperimenter
from py_experimenter.result_processor import ResultProcessor
Expand Down
2 changes: 1 addition & 1 deletion test/test_run_experiments/test_run_sqlite_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from math import cos, sin

import pandas as pd
from mysql.connector.errors import ProgrammingError
from pymysql.err import ProgrammingError

from py_experimenter.experimenter import PyExperimenter
from py_experimenter.result_processor import ResultProcessor
Expand Down

0 comments on commit d299bca

Please sign in to comment.