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


Python common._asarray_tuplesafe方法代码示例

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


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

示例1: test_to_tuples_na

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def test_to_tuples_na(self, tuples, na_tuple):
        # GH 18756
        idx = IntervalIndex.from_tuples(tuples)
        result = idx.to_tuples(na_tuple=na_tuple)

        # check the non-NA portion
        expected_notna = Index(com._asarray_tuplesafe(tuples[:-1]))
        result_notna = result[:-1]
        tm.assert_index_equal(result_notna, expected_notna)

        # check the NA portion
        result_na = result[-1]
        if na_tuple:
            assert isinstance(result_na, tuple)
            assert len(result_na) == 2
            assert all(isna(x) for x in result_na)
        else:
            assert isna(result_na) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:20,代码来源:test_interval.py

示例2: unique

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def unique(values):
    """
    Compute unique values (not necessarily sorted) efficiently from input array
    of values

    Parameters
    ----------
    values : array-like

    Returns
    -------
    uniques
    """
    values = com._asarray_tuplesafe(values)
    f = lambda htype, caster: _unique_generic(values, htype, caster)
    return _hashtable_algo(f, values.dtype)


# def count(values, uniques=None):
#     f = lambda htype, caster: _count_generic(values, htype, caster)

#     if uniques is not None:
#         raise NotImplementedError
#     else:
#         return _hashtable_algo(f, values.dtype) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:27,代码来源:algorithms.py

示例3: _convert_1d

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def _convert_1d(values, unit, axis):
        def try_parse(values):
            try:
                return _dt_to_float_ordinal(tools.to_datetime(values))
            except Exception:
                return values

        if isinstance(values, (datetime, pydt.date)):
            return _dt_to_float_ordinal(values)
        elif isinstance(values, np.datetime64):
            return _dt_to_float_ordinal(tslib.Timestamp(values))
        elif isinstance(values, pydt.time):
            return dates.date2num(values)
        elif (is_integer(values) or is_float(values)):
            return values
        elif isinstance(values, compat.string_types):
            return try_parse(values)
        elif isinstance(values, (list, tuple, np.ndarray, Index)):
            if isinstance(values, Index):
                values = values.values
            if not isinstance(values, np.ndarray):
                values = com._asarray_tuplesafe(values)

            if is_integer_dtype(values) or is_float_dtype(values):
                return values

            try:
                values = tools.to_datetime(values)
                if isinstance(values, Index):
                    values = _dt_to_float_ordinal(values)
                else:
                    values = [_dt_to_float_ordinal(x) for x in values]
            except Exception:
                values = _dt_to_float_ordinal(values)

        return values 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:38,代码来源:_converter.py

示例4: get_kwargs_from_breaks

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def get_kwargs_from_breaks(self, breaks, closed='right'):
        """
        converts intervals in breaks format to a dictionary of kwargs to
        specific to the format expected by IntervalIndex.from_tuples
        """
        if len(breaks) == 0:
            return {'data': breaks}

        tuples = lzip(breaks[:-1], breaks[1:])
        if isinstance(breaks, (list, tuple)):
            return {'data': tuples}
        elif is_categorical_dtype(breaks):
            return {'data': breaks._constructor(tuples)}
        return {'data': com._asarray_tuplesafe(tuples)} 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:16,代码来源:test_construction.py

示例5: test_to_tuples

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def test_to_tuples(self, tuples):
        # GH 18756
        idx = IntervalIndex.from_tuples(tuples)
        result = idx.to_tuples()
        expected = Index(com._asarray_tuplesafe(tuples))
        tm.assert_index_equal(result, expected) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:8,代码来源:test_interval.py

示例6: test_factorize_tuple_list

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def test_factorize_tuple_list(self, data, expected_label, expected_level):
        # GH9454
        result = pd.factorize(data)

        tm.assert_numpy_array_equal(result[0],
                                    np.array(expected_label, dtype=np.intp))

        expected_level_array = com._asarray_tuplesafe(expected_level,
                                                      dtype=object)
        tm.assert_numpy_array_equal(result[1], expected_level_array) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,代码来源:test_algos.py

示例7: test_int64_overflow

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def test_int64_overflow(self):

        B = np.concatenate((np.arange(1000), np.arange(1000), np.arange(500)))
        A = np.arange(2500)
        df = DataFrame({'A': A,
                        'B': B,
                        'C': A,
                        'D': B,
                        'E': A,
                        'F': B,
                        'G': A,
                        'H': B,
                        'values': np.random.randn(2500)})

        lg = df.groupby(['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'])
        rg = df.groupby(['H', 'G', 'F', 'E', 'D', 'C', 'B', 'A'])

        left = lg.sum()['values']
        right = rg.sum()['values']

        exp_index, _ = left.index.sortlevel()
        tm.assert_index_equal(left.index, exp_index)

        exp_index, _ = right.index.sortlevel(0)
        tm.assert_index_equal(right.index, exp_index)

        tups = list(map(tuple, df[['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'
                                   ]].values))
        tups = com._asarray_tuplesafe(tups)

        expected = df.groupby(tups).sum()['values']

        for k, v in compat.iteritems(expected):
            assert left[k] == right[k[::-1]]
            assert left[k] == v
        assert len(left) == len(right) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:38,代码来源:test_sorting.py

