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


Python blist.blist方法代碼示例

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


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

示例1: submapping

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def submapping(self, start, stop):
        bounds, values, nothing = self._bounds, self._values, self.nothing
        
        lindex = bisect_right(bounds, start) if start is not None else 0
        rindex = (bisect_left(bounds, stop)
                  if stop is not None else len(bounds))

        res = type(self)()
        res._bounds = blist(bounds[lindex:rindex])
        res._values = blist(values[lindex:rindex + 1])
        
        if start is not None:
            res[:start] = nothing
        if stop is not None:
            res[stop:] = nothing

        return res 
開發者ID:ActiveState,項目名稱:code,代碼行數:19,代碼來源:recipe-577515.py

示例2: set

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def set(self, indexes=None, columns=None, values=None):
        """
        Given indexes and columns will set a sub-set of the DataFrame to the values provided. This method will direct
        to the below methods based on what types are passed in for the indexes and columns. If the indexes or columns
        contains values not in the DataFrame then new rows or columns will be added.

        :param indexes: indexes value, list of indexes values, or a list of booleans. If None then all indexes are used
        :param columns: columns name, if None then all columns are used. Currently can only handle a single column or\
        all columns
        :param values: value or list of values to set (index, column) to. If setting just a single row, then must be a\
        dict where the keys are the column names. If a list then must be the same length as the indexes parameter, if\
        indexes=None, then must be the same and length of DataFrame
        :return: nothing
        """
        if (indexes is not None) and (columns is not None):
            if isinstance(indexes, (list, blist)):
                self.set_column(indexes, columns, values)
            else:
                self.set_cell(indexes, columns, values)
        elif (indexes is not None) and (columns is None):
            self.set_row(indexes, values)
        elif (indexes is None) and (columns is not None):
            self.set_column(indexes, columns, values)
        else:
            raise ValueError('either or both of indexes or columns must be provided') 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:27,代碼來源:dataframe.py

示例3: to_json

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def to_json(self):
        """
        Returns a JSON of the entire DataFrame that can be reconstructed back with raccoon.from_json(input). Any object
        that cannot be serialized will be replaced with the representation of the object using repr(). In that instance
        the DataFrame will have a string representation in place of the object and will not reconstruct exactly.

        :return: json string
        """
        input_dict = {'data': self.to_dict(index=False), 'index': list(self._index)}

        # if blist, turn into lists
        if self.blist:
            input_dict['index'] = list(input_dict['index'])
            for key in input_dict['data']:
                input_dict['data'][key] = list(input_dict['data'][key])

        meta_data = dict()
        for key in self.__slots__:
            if key not in ['_data', '_index']:
                value = self.__getattribute__(key)
                meta_data[key.lstrip('_')] = value if not isinstance(value, blist) else list(value)
        meta_data['use_blist'] = meta_data.pop('blist')
        input_dict['meta_data'] = meta_data
        return json.dumps(input_dict, default=repr) 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:26,代碼來源:dataframe.py

示例4: delete_rows

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def delete_rows(self, indexes):
        """
        Delete rows from the DataFrame

        :param indexes: either a list of values or list of booleans for the rows to delete
        :return: nothing
        """
        indexes = [indexes] if not isinstance(indexes, (list, blist)) else indexes
        if all([isinstance(i, bool) for i in indexes]):  # boolean list
            if len(indexes) != len(self._index):
                raise ValueError('boolean indexes list must be same size of existing indexes')
            indexes = [i for i, x in enumerate(indexes) if x]
        else:
            indexes = [sorted_index(self._index, x) for x in indexes] if self._sort \
                else [self._index.index(x) for x in indexes]
        indexes = sorted(indexes, reverse=True)  # need to sort and reverse list so deleting works
        for c, _ in enumerate(self._columns):
            for i in indexes:
                del self._data[c][i]
        # now remove from index
        for i in indexes:
            del self._index[i] 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:24,代碼來源:dataframe.py

示例5: delete_columns

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def delete_columns(self, columns):
        """
        Delete columns from the DataFrame

        :param columns: list of columns to delete
        :return: nothing
        """
        columns = [columns] if not isinstance(columns, (list, blist)) else columns
        if not all([x in self._columns for x in columns]):
            raise ValueError('all columns must be in current columns')
        for column in columns:
            c = self._columns.index(column)
            del self._data[c]
            del self._columns[c]
        if not len(self._data):  # if all the columns have been deleted, remove index
            self.index = list() 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:18,代碼來源:dataframe.py

示例6: sort_columns

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def sort_columns(self, column, key=None, reverse=False):
        """
        Sort the DataFrame by one of the columns. The sort modifies the DataFrame inplace. The key and reverse
        parameters have the same meaning as for the built-in sort() function.

        :param column: column name to use for the sort
        :param key: if not None then a function of one argument that is used to extract a comparison key from each
                    list element
        :param reverse: if True then the list elements are sort as if each comparison were reversed.
        :return: nothing
        """
        if isinstance(column, (list, blist)):
            raise TypeError('Can only sort by a single column  ')
        sort = sorted_list_indexes(self._data[self._columns.index(column)], key, reverse)
        # sort index
        self._index = blist([self._index[x] for x in sort]) if self._blist else [self._index[x] for x in sort]
        # each column
        for c in range(len(self._data)):
            self._data[c] = blist([self._data[c][i] for i in sort]) if self._blist else [self._data[c][i] for i in sort] 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:21,代碼來源:dataframe.py

