pydrepr/drepr/outputs/array_backend/array_class.py
def group_by(self, predicate: Union[str, ArrayPredicate]) -> Iterable[Tuple[Any, 'ArrayClass']]:
        """Group by predicate (can be string or predicate id)"""
        if isinstance(predicate, str):
            # perform group by the predicate uri
            if len(self.pred2attrs[predicate]) > 1:
                raise Exception("Key of group_by operator cannot be a list")
            # p = self.p(predicate)[0]
            o = self.attrs[self.pred2attrs[predicate][0]]
        else:
            o = predicate.attr

        if o.size == 1:
            yield o.get_first_value(), self
        else:
            groups = defaultdict(set)
            for id in np.ndindex(self.pk_attr.shape):
                for val in o.get_mval(id):
                    groups[val].add(id)
            for val, ids in groups.items():
                yield val, SubsetArrayClass(self, ids)
Group by predicate (can be string or predicate id)
Group by predicate (can be string or predicate id)
Group by predicate ( can be string or predicate id )
def group_by(self, predicate: Union[str, ArrayPredicate]) -> Iterable[Tuple[Any, 'ArrayClass']]:
        if isinstance(predicate, str):
            if len(self.pred2attrs[predicate]) > 1:
                raise Exception("Key of group_by operator cannot be a list")
            o = self.attrs[self.pred2attrs[predicate][0]]
        else:
            o = predicate.attr
        if o.size == 1:
            yield o.get_first_value(), self
        else:
            groups = defaultdict(set)
            for id in np.ndindex(self.pk_attr.shape):
                for val in o.get_mval(id):
                    groups[val].add(id)
            for val, ids in groups.items():
                yield val, SubsetArrayClass(self, ids)
def group_by ( self , predicate : Union [ str , ArrayPredicate ] ) -> Iterable [ Tuple [ Any , 'ArrayClass' ] ] : if isinstance ( predicate , str ) : if len ( self . pred2attrs [ predicate ] ) > 1 : raise Exception ( "Key of group_by operator cannot be a list" ) o = self . attrs [ self . pred2attrs [ predicate ] [ 0 ] ] else : o = predicate . attr if o . size == 1 : yield o . get_first_value ( ) , self else : groups = defaultdict ( set ) for id in np . ndindex ( self . pk_attr . shape ) : for val in o . get_mval ( id ) : groups [ val ] . add ( id ) for val , ids in groups . items ( ) : yield val , SubsetArrayClass ( self , ids )
Group by predicate (can be string or predicate id)
Group by predicate ( can be string or predicate id )
"""Group by predicate (can be string or predicate id)""" # perform group by the predicate uri # p = self.p(predicate)[0]
self
predicate
Union[str, ArrayPredicate]