Skip to content

Commit db79867

Browse files
committed
style & utils type hints
1 parent 37b5ff4 commit db79867

File tree

4 files changed

+15
-13
lines changed

4 files changed

+15
-13
lines changed

eurybia/style/style_utils.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@
22

33
import json
44
import os
5+
from typing import Any
56

67

7-
def colors_loading():
8+
def colors_loading() -> dict:
89
"""colors_loading allows Eurybia to load a json file which contains different
910
palettes of colors that can be used in the plot
1011
@@ -21,7 +22,7 @@ def colors_loading():
2122
return colors_dic
2223

2324

24-
def select_palette(colors_dic, palette_name):
25+
def select_palette(colors_dic: dict[str, dict], palette_name: str) -> dict:
2526
"""colors_loading allows Eurybia to load a json file which contains different
2627
palettes of colors that can be used in the plot
2728
@@ -43,7 +44,7 @@ def select_palette(colors_dic, palette_name):
4344
return colors_dic[palette_name]
4445

4546

46-
def define_style(palette):
47+
def define_style(palette: dict[str, Any]) -> dict[str, Any]:
4748
"""The define_style function is a function that uses a palette
4849
to define the different styles used in the different outputs
4950
of Eurybia
@@ -59,7 +60,7 @@ def define_style(palette):
5960
contains different style elements
6061
6162
"""
62-
style_dict = dict()
63+
style_dict: dict[str, Any] = dict()
6364
style_dict["dict_title"] = {
6465
"xanchor": "center",
6566
"yanchor": "middle",

eurybia/utils/io.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
"""IO module"""
22

33
import pickle
4+
from typing import Any
45

56

6-
def load_yml(path):
7+
def load_yml(path: str) -> dict:
78
"""Loads a yml file
89
910
Parameters
@@ -33,12 +34,12 @@ def load_yml(path):
3334
try:
3435
import yaml
3536

36-
_is_yaml_available = True
37+
_is_yaml_available = True # FIXME: never used
3738
except (ImportError, ModuleNotFoundError):
3839
_is_yaml_available = False
3940

4041

41-
def save_pickle(obj, path, protocol=pickle.HIGHEST_PROTOCOL):
42+
def save_pickle(obj, path: str, protocol: int = pickle.HIGHEST_PROTOCOL) -> None:
4243
"""Save any python Object in pickle file
4344
4445
Parameters
@@ -68,7 +69,7 @@ def save_pickle(obj, path, protocol=pickle.HIGHEST_PROTOCOL):
6869
pickle.dump(obj, file, protocol=protocol)
6970

7071

71-
def load_pickle(path):
72+
def load_pickle(path: str) -> Any:
7273
"""Load any pickle file
7374
7475
Parameters

eurybia/utils/statistical_tests.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def chisq_test(obs_a: np.array, obs_b: np.array) -> dict:
5757
return output
5858

5959

60-
def prob_mass_fun(data, n, range):
60+
def prob_mass_fun(data: pd.Series, n: int, range: tuple[float, float]) -> tuple[np.ndarray, np.ndarray]:
6161
"""Computing the probability mass function using NumPy’s histogram.
6262
6363
Parameters
@@ -80,7 +80,7 @@ def prob_mass_fun(data, n, range):
8080
return e, p
8181

8282

83-
def compute_js_divergence(df_1, df_2, n_bins=30):
83+
def compute_js_divergence(df_1: pd.DataFrame, df_2: pd.DataFrame, n_bins: int = 30) -> float:
8484
"""Computing the Jensen-Shannon divergence between 2 dataframe
8585
8686
Parameters

eurybia/utils/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ def base_100(series: pd.Series) -> pd.Series:
3939
return series / tot
4040

4141

42-
def get_project_root():
42+
def get_project_root() -> Path:
4343
"""Returns project root absolute path."""
4444
current_path = Path(__file__)
4545
return current_path.parent.parent.resolve()
4646

4747

48-
def truncate_str(text, maxlen=40):
48+
def truncate_str(text: str, maxlen: int = 40) -> str:
4949
"""Truncate a string
5050
5151
Parameters
@@ -76,7 +76,7 @@ def truncate_str(text, maxlen=40):
7676
return text
7777

7878

79-
def round_to_k(x, k):
79+
def round_to_k(x: float, k: int) -> float | int:
8080
"""Round float to k significant figure
8181
8282
Parameters

0 commit comments

Comments
 (0)