def _sparse_fit_transform(self, X):
        X = iter(X)
        try:
            first = next(X)
        except (TypeError, __HOLE__):
            raise ValueError("Cannot fit with an empty dataset")
        logger.debug("Starting flattener.fit_transform")

        self._fit_first(first)

        data = array.array("d")
        indices = array.array("i")
        indptr = array.array("i", [0])

        for datapoint in self._iter_valid(X, first=first):
            self._fit_step(datapoint)
            for i, value in self._sparse_transform_step(datapoint):
                data.append(value)
                indices.append(i)
            indptr.append(len(data))

        if len(indptr) == 0:
            result = numpy.zeros((0, len(self.indexes)))
        else:
            result = csr_matrix((data, indices, indptr),
                                dtype=float,
                                shape=(len(indptr) - 1, len(self.indexes)))

        logger.debug("Finished flattener.fit_transform")
        logger.debug("Matrix has size %sx%s" % result.shape)
        return result
dataset/ETHPy150Open machinalis/featureforge/featureforge/flattener.py/FeatureMappingFlattener._sparse_fit_transform