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

        self._fit_first(first)

        matrix = []
        for datapoint in self._iter_valid(X, first=first):
            self._fit_step(datapoint)
            vector = self._transform_step(datapoint)
            matrix.append(vector.reshape((1, -1)))

        N = len(self.indexes)
        for i, vector in enumerate(matrix):
            if len(vector) == N:
                break
            # This works because one-hot encoded features go at the end
            vector = numpy.array(vector)
            vector.resize((1, N))
            matrix[i] = vector

        if not matrix:
            result = numpy.zeros((0, N))
        else:
            result = numpy.concatenate(matrix)

        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._fit_transform