flagCrossStatistics fails
import saqc, dios
a=pd.Series([1,2,3], index=[1,2,3])
b=pd.Series([1,5], index=[1,5])
di = dios.DictOfSeries(dict(a=a, b=b))
qc = saqc.SaQC(di)
qc.outliers.flagCrossStatistic('dummy', fields=['a', 'b'], thresh=3.5)
--> fails see Traceback
i guess the problem arise from a unaligned mask passed to flags.. i suggest to insert a simple reindex
just before passing the mask.
Click to expand
Traceback
Exception:
ValueError: bad mask
field: dummy
function: outliers.flagCrossStatistic
arguments: ()
keywords: {'nodata': nan, 'flag': 255.0, 'fields': ['a', 'b'], 'thresh': 3.5, 'cross_stat': 'modZscore', 'to_mask': True}
Traceback (most recent call last):
File "/home/palmb/.virtualenvs/gcef_pipeline/lib/python3.8/site-packages/pandas/core/series.py", line 972, in __setitem__
self._set_with_engine(key, value)
File "/home/palmb/.virtualenvs/gcef_pipeline/lib/python3.8/site-packages/pandas/core/series.py", line 1005, in _set_with_engine
loc = self.index._engine.get_loc(key)
File "pandas/_libs/index.pyx", line 70, in pandas._libs.index.IndexEngine.get_loc
File "pandas/_libs/index.pyx", line 75, in pandas._libs.index.IndexEngine.get_loc
TypeError: '1 False
Name: a, dtype: bool' is an invalid key
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/flags.py", line 321, in __setitem__
tmp[mask] = value
File "/home/palmb/.virtualenvs/gcef_pipeline/lib/python3.8/site-packages/pandas/core/series.py", line 989, in __setitem__
key = check_bool_indexer(self.index, key)
File "/home/palmb/.virtualenvs/gcef_pipeline/lib/python3.8/site-packages/pandas/core/indexing.py", line 2269, in check_bool_indexer
raise IndexingError(
pandas.core.indexing.IndexingError: Unalignable boolean Series provided as indexer (index of the boolean Series and of the indexed object do not match).
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/modules/outliers.py", line 121, in flagCrossStatistic
return self.defer("flagCrossStatistic", locals())
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/modules/base.py", line 20, in defer
return self.obj._wrap(FUNC_MAP[f"{self}.{fname}"])(**flocals, **fkwargs)
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/core.py", line 340, in inner
return out.evaluate()
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/core.py", line 262, in evaluate
_handleErrors(e, selector.field, control, function, self._error_policy)
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/core.py", line 56, in _handleErrors
raise exc
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/core.py", line 254, in evaluate
data_result, flags_result = function(data, selector.field, flags)
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/lib.py", line 69, in __call__
return self.func(data, field, flags, *self.args, *args, **keywords)
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/register.py", line 55, in callWrapper
result = func(*args, **kwargs)
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/funcs/outliers.py", line 1227, in flagCrossStatistic
flags[mask[var], var] = flag
File "/home/palmb/projects/gcef_pipeline/saqc/saqc/core/flags.py", line 323, in __setitem__
raise ValueError("bad mask")
ValueError: bad mask
Edited by Bert Palm