示例7: delete

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def delete(self, indexes):
        """
        Delete rows from the DataFrame

        :param indexes: either a list of values or list of booleans for the rows to delete
        :return: nothing
        """
        indexes = [indexes] if not isinstance(indexes, (list, blist)) else indexes
        if all([isinstance(i, bool) for i in indexes]):  # boolean list
            if len(indexes) != len(self._index):
                raise ValueError('boolean indexes list must be same size of existing indexes')
            indexes = [i for i, x in enumerate(indexes) if x]
        else:
            indexes = [sorted_index(self._index, x) for x in indexes] if self._sort \
                else [self._index.index(x) for x in indexes]
        indexes = sorted(indexes, reverse=True)  # need to sort and reverse list so deleting works
        for i in indexes:
            del self._data[i]
        # now remove from index
        for i in indexes:
            del self._index[i] 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:23,代碼來源:series.py

示例8: test_sort_index

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def test_sort_index():
    # test on list
    df = rc.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}, columns=['a', 'b'], index=[10, 8, 9], sort=False)

    df.sort_index()
    assert isinstance(df.index, list)
    assert_frame_equal(df, rc.DataFrame({'a': [2, 3, 1], 'b': [5, 6, 4]}, columns=['a', 'b'], index=[8, 9, 10],
                                        sort=False))

    # test on blist
    df = rc.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}, columns=['a', 'b'], index=[10, 8, 9], sort=False,
                      use_blist=True)

    df.sort_index()
    assert isinstance(df.index, blist)
    assert_frame_equal(df, rc.DataFrame({'a': [2, 3, 1], 'b': [5, 6, 4]}, columns=['a', 'b'], index=[8, 9, 10],
                                        sort=False, use_blist=True))

    # fails on mixed type columns
    df = rc.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}, columns=['a', 'b'], index=[10, 'a', 9])
    if PYTHON3:
        with pytest.raises(TypeError):
            df.sort_index() 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:25,代碼來源:test_sort.py

示例9: test_show

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def test_show():
    df = rc.DataFrame({'a': [1, 2, 3], 'b': [1.0, 2.55, 3.1], 'c': ['first', 'second', None]}, columns=['b', 'c', 'a'],
                      index=['row1', 'row2', 'row3'], use_blist=True)

    # __repr__ produces a simple representation
    expected = "object id: %s\ncolumns:\nblist(['b', 'c', 'a'])\ndata:\nblist([blist([1.0, 2.55, 3.1]), blist([" \
               "'first', 'second', None]), blist([1, 2, 3])])\nindex:\nblist(['row1', 'row2', 'row3'])\n" % id(df)
    actual = df.__repr__()
    assert actual == expected

    # __str__ produces the standard table
    expected = 'index       b  c         a\n-------  ----  ------  ---\nrow1     1     first     1\n' \
               'row2     2.55  second    2\nrow3     3.1             3'
    actual = df.__str__()
    assert actual == expected

    # show() method will pass along any argument for the tabulate.tabulate function
    df.show() 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:20,代碼來源:test_dataframe.py

示例10: test_index_blist

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def test_index_blist():
    actual = rc.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]}, index=['a', 'b', 'c'], columns=['b', 'a'], use_blist=True)
    result = actual.index
    assert result == ['a', 'b', 'c']
    assert isinstance(result, blist)

    # test that a view is returned
    result.append('bad')
    assert actual.index == ['a', 'b', 'c', 'bad']

    actual.index = [9, 10, 11]
    assert actual.index == [9, 10, 11]
    assert isinstance(result, blist)

    # index too long
    with pytest.raises(ValueError):
        actual.index = [1, 3, 4, 5, 6] 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:19,代碼來源:test_getters.py

示例11: test_sort_index

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def test_sort_index():
    # test on list
    srs = rc.Series([4, 5, 6], index=[10, 8, 9], sort=False)

    srs.sort_index()
    assert isinstance(srs.index, list)
    assert_series_equal(srs, rc.Series([5, 6, 4], index=[8, 9, 10], sort=False))

    # test on blist
    srs = rc.Series([4, 5, 6], index=[10, 8, 9], sort=False, use_blist=True)

    srs.sort_index()
    assert isinstance(srs.index, blist)
    assert_series_equal(srs, rc.Series([5, 6, 4], index=[8, 9, 10], sort=False, use_blist=True))

    # fails on mixed type columns
    srs = rc.Series([4, 5, 6], index=[10, 'a', 9])
    if PYTHON3:
        with pytest.raises(TypeError):
            srs.sort_index() 
開發者ID:rsheftel,項目名稱:raccoon,代碼行數:22,代碼來源:test_sort.py

示例12: __init__

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def __init__(self, other={}):
        self._bounds = blist()
        self._values = blist([self.nothing])
        # Invariant: self[key] == self._values[bisect_right(self._bounds, key)]
        self.update(other) 
開發者ID:ActiveState,項目名稱:code,代碼行數:7,代碼來源:recipe-577515.py

示例13: __init__

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def __init__(self):
        self._q = blist.blist() # a sorted list of [(priority, idx), ...]
        self._items = {} # maps idx -> item
        self._counter = itertools.count() 
開發者ID:statgen,項目名稱:pheweb,代碼行數:6,代碼來源:load_utils.py

示例14: __init__

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def __init__(self):
        self._q = blist.blist()
        # self._q is like sorted([(key, variant_dict, [reader_id, ...]), ...])
        # key is like (chrom_idx, pos, ref, alt) 
開發者ID:statgen,項目名稱:pheweb,代碼行數:6,代碼來源:sites.py

示例15: __init__

# 需要導入模塊: import blist [as 別名]
# 或者: from blist import blist [as 別名]
def __init__(self):
        self._q = blist.blist()
        self._items = {}
        self._idx = 0 # Handle uncomparable items 
開發者ID:statgen,項目名稱:encore,代碼行數:6,代碼來源:make_manhattan_json.py


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