当前位置: 首页>>代码示例>>Python>>正文


Python lib.maybe_booleans_to_slice方法代码示例

本文整理汇总了Python中pandas._libs.lib.maybe_booleans_to_slice方法的典型用法代码示例。如果您正苦于以下问题:Python lib.maybe_booleans_to_slice方法的具体用法?Python lib.maybe_booleans_to_slice怎么用?Python lib.maybe_booleans_to_slice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pandas._libs.lib的用法示例。


在下文中一共展示了lib.maybe_booleans_to_slice方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_maybe_booleans_to_slice

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_booleans_to_slice [as 别名]
def test_maybe_booleans_to_slice(self):
        arr = np.array([0, 0, 1, 1, 1, 0, 1], dtype=np.uint8)
        result = lib.maybe_booleans_to_slice(arr)
        assert result.dtype == np.bool_

        result = lib.maybe_booleans_to_slice(arr[:0])
        assert result == slice(0, 0) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:9,代码来源:test_lib.py

示例2: __getitem__

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_booleans_to_slice [as 别名]
def __getitem__(self, key):
        """
        This getitem defers to the underlying array, which by-definition can
        only handle list-likes, slices, and integer scalars
        """

        is_int = lib.is_integer(key)
        if lib.is_scalar(key) and not is_int:
            raise IndexError("only integers, slices (`:`), ellipsis (`...`), "
                             "numpy.newaxis (`None`) and integer or boolean "
                             "arrays are valid indices")

        getitem = self._data.__getitem__
        if is_int:
            val = getitem(key)
            return self._box_func(val)

        if com.is_bool_indexer(key):
            key = np.asarray(key, dtype=bool)
            if key.all():
                key = slice(0, None, None)
            else:
                key = lib.maybe_booleans_to_slice(key.view(np.uint8))

        is_period = is_period_dtype(self)
        if is_period:
            freq = self.freq
        else:
            freq = None
            if isinstance(key, slice):
                if self.freq is not None and key.step is not None:
                    freq = key.step * self.freq
                else:
                    freq = self.freq
            elif key is Ellipsis:
                # GH#21282 indexing with Ellipsis is similar to a full slice,
                #  should preserve `freq` attribute
                freq = self.freq

        result = getitem(key)
        if result.ndim > 1:
            # To support MPL which performs slicing with 2 dim
            # even though it only has 1 dim by definition
            if is_period:
                return self._simple_new(result, dtype=self.dtype, freq=freq)
            return result

        return self._simple_new(result, dtype=self.dtype, freq=freq) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:50,代码来源:datetimelike.py

示例3: __getitem__

# 需要导入模块: from pandas._libs import lib [as 别名]
# 或者: from pandas._libs.lib import maybe_booleans_to_slice [as 别名]
def __getitem__(self, key):
        """
        This getitem defers to the underlying array, which by-definition can
        only handle list-likes, slices, and integer scalars
        """

        is_int = is_integer(key)
        if is_scalar(key) and not is_int:
            raise IndexError("only integers, slices (`:`), ellipsis (`...`), "
                             "numpy.newaxis (`None`) and integer or boolean "
                             "arrays are valid indices")

        getitem = self._data.__getitem__
        if is_int:
            val = getitem(key)
            return self._box_func(val)
        else:
            if com.is_bool_indexer(key):
                key = np.asarray(key)
                if key.all():
                    key = slice(0, None, None)
                else:
                    key = lib.maybe_booleans_to_slice(key.view(np.uint8))

            attribs = self._get_attributes_dict()

            is_period = isinstance(self, ABCPeriodIndex)
            if is_period:
                freq = self.freq
            else:
                freq = None
                if isinstance(key, slice):
                    if self.freq is not None and key.step is not None:
                        freq = key.step * self.freq
                    else:
                        freq = self.freq

            attribs['freq'] = freq

            result = getitem(key)
            if result.ndim > 1:
                # To support MPL which performs slicing with 2 dim
                # even though it only has 1 dim by definition
                if is_period:
                    return self._simple_new(result, **attribs)
                return result

            return self._simple_new(result, **attribs) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:50,代码来源:datetimelike.py


注:本文中的pandas._libs.lib.maybe_booleans_to_slice方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。