Skip to content
Snippets Groups Projects
Commit 61dd6de3 authored by David Schäfer's avatar David Schäfer
Browse files

typing toSequence is hard...

parent 127cf0ba
No related branches found
No related tags found
10 merge requests!685Release 2.4,!684Release 2.4,!567Release 2.2.1,!566Release 2.2,!501Release 2.1,!372fix doctest snippets,!369Current documentation,!345Rework the generic functions,!343Fix Processing Functions. Introduce custom target Parameter.,!340Multivariate functions
......@@ -218,7 +218,7 @@ class SaQC(FunctionsMixin):
"""
def inner(
field: str,
field: str | Sequence[str],
*args,
regex: bool = False,
flag: ExternalFlag = None,
......@@ -233,25 +233,23 @@ class SaQC(FunctionsMixin):
# expand regular expressions
if regex:
fields = self._data.columns.str.match(field)
fields = self._data.columns[fields]
fmask = self._data.columns.str.match(field)
fields: list = self._data.columns[fmask].tolist()
else:
fields = toSequence(field)
if func.__multivariate__:
# we wrap field again to make the downstream loop work as expected
fields = [
fields,
]
# we wrap field again to generalize the down stream loop work as expected
fields = [fields]
out = self
for field in fields:
for f in fields:
out = out._callFunction(
func,
data=out._data,
flags=out._flags,
field=field,
field=f,
*args,
**kwargs,
)
......@@ -264,7 +262,7 @@ class SaQC(FunctionsMixin):
function: Callable,
data: DictOfSeries,
flags: Flags,
field: str,
field: str | Sequence[str],
*args: Any,
**kwargs: Any,
) -> SaQC:
......
#! /usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import annotations
import re
import datetime
import itertools
import warnings
from typing import List, Sequence, Union, Any, Iterator, Callable
from typing import List, Sequence, TypeVar, Union, Any, Iterator, Callable
import numpy as np
import numba as nb
......@@ -16,13 +17,14 @@ import dios
import collections
from scipy.cluster.hierarchy import linkage, fcluster
from saqc.lib.types import T
# keep this for external imports
# TODO: fix the external imports
from saqc.lib.rolling import customRoller
T = TypeVar("T", str, float, int)
def assertScalar(name, value, optional=False):
if (not np.isscalar(value)) and (value is not None) and (optional is True):
raise ValueError(f"'{name}' needs to be a scalar or 'None'")
......@@ -30,9 +32,9 @@ def assertScalar(name, value, optional=False):
raise ValueError(f"'{name}' needs to be a scalar")
def toSequence(value: Union[Any, Sequence[Any]]) -> List[Any]:
if np.isscalar(value):
value = [value]
def toSequence(value: T | Sequence[T]) -> List[T]:
if isinstance(value, (str, int, float)):
return [value]
return list(value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment