correct mypy issues
This commit is contained in:
parent
04559cc95f
commit
4546688d97
8 changed files with 64 additions and 50 deletions
|
|
@ -5,10 +5,11 @@ import pandas as pd
|
|||
import numpy as np
|
||||
from .input.implementations import codes
|
||||
from .tools import k2m, get_file
|
||||
from typing import Any, Union, Optional
|
||||
# this will implement the search functionality
|
||||
|
||||
|
||||
def _project_lookup_by_alias(db, alias):
|
||||
def _project_lookup_by_alias(db: str, alias: str) -> str:
|
||||
# this will lookup the project name based on the alias
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
|
|
@ -19,10 +20,10 @@ def _project_lookup_by_alias(db, alias):
|
|||
print("Error: multiple projects found with alias " + alias)
|
||||
elif len(results) == 0:
|
||||
raise Exception("Error: no project found with alias " + alias)
|
||||
return results[0][0]
|
||||
return str(results[0][0])
|
||||
|
||||
|
||||
def _project_lookup_by_id(db, uuid):
|
||||
def _project_lookup_by_id(db: str, uuid: str) -> list[tuple[str, str]]:
|
||||
conn = sqlite3.connect(db)
|
||||
c = conn.cursor()
|
||||
c.execute(f"SELECT * FROM 'projects' WHERE id = '{uuid}'")
|
||||
|
|
@ -31,7 +32,8 @@ def _project_lookup_by_id(db, uuid):
|
|||
return results
|
||||
|
||||
|
||||
def _db_lookup(db, ensemble, correlator_name,code, project=None, parameters=None, created_before=None, created_after=None, updated_before=None, updated_after=None, revision=None):
|
||||
def _db_lookup(db: str, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None,
|
||||
created_before: Optional[str]=None, created_after: Optional[Any]=None, updated_before: Optional[Any]=None, updated_after: Optional[Any]=None) -> pd.DataFrame:
|
||||
project_str = project
|
||||
|
||||
search_expr = f"SELECT * FROM 'backlogs' WHERE name = '{correlator_name}' AND ensemble = '{ensemble}'"
|
||||
|
|
@ -55,7 +57,7 @@ def _db_lookup(db, ensemble, correlator_name,code, project=None, parameters=Non
|
|||
return results
|
||||
|
||||
|
||||
def sfcf_filter(results, **kwargs):
|
||||
def sfcf_filter(results: pd.DataFrame, **kwargs: Any) -> pd.DataFrame:
|
||||
drops = []
|
||||
for ind in range(len(results)):
|
||||
result = results.iloc[ind]
|
||||
|
|
@ -138,24 +140,25 @@ def sfcf_filter(results, **kwargs):
|
|||
return results.drop(drops)
|
||||
|
||||
|
||||
def find_record(path, ensemble, correlator_name, code, project=None, parameters=None, created_before=None, created_after=None, updated_before=None, updated_after=None, revision=None, **kwargs):
|
||||
def find_record(path: str, ensemble: str, correlator_name: str, code: str, project: Optional[str]=None, parameters: Optional[str]=None,
|
||||
created_before: Optional[str]=None, created_after: Optional[str]=None, updated_before: Optional[str]=None, updated_after: Optional[str]=None, revision: Optional[str]=None, **kwargs: Any) -> pd.DataFrame:
|
||||
db = path + '/backlogger.db'
|
||||
if code not in codes:
|
||||
raise ValueError("Code " + code + "unknown, take one of the following:" + ", ".join(codes))
|
||||
get_file(path, "backlogger.db")
|
||||
results = _db_lookup(db, ensemble, correlator_name,code, project, parameters=parameters, created_before=created_before, created_after=created_after, updated_before=updated_before, updated_after=updated_after, revision=revision)
|
||||
results = _db_lookup(db, ensemble, correlator_name,code, project, parameters=parameters, created_before=created_before, created_after=created_after, updated_before=updated_before, updated_after=updated_after)
|
||||
if code == "sfcf":
|
||||
results = sfcf_filter(results, **kwargs)
|
||||
print("Found " + str(len(results)) + " result" + ("s" if len(results)>1 else ""))
|
||||
return results.reset_index()
|
||||
|
||||
|
||||
def find_project(path, name):
|
||||
def find_project(path: str, name: str) -> str:
|
||||
get_file(path, "backlogger.db")
|
||||
return _project_lookup_by_alias(os.path.join(path, "backlogger.db"), name)
|
||||
|
||||
|
||||
def list_projects(path):
|
||||
def list_projects(path: str) -> list[tuple[str, str]]:
|
||||
db = path + '/backlogger.db'
|
||||
get_file(path, "backlogger.db")
|
||||
conn = sqlite3.connect(db)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue