Skip to content

Commit dbca027

Browse files
committed
added use of Union & Optional for typing to guarantee compatibility with python 3.9
1 parent 28e030f commit dbca027

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

coderdata/dataset/dataset.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import pickle
1212
import sys
1313
from typing import Literal
14+
from typing import Optional
15+
from typing import Union
1416

1517
import numpy as np
1618
from numpy.random import RandomState
@@ -335,8 +337,8 @@ def train_test_validate(
335337
'mixed-set', 'drug-blind', 'cancer-blind'
336338
]='mixed-set',
337339
ratio: tuple[int, int, int]=(8,1,1),
338-
stratify_by: (str | None)=None,
339-
random_state: (int | RandomState | None)=None,
340+
stratify_by: Optional[str]=None,
341+
random_state: Optional[Union[int,RandomState]]=None,
340342
**kwargs: dict,
341343
) -> Split:
342344

@@ -386,7 +388,7 @@ def save(self, path: Path) -> None:
386388

387389
def load(
388390
name: str,
389-
local_path: str|Path=Path.cwd(),
391+
local_path: Union[str,Path]=Path.cwd(),
390392
from_pickle:bool=False
391393
) -> Dataset:
392394
"""
@@ -669,8 +671,8 @@ def train_test_validate(
669671
'mixed-set', 'drug-blind', 'cancer-blind'
670672
]='mixed-set',
671673
ratio: tuple[int, int, int]=(8,1,1),
672-
stratify_by: (str | None)=None,
673-
random_state: (int | RandomState | None)=None,
674+
stratify_by: Optional[str]=None,
675+
random_state: Optional[Union[int,RandomState]]=None,
674676
**kwargs: dict,
675677
) -> Split:
676678
"""
@@ -1015,7 +1017,7 @@ def _load_file(file_path: Path) -> pd.DataFrame:
10151017
)
10161018

10171019

1018-
def _determine_delimiter(file_path):
1020+
def _determine_delimiter(file_path: Path) -> str:
10191021
if '.tsv' in file_path.suffixes:
10201022
return '\t'
10211023
else:

coderdata/utils/utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
from importlib import resources
66
import yaml
77

8+
from typing import Union
9+
810
from .. import __version__
911
from .. import __version_tuple__
1012

@@ -30,7 +32,7 @@ def version() -> dict:
3032
}
3133

3234

33-
def list_datasets(raw: bool=False) -> dict | None:
35+
def list_datasets(raw: bool=False) -> Union[dict, None]:
3436
"""
3537
Hepler function that returns a list of available datasets including
3638
a short description and additional information available.

0 commit comments

Comments
 (0)