def quantile(self, q):
        t = 0
        N = float(self.n)

        for i, key in enumerate(self.C.keys()):
            c_i = self.C[key]
            if i == len(self) - 1:
                delta = (c_i.mean - self.C.prev_item(key)[1].mean) / 2.
            else:
                delta = (self.C.succ_item(key)[1].mean - c_i.mean) / 2.
            z = max(-1, (q - c_i.mean) / delta)

            if z < 1:
                return t / N + c_i.count / N * (z + 1) / 2

            t += c_i.count
        return 1
Merge spans *in-place* within parent doc so that each takes up a single token.
dataset/ETHPy150Open CamDavidsonPilon/tdigest/tdigest/tdigest.py/TDigest.quantile--crossover with--dataset/ETHPy150Open chartbeat-labs/textacy/textacy/spacy_utils.py/merge_spans