<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def mode(self, values, weights=None):
 """compute the mode within each group. Parameters values to compute the mode of per group weights : array_like, [keys], float, optional optional weight associated with each entry in values Returns ------- unique: ndarray, [groups] unique keys value array, reduced over groups """

        if weights is None:
            unique, weights = npi.count((self.index.sorted_group_rank_per_key, values))
        else:
            unique, weights = npi.group_by((self.index.sorted_group_rank_per_key, values)).sum(weights)

        x, bin = npi.group_by(unique[0]).argmax(weights)
        return x, unique[1][bin]