def _collate_metadata(self):
        """Turns a list of objects associated with a classification result into a DataFrame of
        metadata.

        Returns
        -------
        None, but stores a result in self._cached.
        """
        import pandas as pd

        DEFAULT_FIELDS = None
        metadata = []

        for c in self._classifications:
            m = c.sample.metadata

            if DEFAULT_FIELDS is None:
                DEFAULT_FIELDS = list(m._resource._schema["properties"].keys())
                DEFAULT_FIELDS.remove("$uri")
                DEFAULT_FIELDS.remove("sample")

            metadatum = {f: getattr(m, f) for f in DEFAULT_FIELDS}
            metadatum["classification_id"] = c.id
            metadatum["sample_id"] = m.sample.id
            metadatum["metadata_id"] = m.id
            metadatum["created_at"] = m.sample.created_at
            metadatum["filename"] = c.sample.filename

            metadatum.update(m.custom)
            metadata.append(metadatum)

        if metadata:
            metadata = pd.DataFrame(metadata).set_index("classification_id")
        else:
            metadata = pd.DataFrame(
                columns=["classification_id", "sample_id", "metadata_id", "created_at"]
            )

        self._cached["metadata"] = metadata
def _collate_metadata ( self ) : import pandas as pd DEFAULT_FIELDS = None metadata = [ ] for c in self . _classifications : m = c . sample . metadata if DEFAULT_FIELDS is None : DEFAULT_FIELDS = list ( m . _resource . _schema [ "properties" ] . keys ( ) ) DEFAULT_FIELDS . remove ( "$uri" ) DEFAULT_FIELDS . remove ( "sample" ) metadatum = { f : getattr ( m , f ) for f in DEFAULT_FIELDS } metadatum [ "classification_id" ] = c . id metadatum [ "sample_id" ] = m . sample . id metadatum [ "metadata_id" ] = m . id metadatum [ "created_at" ] = m . sample . created_at metadatum [ "filename" ] = c . sample . filename metadatum . update ( m . custom ) metadata . append ( metadatum ) if metadata : metadata = pd . DataFrame ( metadata ) . set_index ( "classification_id" ) else : metadata = pd . DataFrame ( columns = [ "classification_id" , "sample_id" , "metadata_id" , "created_at" ] ) self . _cached [ "metadata" ] = metadata
Turns a list of objects associated with a classification result into a DataFrame of
        metadata.

        Returns
        -------
        None, but stores a result in self._cached.