示例8: _prep_window

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def _prep_window(self, **kwargs):
        """
        provide validation for our window type, return the window
        we have already been validated
        """

        window = self._get_window()
        if isinstance(window, (list, tuple, np.ndarray)):
            return com._asarray_tuplesafe(window).astype(float)
        elif is_integer(window):
            import scipy.signal as sig

            # the below may pop from kwargs
            def _validate_win_type(win_type, kwargs):
                arg_map = {'kaiser': ['beta'],
                           'gaussian': ['std'],
                           'general_gaussian': ['power', 'width'],
                           'slepian': ['width']}
                if win_type in arg_map:
                    return tuple([win_type] + _pop_args(win_type,
                                                        arg_map[win_type],
                                                        kwargs))
                return win_type

            def _pop_args(win_type, arg_names, kwargs):
                msg = '%s window requires %%s' % win_type
                all_args = []
                for n in arg_names:
                    if n not in kwargs:
                        raise ValueError(msg % n)
                    all_args.append(kwargs.pop(n))
                return all_args

            win_type = _validate_win_type(self.win_type, kwargs)
            # GH #15662. `False` makes symmetric window, rather than periodic.
            return sig.get_window(win_type, window, False).astype(float) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:38,代码来源:window.py

示例9: _convert_arr_indexer

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def _convert_arr_indexer(self, keyarr):
        keyarr = com._asarray_tuplesafe(keyarr)

        if self.categories._defer_to_indexing:
            return keyarr

        return self._shallow_copy(keyarr) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:9,代码来源:category.py

示例10: _convert_arr_indexer

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def _convert_arr_indexer(self, keyarr):
        keyarr = com._asarray_tuplesafe(keyarr)
        return keyarr 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:5,代码来源:base.py

示例11: _convert_arr_indexer

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def _convert_arr_indexer(self, keyarr):
        # Cast the indexer to uint64 if possible so
        # that the values returned from indexing are
        # also uint64.
        keyarr = com._asarray_tuplesafe(keyarr)
        if is_integer_dtype(keyarr):
            return com._asarray_tuplesafe(keyarr, dtype=np.uint64)
        return keyarr 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:10,代码来源:numeric.py

示例12: match

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def match(to_match, values, na_sentinel=-1):
    """
    Compute locations of to_match into values

    Parameters
    ----------
    to_match : array-like
        values to find positions of
    values : array-like
        Unique set of values
    na_sentinel : int, default -1
        Value to mark "not found"

    Examples
    --------

    Returns
    -------
    match : ndarray of integers
    """
    values = com._asarray_tuplesafe(values)
    htable, _, values, dtype, ndtype = _get_hashtable_algo(values)
    to_match, _, _ = _ensure_data(to_match, dtype)
    table = htable(min(len(to_match), 1000000))
    table.map_locations(values)
    result = table.lookup(to_match)

    if na_sentinel != -1:

        # replace but return a numpy array
        # use a Series because it handles dtype conversions properly
        from pandas import Series
        result = Series(result.ravel()).replace(-1, na_sentinel).values.\
            reshape(result.shape)

    return result 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:38,代码来源:algorithms.py

示例13: _set_labels

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def _set_labels(self, key, value):
        if isinstance(key, Index):
            key = key.values
        else:
            key = com._asarray_tuplesafe(key)
        indexer = self.index.get_indexer(key)
        mask = indexer == -1
        if mask.any():
            raise ValueError('%s not contained in the index' % str(key[mask]))
        self._set_values(indexer, value) 
开发者ID:birforce,项目名称:vnpy_crypto,代码行数:12,代码来源:series.py

示例14: convert

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def convert(values, unit, axis):
        def try_parse(values):
            try:
                return _dt_to_float_ordinal(tools.to_datetime(values))
            except Exception:
                return values

        if isinstance(values, (datetime, pydt.date)):
            return _dt_to_float_ordinal(values)
        elif isinstance(values, pydt.time):
            return dates.date2num(values)
        elif (com.is_integer(values) or com.is_float(values)):
            return values
        elif isinstance(values, compat.string_types):
            return try_parse(values)
        elif isinstance(values, (list, tuple, np.ndarray)):
            if not isinstance(values, np.ndarray):
                values = com._asarray_tuplesafe(values)

            if com.is_integer_dtype(values) or com.is_float_dtype(values):
                return values

            try:
                values = tools.to_datetime(values)
                if isinstance(values, Index):
                    values = values.map(_dt_to_float_ordinal)
                else:
                    values = [_dt_to_float_ordinal(x) for x in values]
            except Exception:
                pass

        return values 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:34,代码来源:converter.py

示例15: match

# 需要导入模块: from pandas.core import common [as 别名]
# 或者: from pandas.core.common import _asarray_tuplesafe [as 别名]
def match(to_match, values, na_sentinel=-1):
    """
    Compute locations of to_match into values

    Parameters
    ----------
    to_match : array-like
        values to find positions of
    values : array-like
        Unique set of values
    na_sentinel : int, default -1
        Value to mark "not found"

    Examples
    --------

    Returns
    -------
    match : ndarray of integers
    """
    values = com._asarray_tuplesafe(values)
    if issubclass(values.dtype.type, string_types):
        values = np.array(values, dtype='O')

    f = lambda htype, caster: _match_generic(to_match, values, htype, caster)
    result = _hashtable_algo(f, values.dtype)

    if na_sentinel != -1:

        # replace but return a numpy array
        # use a Series because it handles dtype conversions properly
        from pandas.core.series import Series
        result = Series(result.ravel()).replace(-1,na_sentinel).values.reshape(result.shape)

    return result 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:37,代码来源:algorithms.py


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