From c13684519efd5aa65cfe7d6302408270b78c4f72 Mon Sep 17 00:00:00 2001 From: ChristianGeng Date: Wed, 23 Oct 2024 13:32:08 +0200 Subject: [PATCH] Remove typing module (#27) * remove typing module. * Remove unused import. * Update audpsychometric/core/datasets/__init__.py Co-authored-by: Hagen Wierstorf --------- Co-authored-by: Hagen Wierstorf --- audpsychometric/core/datasets/__init__.py | 4 ++-- audpsychometric/core/gold_standard.py | 26 ++++++++++++----------- audpsychometric/core/reliability.py | 16 ++++++++------ 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/audpsychometric/core/datasets/__init__.py b/audpsychometric/core/datasets/__init__.py index 3581490..88880ee 100644 --- a/audpsychometric/core/datasets/__init__.py +++ b/audpsychometric/core/datasets/__init__.py @@ -40,8 +40,8 @@ def read_dataset(data_set_name: str) -> pd.DataFrame: return df -def list_datasets(): - r"""List tests datasets available in package. +def list_datasets() -> pd.DataFrame: + """List datasets available in package. Returns: dataframe listing available datasets diff --git a/audpsychometric/core/gold_standard.py b/audpsychometric/core/gold_standard.py index aac1181..c892af3 100644 --- a/audpsychometric/core/gold_standard.py +++ b/audpsychometric/core/gold_standard.py @@ -1,4 +1,6 @@ -import typing +from __future__ import annotations + +from collections.abc import Sequence import numpy as np import pandas as pd @@ -7,10 +9,10 @@ def agreement_categorical( - ratings: typing.Sequence, + ratings: Sequence, *, axis: int = 1, -) -> typing.Union[float, np.ndarray]: +) -> float | np.ndarray: r"""Confidence score for categorical ratings. The agreement for categorical data @@ -50,12 +52,12 @@ def _agreement(x): def agreement_numerical( - ratings: typing.Sequence, + ratings: Sequence, minimum: float, maximum: float, *, axis: int = 1, -) -> typing.Union[float, np.ndarray]: +) -> float | np.ndarray: r"""Confidence score for numerical ratings. .. math:: @@ -103,10 +105,10 @@ def _agreement(row): def evaluator_weighted_estimator( - ratings: typing.Sequence, + ratings: Sequence, *, axis: int = 1, -) -> typing.Union[float, np.ndarray]: +) -> float | np.ndarray: r"""Evaluator weighted estimator (EWE) of raters' votes. The EWE is described in @@ -150,10 +152,10 @@ def evaluator_weighted_estimator( def mode( - ratings: typing.Sequence, + ratings: Sequence, *, axis: int = 1, -) -> typing.Any: +) -> object: r"""Mode of categorical ratings. ``None`` and ``nan`` values are ignored per item. @@ -200,7 +202,7 @@ def mode( def rater_agreement( - ratings: typing.Sequence, + ratings: Sequence, *, axis: int = 1, ) -> np.ndarray: @@ -256,7 +258,7 @@ def rater_agreement( return np.array(agreements) -def _value_or_array(values: np.ndarray) -> typing.Union[float, np.ndarray]: +def _value_or_array(values: np.ndarray) -> float | np.ndarray: r"""Convert single valued arrays to value. Squeeze array, @@ -276,7 +278,7 @@ def _value_or_array(values: np.ndarray) -> typing.Union[float, np.ndarray]: return values -def _mode(ratings: np.ndarray, *, remove_nan=False) -> typing.Any: +def _mode(ratings: np.ndarray, *, remove_nan=False) -> object: """Mode of categorical values. Args: diff --git a/audpsychometric/core/reliability.py b/audpsychometric/core/reliability.py index 099b5b8..3e201fb 100644 --- a/audpsychometric/core/reliability.py +++ b/audpsychometric/core/reliability.py @@ -1,4 +1,6 @@ -import typing +from __future__ import annotations + +from collections.abc import Sequence import numpy as np import pandas as pd @@ -9,10 +11,10 @@ def cronbachs_alpha( - ratings: typing.Sequence, + ratings: Sequence, *, axis: int = 1, -) -> typing.Tuple[float, typing.Dict]: +) -> tuple[float, dict]: r"""Calculate Cronbach's alpha. The Cronbach coefficient quantifying interrater agreement. @@ -67,10 +69,10 @@ def cronbachs_alpha( def congeneric_reliability( - ratings: typing.Sequence, + ratings: Sequence, *, axis: int = 1, -) -> typing.Tuple[float, typing.Dict]: +) -> tuple[float, dict]: r"""Congeneric reliability coefficient. Extracts the first Principal Component as a measurement model @@ -111,12 +113,12 @@ def congeneric_reliability( def intra_class_correlation( - ratings: typing.Sequence, + ratings: Sequence, *, axis: int = 1, icc_type: str = "ICC_1_1", anova_method: str = "pingouin", -) -> typing.Tuple[float, typing.Dict]: +) -> tuple[float, dict]: r"""Intraclass Correlation. Intraclass correlation calculates rating reliability by relating