Skip to content
Snippets Groups Projects

Expose data and flag through `SaQC`

Merged David Schäfer requested to merge datastructs into develop
All threads resolved!

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

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • 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 in Accessor) 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 Palm
  • I 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äfer
  • David Schäfer added 6 commits

    added 6 commits

    Compare with previous version

  • David Schäfer resolved all threads

    resolved all threads

  • Bert Palm
  • Bert Palm
  • David Schäfer added 1 commit

    added 1 commit

    Compare with previous version

  • David Schäfer added 1 commit

    added 1 commit

    • 6d2d40a3 - Remove MutableMapping from Flags

    Compare with previous version

  • David Schäfer added 1 commit

    added 1 commit

    • 3ee29678 - Remove MutableMapping from DictOfSeries

    Compare with previous version

  • David Schäfer resolved all threads

    resolved all threads

  • David Schäfer approved this merge request

    approved this merge request

  • David Schäfer enabled an automatic merge when the pipeline for 3ee29678 succeeds

    enabled an automatic merge when the pipeline for 3ee29678 succeeds

  • David Schäfer mentioned in commit 4a0c0ad3

    mentioned in commit 4a0c0ad3

  • Please register or sign in to reply
    Loading