コード例 #1
0
ファイル: series.py プロジェクト: willgrass/pandas
    def map(self, arg):
        """
        Map values of Series using input correspondence (which can be
        a dict, Series, or function).

        Parameters
        ----------
        arg : function, dict, or Series

        Returns
        -------
        y : Series
            same index as caller
        """
        if isinstance(arg, (dict, Series)):
            if isinstance(arg, dict):
                arg = Series(arg)

            indexer, mask = tseries.getMergeVec(self, arg.index.indexMap)

            newValues = arg.view(np.ndarray).take(indexer)
            np.putmask(newValues, -mask, np.nan)

            newSer = Series(newValues, index=self.index)
            return newSer
        else:
            return Series([arg(x) for x in self], index=self.index)
コード例 #2
0
    def _join_on(self, other, on):
        if len(other.index) == 0:
            return self

        if on not in self:
            raise Exception('%s column not contained in this frame!' % on)

        fillVec, mask = tseries.getMergeVec(self[on], other.index.indexMap)

        tmpMatrix = other.values.take(fillVec, axis=0)
        tmpMatrix[-mask] = NaN

        seriesDict = dict(
            (col, tmpMatrix[:, j]) for j, col in enumerate(other.columns))

        if getattr(other, 'objects'):
            objects = other.objects

            tmpMat = objects.values.take(fillVec, axis=0)
            tmpMat[-mask] = NaN
            objDict = dict(
                (col, tmpMat[:, j]) for j, col in enumerate(objects.columns))

            seriesDict.update(objDict)

        filledFrame = DataFrame(data=seriesDict, index=self.index)

        return self.join(filledFrame, how='left')
コード例 #3
0
ファイル: series.py プロジェクト: jlsandell/pandas
    def map(self, arg):
        """
        Map values of Series using input correspondence (which can be
        a dict, Series, or function).

        Parameters
        ----------
        arg : function, dict, or Series

        Returns
        -------
        y : Series
            same index as caller
        """
        if isinstance(arg, (dict, Series)):
            if isinstance(arg, dict):
                arg = Series(arg)

            indexer, mask = tseries.getMergeVec(self, arg.index.indexMap)
            notmask = -mask

            newValues = arg.view(np.ndarray).take(indexer)

            if notmask.any():
                if issubclass(newValues.dtype.type, np.integer):
                    newValues = newValues.astype(float)

                np.putmask(newValues, notmask, np.nan)

            newSer = Series(newValues, index=self.index)
            return newSer
        else:
            return Series([arg(x) for x in self], index=self.index)
コード例 #4
0
ファイル: matrix.py プロジェクト: pedrot/pandas
    def _join_on(self, other, on):
        if len(other.index) == 0:
            return self

        if on not in self:
            raise Exception('%s column not contained in this frame!' % on)

        fillVec, mask = tseries.getMergeVec(self[on],
                                            other.index.indexMap)

        tmpMatrix = other.values.take(fillVec, axis=0)
        tmpMatrix[-mask] = NaN

        seriesDict = dict((col, tmpMatrix[:, j])
                           for j, col in enumerate(other.columns))

        if getattr(other, 'objects'):
            objects = other.objects

            tmpMat = objects.values.take(fillVec, axis=0)
            tmpMat[-mask] = NaN
            objDict = dict((col, tmpMat[:, j])
                           for j, col in enumerate(objects.columns))

            seriesDict.update(objDict)

        filledFrame = DataFrame(data=seriesDict, index=self.index)

        return self.join(filledFrame, how='left')
コード例 #5
0
ファイル: bench.py プロジェクト: choketsu/pandas
    def _test2():
        filler, mask = tseries.getMergeVec(new_index, index.indexMap)
        result = obj_vals.take(filler)
        np.putmask(result, -mask, np.NaN)

        return result
コード例 #6
0
ファイル: bench_tseries.py プロジェクト: theandygross/pandas
    def _test2():
        filler, mask = tseries.getMergeVec(new_index, index.indexMap)
        result = obj_vals.take(filler)
        np.putmask(result, -mask, np.NaN)

        return result