docstring stringlengths 52 499 | function stringlengths 67 35.2k | __index_level_0__ int64 52.6k 1.16M |
|---|---|---|
Associate the specified timeline and sketch.
Args:
sketch_id (int): ID of sketch
index_id (int): ID of timeline to add to sketch | def add_timeline_to_sketch(self, sketch_id, index_id):
resource_url = '{0:s}/sketches/{1:d}/timelines/'.format(
self.api_base_url, sketch_id)
form_data = {'timeline': [index_id]}
self.session.post(resource_url, json=form_data) | 372,103 |
Get information on the specified sketch.
Args:
sketch_id (int): ID of sketch
Returns:
dict: Dictionary of sketch information
Raises:
ValueError: Sketch is inaccessible | def get_sketch(self, sketch_id):
resource_url = '{0:s}/sketches/{1:d}/'.format(self.api_base_url, sketch_id)
response = self.session.get(resource_url)
response_dict = response.json()
try:
response_dict['objects']
except KeyError:
raise ValueError('Sketch does not exist or you have n... | 372,104 |
Copies the attribute container from a dictionary.
Args:
attributes (dict[str, object]): attribute values per name. | def copy_from_dict(self, attributes):
for attribute_name, attribute_value in attributes.items():
# Not using startswith to improve performance.
if attribute_name[0] == '_':
continue
setattr(self, attribute_name, attribute_value) | 372,105 |
Sets up the _keywords attribute.
Args:
keywords: pipe separated list of keyword to search | def setup(self, keywords=None): # pylint: disable=arguments-differ
self._keywords = keywords
self._output_path = tempfile.mkdtemp() | 372,110 |
Parse PDF files text content for keywords.
Args:
path: PDF file path.
Returns:
match: set of unique occurrences of every match. | def grepPDF(self, path):
with open(path, 'rb') as pdf_file_obj:
match = set()
text = ''
pdf_reader = PyPDF2.PdfFileReader(pdf_file_obj)
pages = pdf_reader.numPages
for page in range(pages):
page_obj = pdf_reader.getPage(page)
text += '\n' + page_obj.extractText()
... | 372,112 |
Populates the internal module pool with modules declared in a recipe.
Args:
recipe: Dict, recipe declaring modules to load. | def load_recipe(self, recipe):
self.recipe = recipe
for module_description in recipe['modules']:
# Combine CLI args with args from the recipe description
module_name = module_description['name']
module = self.config.get_module(module_name)(self)
self._module_pool[module_name] = modu... | 372,114 |
Thread-safe method to store data in the state's store.
Args:
container (containers.interface.AttributeContainer): The data to store. | def store_container(self, container):
with self._store_lock:
self.store.setdefault(container.CONTAINER_TYPE, []).append(container) | 372,115 |
Thread-safe method to retrieve data from the state's store.
Args:
container_class: AttributeContainer class used to filter data.
Returns:
A list of AttributeContainer objects of matching CONTAINER_TYPE. | def get_containers(self, container_class):
with self._store_lock:
return self.store.get(container_class.CONTAINER_TYPE, []) | 372,116 |
Performs setup tasks for each module in the module pool.
Threads declared modules' setup() functions. Takes CLI arguments into
account when replacing recipe parameters for each module.
Args:
args: Command line arguments that will be used to replace the parameters
declared in the recipe. | def setup_modules(self, args):
def _setup_module_thread(module_description):
new_args = utils.import_args_from_dict(
module_description['args'], vars(args), self.config)
module = self._module_pool[module_description['name']]
try:
module.setup(**new_args)
except... | 372,117 |
Adds an error to the state.
Args:
error: The text that will be added to the error list.
critical: If set to True and the error is checked with check_errors, will
dfTimewolf will abort. | def add_error(self, error, critical=False):
self.errors.append((error, critical)) | 372,119 |
Checks for errors and exits if any of them are critical.
Args:
is_global: If True, check the global_errors attribute. If false, check the
error attribute. | def check_errors(self, is_global=False):
errors = self.global_errors if is_global else self.errors
if errors:
print('dfTimewolf encountered one or more errors:')
for error, critical in errors:
print('{0:s} {1:s}'.format('CRITICAL: ' if critical else '', error))
if critical:
... | 372,121 |
Initialize the Turbinia artifact processor object.
Args:
state: The dfTimewolf state object | def __init__(self, state):
super(TurbiniaProcessor, self).__init__(state)
self.client = None
self.disk_name = None
self.instance = None
self.project = None
self.turbinia_region = None
self.turbinia_zone = None
self._output_path = None | 372,122 |
Sets up the object attributes.
Args:
disk_name (string): Name of the disk to process
project (string): The project containing the disk to process
turbinia_zone (string): The zone containing the disk to process | def setup(self, disk_name, project, turbinia_zone):
# TODO: Consider the case when multiple disks are provided by the previous
# module or by the CLI.
if project is None or turbinia_zone is None:
self.state.add_error(
'project or turbinia_zone are not all specified, bailing out',
... | 372,123 |
Pretty-prints task data.
Args:
task: Task dict generated by Turbinia. | def _print_task_data(self, task):
print(' {0:s} ({1:s})'.format(task['name'], task['id']))
paths = task.get('saved_paths', [])
if not paths:
return
for path in paths:
if path.endswith('worker-log.txt'):
continue
if path.endswith('{0:s}.log'.format(task.get('id'))):
... | 372,124 |
Displays the overall progress of tasks in a Turbinia job.
Args:
instance (string): The name of the Turbinia instance
project (string): The project containing the disk to process
region (string): Region where turbinia is configured.
request_id (string): The request ID provided by Turbinia.
... | def display_task_progress(
self, instance, project, region, request_id=None, user=None,
poll_interval=60):
total_completed = 0
while True:
task_results = self.client.get_task_data(
instance, project, region, request_id=request_id, user=user)
tasks = {task['id']: task for ... | 372,125 |
Initializes the Threat Intelligence container.
Args:
name (string): name of the threat
indicator (string): regular expression relevant to a threat | def __init__(self, name, indicator):
super(ThreatIntelligence, self).__init__()
self.name = name
self.indicator = indicator | 372,132 |
Sets up the _target_directory attribute.
Args:
target_directory: Directory in which collected files will be dumped. | def setup(self, target_directory=None): # pylint: disable=arguments-differ
self._target_directory = target_directory
if not target_directory:
self._target_directory = tempfile.mkdtemp()
elif not os.path.exists(target_directory):
try:
os.makedirs(target_directory)
except OSErr... | 372,134 |
Recursively copies files from source to destination_directory.
Args:
source: source file or directory to copy into destination_directory
destination_directory: destination directory in which to copy source | def _copy_file_or_directory(self, source, destination_directory):
if os.path.isdir(source):
for item in os.listdir(source):
full_source = os.path.join(source, item)
full_destination = os.path.join(destination_directory, item)
shutil.copytree(full_source, full_destination)
else... | 372,136 |
Initialize the base collector object.
Args:
state: a DFTimewolfState object.
critical: Whether the module is critical or not. If True and the module
encounters an error, then the whole recipe will fail. | def __init__(self, state, critical=False):
super(BaseModule, self).__init__()
self.critical = critical
self.state = state | 372,137 |
Checks if any values in a given dictionary still contain @ parameters.
Args:
value: Dictionary, list, or string that will be recursively checked for
placeholders
Raises:
ValueError: There still exists a value with an @ parameter.
Returns:
Top-level caller: a modified dict with replaced toke... | def check_placeholders(value):
if isinstance(value, six.string_types):
if TOKEN_REGEX.search(value):
raise ValueError('{0:s} must be replaced in dictionary'.format(value))
elif isinstance(value, list):
return [check_placeholders(item) for item in value]
elif isinstance(value, dict):
return {k... | 372,139 |
Returns a foreign function exported by `zbar`.
Args:
fname (:obj:`str`): Name of the exported function as string.
restype (:obj:): Return type - one of the `ctypes` primitive C data
types.
*args: Arguments - a sequence of `ctypes` primitive C data types.
Returns:
cddl.C... | def zbar_function(fname, restype, *args):
prototype = CFUNCTYPE(restype, *args)
return prototype((fname, load_libzbar())) | 372,417 |
Computes the bounding box of an iterable of (x, y) coordinates.
Args:
locations: iterable of (x, y) tuples.
Returns:
`Rect`: Coordinates of the bounding box. | def bounding_box(locations):
x_values = list(map(itemgetter(0), locations))
x_min, x_max = min(x_values), max(x_values)
y_values = list(map(itemgetter(1), locations))
y_min, y_max = min(y_values), max(y_values)
return Rect(x_min, y_min, x_max - x_min, y_max - y_min) | 372,418 |
Computes the convex hull of an iterable of (x, y) coordinates.
Args:
points: iterable of (x, y) tuples.
Returns:
`list`: instances of `Point` - vertices of the convex hull in
counter-clockwise order, starting from the vertex with the
lexicographically smallest coordinates.
... | def convex_hull(points):
def is_not_clockwise(p0, p1, p2):
return 0 <= (
(p1[0] - p0[0]) * (p2[1] - p0[1]) -
(p1[1] - p0[1]) * (p2[0] - p0[0])
)
def go(points_):
res = []
for p in points_:
while 1 < len(res) and is_not_clockwise(res[-2],... | 372,419 |
Generator of symbols.
Args:
image: `zbar_image`
Yields:
POINTER(zbar_symbol): Symbol | def _symbols_for_image(image):
symbol = zbar_image_first_symbol(image)
while symbol:
yield symbol
symbol = zbar_symbol_next(symbol) | 372,420 |
Generator of decoded symbol information.
Args:
symbols: iterable of instances of `POINTER(zbar_symbol)`
Yields:
Decoded: decoded symbol | def _decode_symbols(symbols):
for symbol in symbols:
data = string_at(zbar_symbol_get_data(symbol))
# The 'type' int in a value in the ZBarSymbol enumeration
symbol_type = ZBarSymbol(symbol.contents.type).name
polygon = convex_hull(
(
zbar_symbol_get_... | 372,421 |
Decodes datamatrix barcodes in `image`.
Args:
image: `numpy.ndarray`, `PIL.Image` or tuple (pixels, width, height)
symbols: iter(ZBarSymbol) the symbol types to decode; if `None`, uses
`zbar`'s default behaviour, which is to decode all symbol types.
Returns:
:obj:`list` of ... | def decode(image, symbols=None):
pixels, width, height = _pixel_data(image)
results = []
with _image_scanner() as scanner:
if symbols:
# Disable all but the symbols of interest
disable = set(ZBarSymbol).difference(symbols)
for symbol in disable:
... | 372,423 |
Estimate an approximation of the ratio of stationary over empirical distribution from the basis.
Parameters:
-----------
K0, ndarray(M+1, M+1),
time-lagged correlation matrix for the whitened and padded data set.
Returns:
--------
u : ndarray(M,)
coefficients of the ratio station... | def _compute_u(K):
M = K.shape[0] - 1
# Compute right and left eigenvectors:
l, U = scl.eig(K.T)
l, U = sort_by_norm(l, U)
# Extract the eigenvector for eigenvalue one and normalize:
u = np.real(U[:, 0])
v = np.zeros(M+1)
v[M] = 1.0
u = u / np.dot(u, v)
return u | 372,587 |
Return covariance matrix:
Parameters:
-----------
bessel : bool, optional, default=True
Use Bessel's correction in order to
obtain an unbiased estimator of sample covariances. | def covar(self, bessel=True):
if bessel:
return self.Mxy/ (self.w-1)
else:
return self.Mxy / self.w | 372,735 |
start a drag operation with a PandasCellPayload on defined index.
Args:
index (QModelIndex): model index you want to start the drag operation. | def startDrag(self, index):
if not index.isValid():
return
dataFrame = self.model().dataFrame()
# get all infos from dataFrame
dfindex = dataFrame.iloc[[index.row()]].index
columnName = dataFrame.columns[index.column()]
dtype = dataFrame[co... | 373,440 |
Constructs the object with the given parent.
Args:
parent (QObject, optional): Causes the objected to be owned
by `parent` instead of Qt. Defaults to `None`.
iconSize (QSize, optional): Size of edit buttons. Defaults to QSize(36, 36). | def __init__(self, parent=None, iconSize=QtCore.QSize(36, 36)):
super(DataTableWidget, self).__init__(parent)
self._iconSize = iconSize
self.initUi() | 373,442 |
Enable the editing buttons to add/remove rows/columns and to edit the data.
This method is also a slot.
In addition, the data of model will be made editable,
if the `enabled` parameter is true.
Args:
enabled (bool): This flag indicates, if the buttons
shall ... | def enableEditing(self, enabled):
for button in self.buttons[1:]:
button.setEnabled(enabled)
if button.isChecked():
button.setChecked(False)
model = self.tableView.model()
if model is not None:
model.enableEditing(enabled) | 373,444 |
Adds a column with the given parameters to the underlying model
This method is also a slot.
If no model is set, nothing happens.
Args:
columnName (str): The name of the new column.
dtype (numpy.dtype): The datatype of the new column.
defaultValue (object): F... | def addColumn(self, columnName, dtype, defaultValue):
model = self.tableView.model()
if model is not None:
model.addDataFrameColumn(columnName, dtype, defaultValue)
self.addColumnButton.setChecked(False) | 373,446 |
Display the dialog to add a column to the model.
This method is also a slot.
Args:
triggered (bool): If the corresponding button was
activated, the dialog will be created and shown. | def showAddColumnDialog(self, triggered):
if triggered:
dialog = AddAttributesDialog(self)
dialog.accepted.connect(self.addColumn)
dialog.rejected.connect(self.uncheckButton)
dialog.show() | 373,447 |
Adds a row to the model.
This method is also a slot.
Args:
triggered (bool): If the corresponding button was
activated, the row will be appended to the end. | def addRow(self, triggered):
if triggered:
model = self.tableView.model()
model.addDataFrameRows()
self.sender().setChecked(False) | 373,448 |
Removes a row to the model.
This method is also a slot.
Args:
triggered (bool): If the corresponding button was
activated, the selected row will be removed
from the model. | def removeRow(self, triggered):
if triggered:
model = self.tableView.model()
selection = self.tableView.selectedIndexes()
rows = [index.row() for index in selection]
model.removeDataFrameRows(set(rows))
self.sender().setChecked(False) | 373,449 |
Removes one or multiple columns from the model.
This method is also a slot.
Args:
columnNames (list): A list of columns, which shall
be removed from the model. | def removeColumns(self, columnNames):
model = self.tableView.model()
if model is not None:
model.removeDataFrameColumns(columnNames)
self.removeColumnButton.setChecked(False) | 373,450 |
Display the dialog to remove column(s) from the model.
This method is also a slot.
Args:
triggered (bool): If the corresponding button was
activated, the dialog will be created and shown. | def showRemoveColumnDialog(self, triggered):
if triggered:
model = self.tableView.model()
if model is not None:
columns = model.dataFrameColumns()
dialog = RemoveAttributesDialog(columns, self)
dialog.accepted.connect(self.removeCo... | 373,451 |
Sets the model for the enclosed TableView in this widget.
Args:
model (DataFrameModel): The model to be displayed by
the Table View. | def setViewModel(self, model):
if isinstance(model, DataFrameModel):
self.enableEditing(False)
self.uncheckButton()
selectionModel = self.tableView.selectionModel()
self.tableView.setModel(model)
model.dtypeChanged.connect(self.up... | 373,452 |
Create a new thread for given worker.
Args:
parent (QObject): parent of thread and worker.
worker (ProgressWorker): worker to use in thread.
deleteWorkerLater (bool, optional): delete the worker if thread finishes.
Returns:
QThread | def createThread(parent, worker, deleteWorkerLater=False):
thread = QtCore.QThread(parent)
thread.started.connect(worker.doWork)
worker.finished.connect(thread.quit)
if deleteWorkerLater:
thread.finished.connect(worker.deleteLater)
worker.moveToThread(thread)
worker.setParent(paren... | 373,454 |
Worker object that will be passed to the thread.
Args:
name (str): name shown in progress ui. | def __init__(self, name):
super(ProgressWorker, self).__init__()
self.name = name | 373,455 |
Constructs the object with the given parent.
Args:
parent (QtCore.QObject, optional): Causes the objected to be owned
by `parent` instead of Qt. Defaults to `None`. | def __init__(self, parent=None):
super(SupportedDtypesTranslator, self).__init__(parent)
# we are not supposed to use str objects (str/ dtype('S'))
self._strs = [(np.dtype(object), self.tr('text'))]
self._ints = [(np.dtype(np.int8), self.tr('small integer (8 bit)')),
... | 373,456 |
Gets the datatype for the given `value` (description).
Args:
value (str): A text description for any datatype.
Returns:
numpy.dtype: The matching datatype for the given text.
None: If no match can be found, `None` will be returned. | def dtype(self, value):
for (dtype, string) in self._all:
if string == value:
return dtype
return None | 373,458 |
Fill all NaN/NaT values of a column with an empty string
Args:
column (pandas.Series): A Series object with all rows.
Returns:
column: Series with filled NaN values. | def fillNoneValues(column):
if column.dtype == object:
column.fillna('', inplace=True)
return column | 373,461 |
Convert a dtype of a given column to a datetime.
This method tries to do this by brute force.
Args:
column (pandas.Series): A Series object with all rows.
Returns:
column: Converted to datetime if no errors occured, else the
original column will be returned. | def convertTimestamps(column):
tempColumn = column
try:
# Try to convert the first row and a random row instead of the complete
# column, might be faster
# tempValue = np.datetime64(column[0])
tempValue = np.datetime64(column[randint(0, len(column.index) - 1)])
temp... | 373,462 |
construct a new instance of a BigIntSpinboxDelegate.
Args:
maximum (int or long, optional): minimum allowed number in BigIntSpinbox. defaults to -18446744073709551616.
minimum (int or long, optional): maximum allowed number in BigIntSpinbox. defaults to 18446744073709551615.
... | def __init__(self, minimum=-18446744073709551616, maximum=18446744073709551615, singleStep=1, parent=None):
super(BigIntSpinboxDelegate, self).__init__(parent)
self.minimum = minimum
self.maximum = maximum
self.singleStep = singleStep | 373,471 |
Returns the widget used to edit the item specified by index for editing. The parent widget and style option are used to control how the editor widget appears.
Args:
parent (QWidget): parent widget.
option (QStyleOptionViewItem): controls how editor widget appears.
index (QMo... | def createEditor(self, parent, option, index):
editor = BigIntSpinbox(parent)
try:
editor.setMinimum(self.minimum)
editor.setMaximum(self.maximum)
editor.setSingleStep(self.singleStep)
except TypeError as err:
# initiate the editor with de... | 373,472 |
Sets the data to be displayed and edited by the editor from the data model item specified by the model index.
Args:
spinBox (BigIntSpinbox): editor widget.
index (QModelIndex): model data index. | def setEditorData(self, spinBox, index):
if index.isValid():
value = index.model().data(index, QtCore.Qt.EditRole)
spinBox.setValue(value) | 373,473 |
construct a new instance of a CustomDoubleSpinboxDelegate.
Args:
maximum (float): minimum allowed number in QDoubleSpinBox.
minimum (float): maximum allowed number in QDoubleSpinBox.
singleStep (int, optional): amount of steps to stepUp QDoubleSpinBox. defaults to 0.1.
... | def __init__(self, minimum, maximum, decimals=2, singleStep=0.1, parent=None):
super(CustomDoubleSpinboxDelegate, self).__init__(parent)
self.minimum = minimum
self.maximum = maximum
self.decimals = decimals
self.singleStep = singleStep | 373,474 |
Returns the widget used to edit the item specified by index for editing. The parent widget and style option are used to control how the editor widget appears.
Args:
parent (QWidget): parent widget.
option (QStyleOptionViewItem): controls how editor widget appears.
index (QMo... | def createEditor(self, parent, option, index):
editor = QtGui.QDoubleSpinBox(parent)
try:
editor.setMinimum(self.minimum)
editor.setMaximum(self.maximum)
editor.setSingleStep(self.singleStep)
editor.setDecimals(self.decimals)
except TypeEr... | 373,475 |
Gets data from the editor widget and stores it in the specified model at the item index.
Args:
spinBox (QDoubleSpinBox): editor widget.
model (QAbstractItemModel): parent model.
index (QModelIndex): model data index. | def setModelData(self, spinBox, model, index):
spinBox.interpretText()
value = spinBox.value()
model.setData(index, value, QtCore.Qt.EditRole) | 373,476 |
Returns the widget used to edit the item specified by index for editing. The parent widget and style option are used to control how the editor widget appears.
Args:
parent (QWidget): parent widget.
option (QStyleOptionViewItem): controls how editor widget appears.
index (QMo... | def createEditor(self, parent, option, index):
editor = QtGui.QLineEdit(parent)
return editor | 373,477 |
Gets data from the editor widget and stores it in the specified model at the item index.
Args:
editor (QtGui.QLineEdit): editor widget.
model (QAbstractItemModel): parent model.
index (QModelIndex): model data index. | def setModelData(self, editor, model, index):
if index.isValid():
value = editor.text()
model.setData(index, value, QtCore.Qt.EditRole) | 373,478 |
Updates the model after changing data in the editor.
Args:
editor (QtGui.QComboBox): The current editor for the item. Should be
a `QtGui.QComboBox` as defined in `createEditor`.
model (ColumnDtypeModel): The model which holds the displayed data.
index (QtCore... | def setModelData(self, editor, model, index):
model.setData(index, editor.itemText(editor.currentIndex())) | 373,481 |
create a new MimeData object.
Args:
mimeType (str): the mime type. | def __init__(self, mimeType=PandasCellMimeType):
super(MimeData, self).__init__()
self._mimeType = mimeType | 373,482 |
Add some data.
Args:
data (object): Object to add as data. This object has to be pickable.
Qt objects don't work!
Raises:
TypeError if data is not pickable | def setData(self, data):
try:
bytestream = pickle.dumps(data)
super(MimeData, self).setData(self._mimeType, bytestream)
except TypeError:
raise TypeError(self.tr("can not pickle added data"))
except:
raise | 373,483 |
store dataframe information in a pickable object
Args:
dfindex (pandas.index): index of the dragged data.
column (str): name of column to be dragged.
value (object): value on according position.
dtype (pandas dtype): data type of column.
paren... | def __init__(self, dfindex, column, value, dtype, parentId):
super(PandasCellPayload, self).__init__()
self.dfindex = dfindex
self.column = column
self.value = value
self.dtype = dtype
self.parentId = parentId | 373,485 |
the __init__ method.
Args:
parent (QObject): defaults to None. If parent is 0, the new widget becomes a window.
If parent is another widget, this widget becomes a child window inside parent.
The new widget is deleted when its parent is deleted. | def __init__(self, parent=None):
super(BigIntSpinbox, self).__init__(parent)
self._singleStep = 1
self._minimum = -18446744073709551616
self._maximum = 18446744073709551615
rx = QtCore.QRegExp("[0-9]\\d{0,20}")
validator = QtGui.QRegExpValidator(rx, self)
... | 373,498 |
setter function to _lineEdit.text. Sets minimum/maximum as new value if value is out of bounds.
Args:
value (int/long): new value to set.
Returns
True if all went fine. | def setValue(self, value):
if value >= self.minimum() and value <= self.maximum():
self._lineEdit.setText(str(value))
elif value < self.minimum():
self._lineEdit.setText(str(self.minimum()))
elif value > self.maximum():
self._lineEdit.setText(str(self... | 373,499 |
steps value up/down by a single step. Single step is defined in singleStep().
Args:
steps (int): positiv int steps up, negativ steps down | def stepBy(self, steps):
self.setValue(self.value() + steps*self.singleStep()) | 373,500 |
setter to _singleStep. converts negativ values to positiv ones.
Args:
singleStep (int): new _singleStep value. converts negativ values to positiv ones.
Raises:
TypeError: If the given argument is not an integer.
Returns:
int or long: the absolute value of t... | def setSingleStep(self, singleStep):
if not isinstance(singleStep, int):
raise TypeError("Argument is not of type int")
# don't use negative values
self._singleStep = abs(singleStep)
return self._singleStep | 373,502 |
setter to _minimum.
Args:
minimum (int or long): new _minimum value.
Raises:
TypeError: If the given argument is not an integer. | def setMinimum(self, minimum):
if not isinstance(minimum, int):
raise TypeError("Argument is not of type int or long")
self._minimum = minimum | 373,503 |
setter to _maximum.
Args:
maximum (int or long): new _maximum value | def setMaximum(self, maximum):
if not isinstance(maximum, int):
raise TypeError("Argument is not of type int or long")
self._maximum = maximum | 373,504 |
the __init__ method.
Args:
dataFrame (pandas.core.frame.DataFrame, optional): initializes the model with given DataFrame.
If none is given an empty DataFrame will be set. defaults to None.
editable (bool, optional): apply changes while changing dtype. defaults to True. | def __init__(self, dataFrame=None, editable=False):
super(ColumnDtypeModel, self).__init__()
self.headers = ['column', 'data type']
self._editable = editable
self._dataFrame = pandas.DataFrame()
if dataFrame is not None:
self.setDataFrame(dataFrame) | 373,518 |
setter function to _dataFrame. Holds all data.
Note:
It's not implemented with python properties to keep Qt conventions.
Raises:
TypeError: if dataFrame is not of type pandas.core.frame.DataFrame.
Args:
dataFrame (pandas.core.frame.DataFrame): assign dataFr... | def setDataFrame(self, dataFrame):
if not isinstance(dataFrame, pandas.core.frame.DataFrame):
raise TypeError('Argument is not of type pandas.core.frame.DataFrame')
self.layoutAboutToBeChanged.emit()
self._dataFrame = dataFrame
self.layoutChanged.emit() | 373,519 |
setter to _editable. apply changes while changing dtype.
Raises:
TypeError: if editable is not of type bool.
Args:
editable (bool): apply changes while changing dtype. | def setEditable(self, editable):
if not isinstance(editable, bool):
raise TypeError('Argument is not of type bool')
self._editable = editable | 373,520 |
Returns the item flags for the given index as ored value, e.x.: Qt.ItemIsUserCheckable | Qt.ItemIsEditable
Args:
index (QtCore.QModelIndex): Index to define column and row
Returns:
for column 'column': Qt.ItemIsSelectable | Qt.ItemIsEnabled
for column 'data type': Q... | def flags(self, index):
if not index.isValid():
return Qt.NoItemFlags
col = index.column()
flags = Qt.ItemIsEnabled | Qt.ItemIsSelectable
if col > 0 and self.editable():
flags = Qt.ItemIsSelectable | Qt.ItemIsEnabled | Qt.ItemIsEditable
return... | 373,523 |
Constructs a `DataSearch` object from the given attributes.
Args:
name (str): The name of the filter.
filterString (str, optional): A python expression as string.
Defaults to an empty string.
dataFrame (pandas.DataFrame, optional): The object to filter.
... | def __init__(self, name, filterString='', dataFrame=pd.DataFrame()):
self._filterString = filterString
self._dataFrame = dataFrame
self.name = name | 373,524 |
Filters the data by a list of indexes.
Args:
indexes (list of int): List of index numbers to return.
Returns:
list: A list containing all indexes with filtered data. Matches
will be `True`, the remaining items will be `False`. If the
dataFrame is empty, ... | def indexSearch(self, indexes):
if not self._dataFrame.empty:
filter0 = self._dataFrame.index == -9999
for index in indexes:
filter1 = self._dataFrame.index == index
filter0 = np.logical_or(filter0, filter1)
return filter0
el... | 373,529 |
Setter to _timestampFormat. Formatting string for conversion of timestamps to QtCore.QDateTime
Raises:
AssertionError: if timestampFormat is not of type unicode.
Args:
timestampFormat (unicode): assign timestampFormat to _timestampFormat.
Formatting string for c... | def timestampFormat(self, timestampFormat):
if not isinstance(timestampFormat, str):
raise TypeError('not of type unicode')
#assert isinstance(timestampFormat, unicode) or timestampFormat.__class__.__name__ == "DateFormat", "not of type unicode"
self._timestampFormat = times... | 373,535 |
Apply a filter and hide rows.
The filter must be a `DataSearch` object, which evaluates a python
expression.
If there was an error while parsing the expression, the data will remain
unfiltered.
Args:
search(qtpandas.DataSearch): data search object to use.
R... | def setFilter(self, search):
if not isinstance(search, DataSearch):
raise TypeError('The given parameter must an `qtpandas.DataSearch` object')
self._search = search
self.layoutAboutToBeChanged.emit()
if self._dataFrameOriginal is not None:
self._dataF... | 373,543 |
Gets the first key of all available encodings where the corresponding
value matches the comparator.
Args:
comparator (string): A view name for an encoding.
Returns:
str: A key for a specific encoding used by python. | def _calculateEncodingKey(comparator):
encodingName = None
for k, v in list(_encodings.items()):
if v == comparator:
encodingName = k
break
return encodingName | 373,583 |
Constructs the object with the given parent.
Args:
parent (QObject, optional): Causes the objected to be owned
by `parent` instead of Qt. Defaults to `None`. | def __init__(self, parent=None):
super(DelimiterValidator, self).__init__(parent)
re = QtCore.QRegExp('\S{1}')
self.setRegExp(re) | 373,584 |
Constructs the object with the given parent.
Args:
parent (QObject, optional): Causes the objected to be owned
by `parent` instead of Qt. Defaults to `None`. | def __init__(self, parent=None):
super(DelimiterSelectionWidget, self).__init__(parent)
self.semicolonRadioButton = None
self.commaRadioButton = None
self.tabRadioButton = None
self.otherRadioButton = None
self.otherSeparatorLineEdit = None
self._initUI() | 373,585 |
Constructs the object with the given parent.
Args:
parent (QObject, optional): Causes the objected to be owned
by `parent` instead of Qt. Defaults to `None`. | def __init__(self, parent=None):
super(CSVImportDialog, self).__init__(parent)
self._modal = True
self._windowTitle = 'Import CSV'
self._encodingKey = None
self._filename = None
self._delimiter = None
self._header = None
# self._detector = Detecto... | 373,589 |
Opens a file from the given `path` and checks the file encoding.
The file must exists on the file system and end with the extension
`.csv`. The file is read line by line until the encoding could be
guessed.
On a successfull identification, the widgets of this dialog will be
upda... | def _guessEncoding(self, path):
if os.path.exists(path) and path.lower().endswith('csv'):
# encoding = self._detector.detect(path)
encoding = None
if encoding is not None:
if encoding.startswith('utf'):
encoding = encoding.replace... | 373,593 |
Changes the value of the encoding combo box to the value of given index.
This method is also a `SLOT`.
After the encoding is changed, the file will be reloaded and previewed.
Args:
index (int): An valid index of the combo box. | def _updateEncoding(self, index):
encoding = self._encodingComboBox.itemText(index)
encoding = encoding.lower()
self._encodingKey = _calculateEncodingKey(encoding)
self._previewFile() | 373,594 |
Message constructor with ([buf], [field=val,...]) prototype.
Arguments:
buf -- option message buffer to decode
Optional keyword arguments corresponts to members to set (matching
fields in self.__fields__, or 'data'). | def __init__(self, *args, **kwargs):
# create message fields
if hasattr(self, '__fields__'):
self._create_fields()
# set default lun
self.lun = self.__default_lun__
self.data = ''
if args:
self._decode(args[0])
else:
... | 374,168 |
Create an empty table with column labels.
>>> tiles = Table(make_array('letter', 'count', 'points'))
>>> tiles
letter | count | points
Args:
``labels`` (list of strings): The column labels.
``formatter`` (Formatter): An instance of :class:`Formatter` that
... | def __init__(self, labels=None, _deprecated=None, *, formatter=_formats.default_formatter):
self._columns = collections.OrderedDict()
self._formats = dict()
self.formatter = formatter
if _deprecated is not None:
warnings.warn("Two-argument __init__ is deprecated. Us... | 375,530 |
Creates an empty table. Column labels are optional. [Deprecated]
Args:
``labels`` (None or list): If ``None``, a table with 0
columns is created.
If a list, each element is a column label in a table with
0 rows.
Returns:
A new ins... | def empty(cls, labels=None):
warnings.warn("Table.empty(labels) is deprecated. Use Table(labels)", FutureWarning)
if labels is None:
return cls()
values = [[] for label in labels]
return cls(values, labels) | 375,531 |
Return a table with an additional row.
Args:
``row`` (sequence): A value for each column.
Raises:
``ValueError``: If the row length differs from the column count.
>>> tiles = Table(make_array('letter', 'count', 'points'))
>>> tiles.with_row(['c', 2, 3]).with_ro... | def with_row(self, row):
self = self.copy()
self.append(row)
return self | 375,570 |
Plots a normal curve with specified parameters and area below curve shaded
between ``lbound`` and ``rbound``.
Args:
``rbound`` (numeric): right boundary of shaded region
``lbound`` (numeric): left boundary of shaded region; by default is negative infinity
``mean`` (numeric): mean/expe... | def plot_normal_cdf(rbound=None, lbound=None, mean=0, sd=1):
shade = rbound is not None or lbound is not None
shade_left = rbound is not None and lbound is not None
inf = 3.5 * sd
step = 0.1
rlabel = rbound
llabel = lbound
if rbound is None:
rbound = inf + mean
rlabel = ... | 375,597 |
Get individual ISO transfer's setup.
Returns a list of dicts, each containing an individual ISO transfer
parameters:
- length
- actual_length
- status
(see libusb1's API documentation for their signification)
Returned list is consistent with getISOBufferList retur... | def getISOSetupList(self):
transfer_p = self.__transfer
transfer = transfer_p.contents
# pylint: disable=undefined-variable
if transfer.type != TRANSFER_TYPE_ISOCHRONOUS:
# pylint: enable=undefined-variable
raise TypeError(
'This method ca... | 375,764 |
TODO: Implement trie lookup with edit distance
Args:
iterable(list?): key used to find what is requested this could
be a generator.
index(int): index of what is requested
gather(bool): of weather to gather or not
edit_distance(int): the distance -... | def lookup(self, iterable, index=0, gather=False, edit_distance=0, max_edit_distance=0, match_threshold=0.0, matched_length=0):
if self.is_terminal:
if index == len(iterable) or \
(gather and index < len(iterable) and iterable[index] == ' '): # only gather on word break... | 376,068 |
Insert new node into tree
Args:
iterable(hashable): key used to find in the future.
data(object): data associated with the key
index(int): an index used for insertion.
weight(float): the wait given for the item added. | def insert(self, iterable, index=0, data=None, weight=1.0):
if index == len(iterable):
self.is_terminal = True
self.key = iterable
self.weight = weight
if data:
self.data.add(data)
else:
if iterable[index] not in self.c... | 376,069 |
Init the Trie object and create root node.
Creates an Trie object with a root node with the passed in
max_edit_distance and match_threshold.
Args:
max_edit_distance(int): ?
match_threshold(int): ?
Notes:
This never seems to get called with max_edit_... | def __init__(self, max_edit_distance=0, match_threshold=0.0):
self.root = TrieNode('root')
self.max_edit_distance = max_edit_distance
self.match_threshold = match_threshold | 376,072 |
Used to remove from the root node
Args:
iterable(hashable): index or key used to identify
item to remove
data: data to be paired with the key | def remove(self, iterable, data=None):
return self.root.remove(iterable, data=data) | 376,076 |
This is used to fine cliques and remove them from graph
Args:
graph (graph): this is the graph of verticies to search for
cliques
p (list): this is a list of the verticies to search
r (list): used by bronk for the search
x (list): used by bronk for the search
Yields... | def bronk(r, p, x, graph):
if len(p) == 0 and len(x) == 0:
yield r
return
for vertex in p[:]:
r_new = r[::]
r_new.append(vertex)
p_new = [val for val in p if val in graph.get_neighbors_of(vertex)] # p intersects N(vertex)
x_new = [val for val in x if val in g... | 376,077 |
Returns a key from a tag entity
Args:
tag (tag) : this is the tag selected to get the key from
entity_index (int) : this is the index of the tagged entity
Returns:
str : String representing the key for the given tagged entity. | def graph_key_from_tag(tag, entity_index):
start_token = tag.get('start_token')
entity = tag.get('entities', [])[entity_index]
return str(start_token) + '-' + entity.get('key') + '-' + str(entity.get('confidence')) | 376,078 |
Used to add edges to the graph. 'a' and 'b' are vertexes and
if 'a' or 'b' doesn't exisit then the vertex is created
Args:
a (hash): is one vertex of the edge
b (hash): is another vertext of the edge | def add_edge(self, a, b):
neighbors_of_a = self.adjacency_lists.get(a)
if not neighbors_of_a:
neighbors_of_a = set()
self.adjacency_lists[a] = neighbors_of_a
neighbors_of_a.add(b)
neighbors_of_b = self.adjacency_lists.get(b)
if not neighbors_of_... | 376,079 |
Appends items or lists to the Lattice
Args:
data (item,list) : The Item or List to be added to the Lattice | def append(self, data):
if isinstance(data, list) and len(data) > 0:
self.nodes.append(data)
else:
self.nodes.append([data]) | 376,080 |
This is used to produce a list of lists where each each item
in that list is a diffrent combination of items from the lists
within with every combination of such values.
Args:
index (int) : the index at witch to start the list.
Note this is used only in the function ... | def traverse(self, index=0):
if index < len(self.nodes):
for entity in self.nodes[index]:
for next_result in self.traverse(index=index+1):
if isinstance(entity, list):
yield entity + next_result
else:
... | 376,081 |
Builds a graph from the entities included in the tags.
Note this is used internally.
Args:
tags (list): A list of the tags to include in graph
Returns:
graph : this is the resulting graph of the tagged entities. | def _build_graph(self, tags):
graph = SimpleGraph()
for tag_index in xrange(len(tags)):
for entity_index in xrange(len(tags[tag_index].get('entities'))):
a_entity_name = graph_key_from_tag(tags[tag_index], entity_index)
tokens = self.tokenizer.tokeniz... | 376,082 |
This called by expand to find cliques
Args:
tags (list): a list of the tags used to get cliques
Yields:
list : list of sorted tags by start_token this is a clique | def _sub_expand(self, tags):
entities = {}
graph = self._build_graph(tags)
# name entities
for tag in tags:
for entity_index in xrange(len(tag.get('entities'))):
node_name = graph_key_from_tag(tag, entity_index)
if not node_name in en... | 376,083 |
This is the main function to expand tags into cliques
Args:
tags (list): a list of tags to find the cliques.
clique_scoring_func (func): a function that returns a float
value for the clique
Returns:
list : a list of cliques | def expand(self, tags, clique_scoring_func=None):
lattice = Lattice()
overlapping_spans = []
def end_token_index():
return max([t.get('end_token') for t in overlapping_spans])
for i in xrange(len(tags)):
tag = tags[i]
if len(overlapping_spa... | 376,084 |
Using regex invokes this function, which significantly impacts performance of adapt. it is an N! operation.
Args:
tokens(list): list of tokens for Yield results.
Yields:
str: ? | def _iterate_subsequences(self, tokens):
for start_idx in xrange(len(tokens)):
for end_idx in xrange(start_idx + 1, len(tokens) + 1):
yield ' '.join(tokens[start_idx:end_idx]), start_idx | 376,086 |
Initialize the IntentDeterminationEngine
Args:
tokenizer(tokenizer) : tokenizer used to break up spoken text
example EnglishTokenizer()
trie(Trie): tree of matches to Entites | def __init__(self, tokenizer=None, trie=None):
pyee.EventEmitter.__init__(self)
self.tokenizer = tokenizer or EnglishTokenizer()
self.trie = trie or Trie()
self.regular_expressions_entities = []
self._regex_strings = set()
self.tagger = EntityTagger(self.trie, se... | 376,089 |
Decide the best intent
Args:
parse_result(list): results used to match the best intent.
context(list): ?
Returns:
best_intent, best_tags:
best_intent : The best intent for given results
best_tags : The Tags for result | def __best_intent(self, parse_result, context=[]):
best_intent = None
best_tags = None
context_as_entities = [{'entities': [c]} for c in context]
for intent in self.intent_parsers:
i, tags = intent.validate_with_tags(parse_result.get('tags') + context_as_entities, pa... | 376,090 |
Used to get unused context from context. Any keys not in
parse_result
Args:
parse_results(list): parsed results used to identify what keys
in the context are used.
context(list): this is the context used to match with parsed results
keys missing ... | def __get_unused_context(self, parse_result, context):
tags_keys = set([t['key'] for t in parse_result['tags'] if t['from_context']])
result_context = [c for c in context if c['key'] not in tags_keys]
return result_context | 376,091 |
Given an utterance, provide a valid intent.
Args:
utterance(str): an ascii or unicode string representing natural language speech
include_tags(list): includes the parsed tags (including position and confidence)
as part of result
context_manager(list): a conte... | def determine_intent(self, utterance, num_results=1, include_tags=False, context_manager=None):
parser = Parser(self.tokenizer, self.tagger)
parser.on('tagged_entities',
(lambda result:
self.emit("tagged_entities", result)))
context = []
if ... | 376,092 |
Register an entity to be tagged in potential parse results
Args:
entity_value(str): the value/proper name of an entity instance (Ex: "The Big Bang Theory")
entity_type(str): the type/tag of an entity instance (Ex: "Television Show") | def register_entity(self, entity_value, entity_type, alias_of=None):
if alias_of:
self.trie.insert(entity_value.lower(), data=(alias_of, entity_type))
else:
self.trie.insert(entity_value.lower(), data=(entity_value, entity_type))
self.trie.insert(entity_type.... | 376,093 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.