Skip to content
Snippets Groups Projects

Several fixes

Closed David Schäfer requested to merge multifix into develop
1 unresolved thread
2 files
+ 6
56
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 6
24
#!/usr/bin/env python
from __future__ import annotations
import pandas as pd
@@ -45,7 +44,6 @@ class _HistAccess:
History._validateHistWithMask(value.hist, value.mask)
self.obj._data[key] = value
self.obj._cache.pop(key, None)
class Flags:
@@ -175,14 +173,8 @@ class Flags:
# with python 3.7 dicts are insertion-ordered by default
self._data = self._initFromRaw(raw_data, copy)
# this is a simple cache that reduce the calculation of the flags
# from the entire history of a flag column. The _cache is filled
# with __getitem__ and cleared on any write access to self_data.
# There are not to may write access possibilities here so we don't
# have to much trouble.
self._cache = {}
def _initFromRaw(self, data, copy) -> Dict[str, History]:
@staticmethod
def _initFromRaw(data: Mapping, copy: bool) -> Dict[str, History]:
"""
init from dict-like: keys are flag column, values become
initial columns of history(s).
@@ -250,16 +242,12 @@ class Flags:
if not len(value) == len(self):
raise ValueError("index must match current index in length")
_data, _cache = {}, {}
_data = {}
for old, new in zip(self.columns, value):
_data[new] = self._data[old]
if old in self._cache:
_cache[new] = self._cache[old]
self._data = _data
self._cache = _cache
@property
def empty(self) -> bool:
@@ -283,11 +271,7 @@ class Flags:
# item access
def __getitem__(self, key: str) -> pd.Series:
if key not in self._cache:
self._cache[key] = self._data[key].max()
return self._cache[key].copy()
return self._data[key].max()
def __setitem__(self, key: SelectT, value: ValueT):
# force-KW is internal available only
@@ -330,11 +314,9 @@ class Flags:
self._data[key] = History()
self._data[key].append(value, force=True)
self._cache.pop(key, None)
def __delitem__(self, key):
self._data.pop(key)
self._cache.pop(key, None)
def drop(self, key: str):
"""
@@ -418,8 +400,8 @@ class Flags:
"""
di = dios.DictOfSeries(columns=self.columns)
for k, v in self._data.items():
di[k] = self[k] # use cache
for k in self._data.keys():
di[k] = self[k]
return di.copy()
Loading