Expose data and flag through `SaQC`
Expose our main data structures through the SaQC
API. In order to not share to many implementation details data
and flags
are of the abstract type MutableMapping
.
Merge request reports
Activity
an other solution where we dont depend on mutable mapping, would be to make a accessor like this:
class Accessor: def __init__(self, obj, which): if which == 'flags': self.container = obj._flags elif which == 'data': self.container = obj._data elif which == 'history': self.container = obj._flags.history def __getitem__(self, key): return self.container[key] @property def columns(self): return self.container.columns def __repr__(self): return self.container.__repr__()
with:
class SaQC: ... @property def data(self): return Accessor(self.evaluate(), 'data') @property def flags(self): return Accessor(self.evaluate(), 'flags') @property def history(self): return Accessor(self.evaluate(), 'history') ...
With that we have more control (like reliable exposing
columns
, see above inAccessor
) and provide all basic features, like:- representation (nice dios prints)
- item selection
- columns access
but nothing more, so we don't expose any datastructure, especially not our custom internal-only structures. We also gain the possibility to add stuff (attributes/methods to accessor) that not necessarily need to go to our internal data structures (one could imagine a plot method for data or multi field selector for flags, like
flags[['a', 'b']]
or whatever fancy, if needed)
then we have:
>>> qc = saqc.SaQC(..) >>> qc.history # non-informative (<saqc.core.flags._HistAccess object at 0x...>) >>> qc.data # noice dios print (via Accessor.__repr__) >>> qc.flags # noice dios print (via Accessor.__repr__) >>> qc.data['a'] # -> pd.Series >>> qc.flags['a'] # -> pd.Series >>> qc.history['a'] # -> pd.DataFrame >>> qc.data.columns # -> pd.Index (columns of data) >>> qc.flags.columns # -> pd.Index (columns of flags) >>> qc.history.columns # -> pd.Index (columns of flags! )
and nothing more..
Edited by Bert PalmI know we discussed that before. But honestly, I am not a big fan of accessors. They add so much boilerploite code, obfuscate access patterns and complicate debugging. I stumpled upon
HistAccess
more than once...I am fine with a declared output type of Mapping, this refuses to give any garantuees about the type, but still allows to reuse the data structures on your on risk.
I think, the accesor could be formulated in a simpler way:
class Accessor: def __init__(self, obj): self.container = obj def __getitem__(self, key): return self.container[key] @property def columns(self): return self.container.columns def __repr__(self): return self.container.__repr__()
class SaQC: ... @property def data(self): return Accessor(self.evaluate()._data) @property def flags(self): return Accessor(self.evaluate()._flags) ...
Edited by David Schäferadded 6 commits
-
0973a7f3...25e119d8 - 3 commits from branch
develop
- 35affcce - [FIX] removed '_original' leftovers
- 806bd3fa - Merge branch 'develop' into datastructs
- ae166ddc - expose data/flags through an accessor
Toggle commit list-
0973a7f3...25e119d8 - 3 commits from branch
- Resolved by David Schäfer
in order to get things simpler, i would remove the mutable mapping inheritance, shouldn't we?
- Resolved by David Schäfer
- Resolved by David Schäfer
enabled an automatic merge when the pipeline for 3ee29678 succeeds
mentioned in commit 4a0c0ad3