當前位置: 首頁>>代碼示例>>Python>>正文


Python common.is_null_slice方法代碼示例

本文整理匯總了Python中pandas.core.common.is_null_slice方法的典型用法代碼示例。如果您正苦於以下問題:Python common.is_null_slice方法的具體用法?Python common.is_null_slice怎麽用?Python common.is_null_slice使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pandas.core.common的用法示例。


在下文中一共展示了common.is_null_slice方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _slice

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def _slice(self, slicer):
        """
        Return a slice of myself.

        For internal compatibility with numpy arrays.
        """

        # only allow 1 dimensional slicing, but can
        # in a 2-d case be passd (slice(None),....)
        if isinstance(slicer, tuple) and len(slicer) == 2:
            if not com.is_null_slice(slicer[0]):
                raise AssertionError("invalid slicing for a 1-ndim "
                                     "categorical")
            slicer = slicer[1]

        codes = self._codes[slicer]
        return self._constructor(values=codes, dtype=self.dtype, fastpath=True) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:19,代碼來源:categorical.py

示例2: _getitem_tuple

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def _getitem_tuple(self, tup):
        try:
            return self._getitem_lowerdim(tup)
        except IndexingError:
            pass

        # no multi-index, so validate all of the indexers
        self._has_valid_tuple(tup)

        # ugly hack for GH #836
        if self._multi_take_opportunity(tup):
            return self._multi_take(tup)

        # no shortcut needed
        retval = self.obj
        for i, key in enumerate(tup):
            if i >= self.obj.ndim:
                raise IndexingError('Too many indexers')

            if com.is_null_slice(key):
                continue

            retval = getattr(retval, self.name)._getitem_axis(key, axis=i)

        return retval 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:27,代碼來源:indexing.py

示例3: _slice

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def _slice(self, slicer):
        """ Return a slice of myself.

        For internal compatibility with numpy arrays.
        """

        # only allow 1 dimensional slicing, but can
        # in a 2-d case be passd (slice(None),....)
        if isinstance(slicer, tuple) and len(slicer) == 2:
            if not com.is_null_slice(slicer[0]):
                raise AssertionError("invalid slicing for a 1-ndim "
                                     "categorical")
            slicer = slicer[1]

        _codes = self._codes[slicer]
        return self._constructor(values=_codes, categories=self.categories,
                                 ordered=self.ordered, fastpath=True) 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:19,代碼來源:categorical.py

示例4: _slice

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def _slice(self, slicer):
        """ Return a slice of myself.

        For internal compatibility with numpy arrays.
        """

        # only allow 1 dimensional slicing, but can
        # in a 2-d case be passd (slice(None),....)
        if isinstance(slicer, tuple) and len(slicer) == 2:
            if not is_null_slice(slicer[0]):
                raise AssertionError("invalid slicing for a 1-ndim "
                                     "categorical")
            slicer = slicer[1]

        _codes = self._codes[slicer]
        return self._constructor(values=_codes, categories=self.categories,
                                 ordered=self.ordered, fastpath=True) 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:19,代碼來源:categorical.py

示例5: iget

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def iget(self, col):

        if self.ndim == 2 and isinstance(col, tuple):
            col, loc = col
            if not com.is_null_slice(col) and col != 0:
                raise IndexError("{0} only contains one item".format(self))
            return self.values[loc]
        else:
            if col != 0:
                raise IndexError("{0} only contains one item".format(self))
            return self.values 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:13,代碼來源:blocks.py

示例6: _slice

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def _slice(self, slicer):
        """ return a slice of my values """

        # slice the category
        # return same dims as we currently have

        if isinstance(slicer, tuple) and len(slicer) == 2:
            if not com.is_null_slice(slicer[0]):
                raise AssertionError("invalid slicing for a 1-ndim "
                                     "categorical")
            slicer = slicer[1]

        return self.values[slicer] 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:15,代碼來源:blocks.py

示例7: iget

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def iget(self, col):

        if self.ndim == 2 and isinstance(col, tuple):
            col, loc = col
            if not is_null_slice(col) and col != 0:
                raise IndexError("{0} only contains one item".format(self))
            return self.values[loc]
        else:
            if col != 0:
                raise IndexError("{0} only contains one item".format(self))
            return self.values 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:13,代碼來源:internals.py

