Skip to content

Commit

Permalink
Changes to restore Python 3.8 compatibility (#1)
Browse files Browse the repository at this point in the history
* Changes to add Python 3.8 compatability

1. Revert to old-style typing importing to add Python 3.8 backwards (capitalisation of List and Dict)
2. Correct parynthesis use around file opening command for python 3.8 compatability

* Update github workflow to include python 3.8

* Changes for haslib compatability

Remove references to usedforsecurity for hashlib compatiablity

* Correct syntax
  • Loading branch information
andrewsoltan authored Jul 3, 2024
1 parent e7c9d15 commit 063c9b4
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ '3.9', '3.10' ]
python-version: [ '3.8', '3.9', '3.10' ]
max-parallel: 2

steps:
Expand Down
2 changes: 1 addition & 1 deletion app/data/anno_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def _generate_examples(self, filepaths: List[Path]) -> Iterable[Tuple[str, Dict]
def generate_examples(filepaths: List[Path]) -> Iterable[Tuple[str, Dict]]:
id_ = 1
for filepath in filepaths:
with (open(str(filepath), "r") as f):
with open(str(filepath), "r") as f:
annotations = json.load(f)
filtered = filter_by_concept_ids(annotations)
for project in filtered["projects"]:
Expand Down
4 changes: 2 additions & 2 deletions app/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ class Annotation(BaseModel):
categories: Optional[List[str]] = Field(default=None, description="The categories to which the annotation concept belongs")
accuracy: Optional[float] = Field(default=None, description="The confidence score of the annotation")
text: Optional[str] = Field(default=None, description="The string literal of the annotation span")
meta_anns: Optional[dict] = Field(default=None, description="The meta annotations")
athena_ids: Optional[list[dict]] = Field(default=None, description="The OHDSI Athena concept IDs")
meta_anns: Optional[Dict] = Field(default=None, description="The meta annotations")
athena_ids: Optional[List[Dict]] = Field(default=None, description="The OHDSI Athena concept IDs")

@root_validator()
def _validate(cls, values: Dict[str, Any]) -> Dict[str, Any]:
Expand Down
8 changes: 4 additions & 4 deletions app/processors/metrics_collector.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

ANCHOR_DELIMITER = ";"
DOC_SPAN_DELIMITER = "_"
STATE_MISSING = hashlib.sha1("MISSING".encode("utf-8"), usedforsecurity=False).hexdigest()
META_STATE_MISSING = hashlib.sha1("{}".encode("utf-8"), usedforsecurity=False).hexdigest()
STATE_MISSING = hashlib.sha1("MISSING".encode("utf-8")).hexdigest()
META_STATE_MISSING = hashlib.sha1("{}".encode("utf-8")).hexdigest()


def sanity_check_model_with_trainer_export(trainer_export: Union[str, TextIO, Dict],
Expand Down Expand Up @@ -425,12 +425,12 @@ def _filter_docspan_by_value(docspan2value: Dict, value: str) -> Dict:


def _get_hashed_annotation_state(annotation: Dict, state_keys: Set[str]) -> str:
return hashlib.sha1("_".join([str(annotation.get(key)) for key in state_keys]).encode("utf-8"), usedforsecurity=False).hexdigest()
return hashlib.sha1("_".join([str(annotation.get(key)) for key in state_keys]).encode("utf-8")).hexdigest()


def _get_hashed_meta_annotation_state(meta_anno: Dict) -> str:
meta_anno = {key: val for key, val in sorted(meta_anno.items(), key=lambda item: item[0])} # may not be necessary
return hashlib.sha1(str(meta_anno).encode("utf=8"), usedforsecurity=False).hexdigest()
return hashlib.sha1(str(meta_anno).encode("utf=8")).hexdigest()


def _get_cohens_kappa_coefficient(y1_labels: List, y2_labels: List) -> float:
Expand Down

0 comments on commit 063c9b4

Please sign in to comment.