本文整理汇总了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
示例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')
示例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)
示例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]
示例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()
示例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]
示例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]
示例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()
示例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()
示例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]
示例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()
示例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)
示例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()
示例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)
示例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