示例8: _slice

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def _slice(self, slicer):
        """ return a slice of my values """
        if isinstance(slicer, tuple):
            col, loc = slicer
            if not is_null_slice(col) and col != 0:
                raise IndexError("{0} only contains one item".format(self))
            return self.values[loc]
        return self.values[slicer] 
開發者ID:nccgroup,項目名稱:Splunking-Crime,代碼行數:10,代碼來源:internals.py

示例9: _getitem_nested_tuple

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def _getitem_nested_tuple(self, tup):
        # we have a nested tuple so have at least 1 multi-index level
        # we should be able to match up the dimensionaility here

        # we have too many indexers for our dim, but have at least 1
        # multi-index dimension, try to see if we have something like
        # a tuple passed to a series with a multi-index
        if len(tup) > self.ndim:
            result = self._handle_lowerdim_multi_index_axis0(tup)
            if result is not None:
                return result

            # this is a series with a multi-index specified a tuple of
            # selectors
            return self._getitem_axis(tup, axis=self.axis)

        # handle the multi-axis by taking sections and reducing
        # this is iterative
        obj = self.obj
        axis = 0
        for i, key in enumerate(tup):

            if com.is_null_slice(key):
                axis += 1
                continue

            current_ndim = obj.ndim
            obj = getattr(obj, self.name)._getitem_axis(key, axis=axis)
            axis += 1

            # if we have a scalar, we are done
            if is_scalar(obj) or not hasattr(obj, 'ndim'):
                break

            # has the dim of the obj changed?
            # GH 7199
            if obj.ndim < current_ndim:

                # GH 7516
                # if had a 3 dim and are going to a 2d
                # axes are reversed on a DataFrame
                if i >= 1 and current_ndim == 3 and obj.ndim == 2:
                    obj = obj.T

                axis -= 1

        return obj 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:49,代碼來源:indexing.py

示例10: _getitem_lowerdim

# 需要導入模塊: from pandas.core import common [as 別名]
# 或者: from pandas.core.common import is_null_slice [as 別名]
def _getitem_lowerdim(self, tup):

        # we can directly get the axis result since the axis is specified
        if self.axis is not None:
            axis = self.obj._get_axis_number(self.axis)
            return self._getitem_axis(tup, axis=axis)

        # we may have a nested tuples indexer here
        if self._is_nested_tuple_indexer(tup):
            return self._getitem_nested_tuple(tup)

        # we maybe be using a tuple to represent multiple dimensions here
        ax0 = self.obj._get_axis(0)
        # ...but iloc should handle the tuple as simple integer-location
        # instead of checking it as multiindex representation (GH 13797)
        if isinstance(ax0, MultiIndex) and self.name != 'iloc':
            result = self._handle_lowerdim_multi_index_axis0(tup)
            if result is not None:
                return result

        if len(tup) > self.obj.ndim:
            raise IndexingError("Too many indexers. handle elsewhere")

        # to avoid wasted computation
        # df.ix[d1:d2, 0] -> columns first (True)
        # df.ix[0, ['C', 'B', A']] -> rows first (False)
        for i, key in enumerate(tup):
            if is_label_like(key) or isinstance(key, tuple):
                section = self._getitem_axis(key, axis=i)

                # we have yielded a scalar ?
                if not is_list_like_indexer(section):
                    return section

                elif section.ndim == self.ndim:
                    # we're in the middle of slicing through a MultiIndex
                    # revise the key wrt to `section` by inserting an _NS
                    new_key = tup[:i] + (_NS,) + tup[i + 1:]

                else:
                    new_key = tup[:i] + tup[i + 1:]

                    # unfortunately need an odious kludge here because of
                    # DataFrame transposing convention
                    if (isinstance(section, ABCDataFrame) and i > 0 and
                            len(new_key) == 2):
                        a, b = new_key
                        new_key = b, a

                    if len(new_key) == 1:
                        new_key, = new_key

                # Slices should return views, but calling iloc/loc with a null
                # slice returns a new object.
                if com.is_null_slice(new_key):
                    return section
                # This is an elided recursive call to iloc/loc/etc'
                return getattr(section, self.name)[new_key]

        raise IndexingError('not applicable') 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:62,代碼來源:indexing.py


注:本文中的pandas.core.common.is_null_slice方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。