_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 31 13.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q250600 | Objective.clone | train | def clone(cls, objective, model=None, **kwargs):
"""
Make a copy of an objective. The objective being copied can be of the same type or belong to
a different solver interface.
Example
----------
>>> new_objective = Objective.clone(old_objective)
| python | {
"resource": ""
} |
q250601 | Objective.to_json | train | def to_json(self):
"""
Returns a json-compatible object from the objective that can be saved using the json module.
Example
--------
>>> import json
>>> with open("path_to_file.json", "w") as outfile:
>>> json.dump(obj.to_json(), outfile)
"""
| python | {
"resource": ""
} |
q250602 | Objective.from_json | train | def from_json(cls, json_obj, variables=None):
"""
Constructs an Objective from the provided json-object.
Example
--------
>>> import json
>>> with open("path_to_file.json") as infile:
| python | {
"resource": ""
} |
q250603 | Model.clone | train | def clone(cls, model, use_json=True, use_lp=False):
"""
Make a copy of a model. The model being copied can be of the same type or belong to
a different solver interface. This is the preferred way of copying models.
Example
----------
>>> new_model = Model.clone(old_model... | python | {
"resource": ""
} |
q250604 | Model.add | train | def add(self, stuff, sloppy=False):
"""Add variables and constraints.
Parameters
----------
stuff : iterable, Variable, Constraint
Either an iterable containing variables and constraints or a single variable or constraint.
sloppy : bool
Check constraints... | python | {
"resource": ""
} |
q250605 | Model.remove | train | def remove(self, stuff):
"""Remove variables and constraints.
Parameters
----------
stuff : iterable, str, Variable, Constraint
Either an iterable containing variables and constraints to be removed from the model or a single variable or contstraint (or their names).
... | python | {
"resource": ""
} |
q250606 | Model.update | train | def update(self, callback=int):
"""Process all pending model modifications."""
# print(self._pending_modifications)
add_var = self._pending_modifications.add_var
if len(add_var) > 0:
self._add_variables(add_var)
self._pending_modifications.add_var = []
cal... | python | {
"resource": ""
} |
q250607 | Model.optimize | train | def optimize(self):
"""
Solve the optimization problem using the relevant solver back-end.
The status returned by this method tells whether an optimal solution was found,
if the problem is infeasible etc. Consult optlang.statuses for more elaborate explanations
of each status.
... | python | {
"resource": ""
} |
q250608 | Model.to_json | train | def to_json(self):
"""
Returns a json-compatible object from the model that can be saved using the json module.
Variables, constraints and objective contained in the model will be saved. Configurations
will not be saved.
Example
--------
>>> import json
>... | python | {
"resource": ""
} |
q250609 | solve_with_glpsol | train | def solve_with_glpsol(glp_prob):
"""Solve glpk problem with glpsol commandline solver. Mainly for testing purposes.
# Examples
# --------
# >>> problem = glp_create_prob()
# ... glp_read_lp(problem, None, "../tests/data/model.lp")
# ... solution = solve_with_glpsol(problem)
# ... print 'as... | python | {
"resource": ""
} |
q250610 | glpk_read_cplex | train | def glpk_read_cplex(path):
"""Reads cplex file and returns glpk problem.
Returns
-------
glp_prob
A glpk problems (same type as returned by glp_create_prob)
"""
from swiglpk import | python | {
"resource": ""
} |
q250611 | expr_to_json | train | def expr_to_json(expr):
"""
Converts a Sympy expression to a json-compatible tree-structure.
"""
if isinstance(expr, symbolics.Mul):
return {"type": "Mul", "args": [expr_to_json(arg) for arg in expr.args]}
elif isinstance(expr, symbolics.Add):
return {"type": "Add", "args": [expr_to_... | python | {
"resource": ""
} |
q250612 | parse_expr | train | def parse_expr(expr, local_dict=None):
"""
Parses a json-object created with 'expr_to_json' into a Sympy expression.
If a local_dict argument is passed, symbols with be looked up by name, and a new symbol will
be created only if the name is not in local_dict.
"""
if local_dict is None:
... | python | {
"resource": ""
} |
q250613 | Problem.set_variable_bounds | train | def set_variable_bounds(self, name, lower, upper):
"""Set the bounds of a variable"""
| python | {
"resource": ""
} |
q250614 | Problem.add_constraint | train | def add_constraint(self, name, coefficients={}, ub=0):
"""
Add a constraint to the problem. The constrain is formulated as a dictionary of variable names to
linear coefficients.
The constraint can only have an upper bound. To make a constraint with a lower bound, multiply
all coe... | python | {
"resource": ""
} |
q250615 | Problem.remove_variable | train | def remove_variable(self, name):
"""Remove a variable from the problem."""
index = self._get_var_index(name)
# Remove from matrix
self._A = np.delete(self.A, index, 1)
# Remove from bounds
del self.bounds[name]
| python | {
"resource": ""
} |
q250616 | Problem.remove_constraint | train | def remove_constraint(self, name):
"""Remove a constraint from the problem"""
index = self._get_constraint_index(name)
# Remove from matrix
self._A = np.delete(self.A, index, 0) | python | {
"resource": ""
} |
q250617 | Problem.set_constraint_bound | train | def set_constraint_bound(self, name, value):
"""Set the upper bound of a constraint."""
index = self._get_constraint_index(name)
| python | {
"resource": ""
} |
q250618 | Problem.get_var_primal | train | def get_var_primal(self, name):
"""Get the primal value of a variable. Returns None if the problem has not bee optimized."""
| python | {
"resource": ""
} |
q250619 | Problem.get_constraint_slack | train | def get_constraint_slack(self, name):
"""Get the value of the slack variable of a constraint."""
if self._slacks is None:
return None
else:
| python | {
"resource": ""
} |
q250620 | Problem.optimize | train | def optimize(self, method="simplex", verbosity=False, tolerance=1e-9, **kwargs):
"""Run the linprog function on the problem. Returns None."""
c = np.array([self.objective.get(name, 0) for name in self._variables])
if self.direction == "max":
c *= -1
bounds = list(six.iterval... | python | {
"resource": ""
} |
q250621 | Problem.objective_value | train | def objective_value(self):
"""Returns the optimal objective value"""
if self._f is None:
raise RuntimeError("Problem has not been optimized yet")
if self.direction == "max": | python | {
"resource": ""
} |
q250622 | install | train | def install(application, io_loop=None, **kwargs):
"""Call this to install AMQP for the Tornado application. Additional
keyword arguments are passed through to the constructor of the AMQP
object.
:param tornado.web.Application application: The tornado application
:param tornado.ioloop.IOLoop io_loop... | python | {
"resource": ""
} |
q250623 | PublishingMixin.amqp_publish | train | def amqp_publish(self, exchange, routing_key, body, properties=None):
"""Publish a message to RabbitMQ
:param str exchange: The exchange to publish the message to
:param str routing_key: The routing key to publish the message with
:param bytes body: The message body to send
:par... | python | {
"resource": ""
} |
q250624 | Client.publish | train | def publish(self, exchange, routing_key, body, properties=None):
"""Publish a message to RabbitMQ. If the RabbitMQ connection is not
established or is blocked, attempt to wait until sending is possible.
:param str exchange: The exchange to publish the message to.
:param str routing_key:... | python | {
"resource": ""
} |
q250625 | Client.on_delivery_confirmation | train | def on_delivery_confirmation(self, method_frame):
"""Invoked by pika when RabbitMQ responds to a Basic.Publish RPC
command, passing in either a Basic.Ack or Basic.Nack frame with
the delivery tag of the message that was published. The delivery tag
is an integer counter indicating the mes... | python | {
"resource": ""
} |
q250626 | Client.close | train | def close(self):
"""Cleanly shutdown the connection to RabbitMQ
:raises: sprockets.mixins.amqp.ConnectionStateError
"""
if not self.closable:
LOGGER.warning('Closed called while %s', self.state_description)
| python | {
"resource": ""
} |
q250627 | Client._reconnect | train | def _reconnect(self):
"""Schedule the next connection attempt if the class is not currently
closing.
"""
if self.idle or self.closed:
LOGGER.debug('Attempting RabbitMQ reconnect in %s seconds',
self.reconnect_delay)
| python | {
"resource": ""
} |
q250628 | Client.on_connection_open | train | def on_connection_open(self, connection):
"""This method is called by pika once the connection to RabbitMQ has
been established.
:type connection: pika.TornadoConnection
"""
LOGGER.debug('Connection opened')
| python | {
"resource": ""
} |
q250629 | Client.on_connection_open_error | train | def on_connection_open_error(self, connection, error):
"""Invoked if the connection to RabbitMQ can not be made.
:type connection: pika.TornadoConnection
:param Exception error: The exception indicating failure
"""
LOGGER.critical('Could not connect | python | {
"resource": ""
} |
q250630 | Client.on_connection_blocked | train | def on_connection_blocked(self, method_frame):
"""This method is called by pika if RabbitMQ sends a connection blocked
method, to let us know we need to throttle our publishing.
| python | {
"resource": ""
} |
q250631 | Client.on_connection_closed | train | def on_connection_closed(self, connection, reply_code, reply_text):
"""This method is invoked by pika when the connection to RabbitMQ is
closed unexpectedly. Since it is unexpected, we will reconnect to
RabbitMQ if it disconnects.
:param pika.TornadoConnection connection: Closed connect... | python | {
"resource": ""
} |
q250632 | Client.on_basic_return | train | def on_basic_return(self, _channel, method, properties, body):
"""Invoke a registered callback or log the returned message.
:param _channel: The channel the message was sent on
:type _channel: pika.channel.Channel
:param pika.spec.Basic.Return method: The method object
:param pi... | python | {
"resource": ""
} |
q250633 | Client.on_channel_closed | train | def on_channel_closed(self, channel, reply_code, reply_text):
"""Invoked by pika when RabbitMQ unexpectedly closes the channel.
Channels are usually closed if you attempt to do something that
violates the protocol, such as re-declare an exchange or queue with
different parameters.
... | python | {
"resource": ""
} |
q250634 | object_to_json | train | def object_to_json(obj):
"""Convert object that cannot be natively serialized by python to JSON | python | {
"resource": ""
} |
q250635 | Mail.from_response | train | def from_response(cls, response_data):
"""
Factory method to create a Mail instance from a Guerrillamail response
dict.
"""
identity = lambda x: x
return Mail(**_transform_dict(response_data, {
'guid': ('mail_id', identity),
'subject': ('mail_subje... | python | {
"resource": ""
} |
q250636 | grad_f | train | def grad_f(xy):
"""Gradient of f"""
| python | {
"resource": ""
} |
q250637 | prox_circle | train | def prox_circle(xy, step):
"""Projection onto circle"""
center = np.array([0,0])
dxy = xy - center
radius = 0.5
# exclude interior of circle
#if (dxy**2).sum() < radius**2:
# exclude everything other than perimeter of circle
if 1:
phi = | python | {
"resource": ""
} |
q250638 | prox_xline | train | def prox_xline(x, step):
"""Projection onto line in x"""
if not np.isscalar(x):
x= x[0]
if x > 0.5: | python | {
"resource": ""
} |
q250639 | prox_yline | train | def prox_yline(y, step):
"""Projection onto line in y"""
if not np.isscalar(y):
y= y[0]
if y > -0.75: | python | {
"resource": ""
} |
q250640 | prox_line | train | def prox_line(xy, step):
"""2D projection onto 2 lines"""
| python | {
"resource": ""
} |
q250641 | prox_lim | train | def prox_lim(xy, step, boundary=None):
"""Proximal projection operator"""
if boundary == "circle":
return prox_circle(xy, step)
if boundary == | python | {
"resource": ""
} |
q250642 | prox_gradf12 | train | def prox_gradf12(x, step, j=None, Xs=None):
"""1D gradient operator for x or y"""
if j == 0:
return x - step*grad_fx(Xs[0][0], Xs[1][0])
if j == 1:
| python | {
"resource": ""
} |
q250643 | prox_gradf_lim12 | train | def prox_gradf_lim12(x, step, j=None, Xs=None, boundary=None):
"""1D projection operator"""
# TODO: split boundary in x1 and x2 and use appropriate operator
if j == 0:
x -= step*grad_fx(Xs[0][0], Xs[1][0])
if j == 1:
| python | {
"resource": ""
} |
q250644 | pgm | train | def pgm(X, prox_f, step_f, accelerated=False, relax=None, e_rel=1e-6, max_iter=1000, traceback=None):
"""Proximal Gradient Method
Adapted from Combettes 2009, Algorithm 3.4.
The accelerated version is Algorithm 3.6 with modifications
from Xu & Yin (2015).
Args:
X: initial X, will be update... | python | {
"resource": ""
} |
q250645 | admm | train | def admm(X, prox_f, step_f, prox_g=None, step_g=None, L=None, e_rel=1e-6, e_abs=0, max_iter=1000, traceback=None):
"""Alternating Direction Method of Multipliers
This method implements the linearized ADMM from Parikh & Boyd (2014).
Args:
X: initial X will be updated
prox_f: proxed function... | python | {
"resource": ""
} |
q250646 | bpgm | train | def bpgm(X, proxs_f, steps_f_cb, update_order=None, accelerated=False, relax=None, max_iter=1000, e_rel=1e-6, traceback=None):
"""Block Proximal Gradient Method.
Also know as Alternating Proximal Gradient Method, it performs Proximal
gradient (forward-backward) updates on each block in alternating fashion.... | python | {
"resource": ""
} |
q250647 | get_step_f | train | def get_step_f(step_f, lR2, lS2):
"""Update the stepsize of given the primal and dual errors.
See Boyd (2011), section | python | {
"resource": ""
} |
q250648 | update_variables | train | def update_variables(X, Z, U, prox_f, step_f, prox_g, step_g, L):
"""Update the primal and dual variables
Note: X, Z, U are updated inline
Returns: LX, R, S
"""
if not hasattr(prox_g, '__iter__'):
if prox_g is not None:
dX = step_f/step_g * L.T.dot(L.dot(X) - Z + U)
... | python | {
"resource": ""
} |
q250649 | get_variable_errors | train | def get_variable_errors(X, L, LX, Z, U, step_g, e_rel, e_abs=0):
"""Get the errors in a single multiplier method step
For a given linear operator A, (and its dot product with X to save time),
calculate the errors in the prime and dual variables, used by the
Boyd 2011 Section 3 stopping criteria.
""... | python | {
"resource": ""
} |
q250650 | check_constraint_convergence | train | def check_constraint_convergence(X, L, LX, Z, U, R, S, step_f, step_g, e_rel, e_abs):
"""Calculate if all constraints have converged.
Using the stopping criteria from Boyd 2011, Sec 3.3.1, calculate whether the
variables for each constraint have converged.
"""
if isinstance(L, list):
M = l... | python | {
"resource": ""
} |
q250651 | check_convergence | train | def check_convergence(newX, oldX, e_rel):
"""Check that the algorithm converges using Langville 2014 criteria
Uses the check from Langville 2014, Section 5, to check if the NMF
algorithm has converged.
"""
# Calculate the norm for columns and rows, which can be used for debugging
# Otherwise sk... | python | {
"resource": ""
} |
q250652 | Traceback._store_variable | train | def _store_variable(self, j, key, m, value):
"""Store a copy of the variable in the history
| python | {
"resource": ""
} |
q250653 | Traceback.update_history | train | def update_history(self, it, j=0, M=None, **kwargs):
"""Add the current state for all kwargs to the history
"""
# Create a new entry in the history for new variables (if they don't exist)
if not np.any([k in self.history[j] for k in kwargs]):
for k in kwargs:
... | python | {
"resource": ""
} |
q250654 | generateComponent | train | def generateComponent(m):
"""Creates oscillating components to be mixed"""
freq = 25*np.random.random()
phase = | python | {
"resource": ""
} |
q250655 | generateAmplitudes | train | def generateAmplitudes(k):
"""Makes mixing coefficients"""
| python | {
"resource": ""
} |
q250656 | add_noise | train | def add_noise(Y, sigma):
"""Adds noise to Y"""
return Y + | python | {
"resource": ""
} |
q250657 | nmf | train | def nmf(Y, A, S, W=None, prox_A=operators.prox_plus, prox_S=operators.prox_plus, proxs_g=None, steps_g=None, Ls=None, slack=0.9, update_order=None, steps_g_update='steps_f', max_iter=1000, e_rel=1e-3, e_abs=0, traceback=None):
"""Non-negative matrix factorization.
This method solves the NMF problem
min... | python | {
"resource": ""
} |
q250658 | prox_zero | train | def prox_zero(X, step):
"""Proximal operator to project onto zero
""" | python | {
"resource": ""
} |
q250659 | prox_unity | train | def prox_unity(X, step, axis=0):
"""Projection onto sum=1 along an axis
""" | python | {
"resource": ""
} |
q250660 | prox_unity_plus | train | def prox_unity_plus(X, step, axis=0):
"""Non-negative projection onto | python | {
"resource": ""
} |
q250661 | prox_min | train | def prox_min(X, step, thresh=0):
"""Projection onto numbers above `thresh`
| python | {
"resource": ""
} |
q250662 | prox_max | train | def prox_max(X, step, thresh=0):
"""Projection onto numbers below `thresh`
| python | {
"resource": ""
} |
q250663 | prox_components | train | def prox_components(X, step, prox=None, axis=0):
"""Split X along axis and apply prox to each chunk.
prox can be a list.
"""
K = X.shape[axis]
if not hasattr(prox_list, '__iter__'):
prox = [prox] * K
assert len(prox_list) == K
if axis == 0:
| python | {
"resource": ""
} |
q250664 | prox_hard_plus | train | def prox_hard_plus(X, step, thresh=0):
"""Hard thresholding with projection onto non-negative numbers
"""
| python | {
"resource": ""
} |
q250665 | prox_soft | train | def prox_soft(X, step, thresh=0):
"""Soft thresholding proximal operator
| python | {
"resource": ""
} |
q250666 | prox_soft_plus | train | def prox_soft_plus(X, step, thresh=0):
"""Soft thresholding with projection onto non-negative numbers
"""
| python | {
"resource": ""
} |
q250667 | prox_max_entropy | train | def prox_max_entropy(X, step, gamma=1):
"""Proximal operator for maximum entropy regularization.
g(x) = gamma \sum_i x_i ln(x_i)
has the analytical solution of gamma W(1/gamma exp((X-gamma)/gamma)), where
W is the Lambert W function.
"""
from scipy.special import lambertw
gamma_ = _step_ga... | python | {
"resource": ""
} |
q250668 | get_gradient_y | train | def get_gradient_y(shape, py):
"""Calculate the gradient in the y direction to the line at py
The y gradient operator is a block matrix, where each block is the size of the image width.
The matrix itself is made up of (img_height x img_height) blocks, most of which are all zeros.
"""
import scipy.s... | python | {
"resource": ""
} |
q250669 | get_gradient_x | train | def get_gradient_x(shape, px):
"""Calculate the gradient in the x direction to the line at px
The y gradient operator is a block diagonal matrix, where each block is the size of the image width.
The matrix itself is made up of (img_height x img_height) blocks, most of which are all zeros.
"""
impor... | python | {
"resource": ""
} |
q250670 | NewVPK.read_dir | train | def read_dir(self, path):
"""
Reads the given path into the tree
"""
self.tree = {}
self.file_count = 0
self.path = path
for root, _, filelist in os.walk(path):
rel = root[len(path):].lstrip('/\\')
# empty rel, means file is in root dir
... | python | {
"resource": ""
} |
q250671 | NewVPK.calculate_tree_length | train | def calculate_tree_length(self):
"""
Walks the tree and calculate the tree length
"""
tree_length = 0
for ext in self.tree:
tree_length += len(ext) + 2
for relpath in self.tree[ext]:
| python | {
"resource": ""
} |
q250672 | NewVPK.save | train | def save(self, vpk_output_path):
"""
Saves the VPK at the given path
"""
with fopen(vpk_output_path, 'wb') as f:
# write VPK1 header
f.write(struct.pack("3I", self.signature,
self.version,
... | python | {
"resource": ""
} |
q250673 | VPK.get_file | train | def get_file(self, path):
"""
Returns VPKFile instance for the given path
"""
| python | {
"resource": ""
} |
q250674 | VPK.get_file_meta | train | def get_file_meta(self, path):
"""
Returns metadata for given file path
"""
if self.tree is None:
self.read_index()
if path not in self.tree:
| python | {
"resource": ""
} |
q250675 | VPK.read_header | train | def read_header(self):
"""
Reads VPK file header from the file
"""
with fopen(self.vpk_path, 'rb') as f:
(self.signature,
self.version,
self.tree_length
) = struct.unpack("3I", f.read(3*4))
# original format - headerless
... | python | {
"resource": ""
} |
q250676 | VPK.read_index | train | def read_index(self):
"""
Reads the index and populates the directory tree
"""
if not isinstance(self.tree, dict):
self.tree = dict()
| python | {
"resource": ""
} |
q250677 | VPK.read_index_iter | train | def read_index_iter(self):
"""Generator function that reads the file index from the vpk file
yeilds (file_path, metadata)
"""
with fopen(self.vpk_path, 'rb') as f:
f.seek(self.header_length)
while True:
if self.version > 0 and f.tell() > self.tr... | python | {
"resource": ""
} |
q250678 | VPKFile.save | train | def save(self, path):
"""
Save the file to the specified path
"""
# remember and restore file position
pos = self.tell()
self.seek(0)
with fopen(path, 'wb') as output:
output.truncate(self.length) | python | {
"resource": ""
} |
q250679 | VPKFile.verify | train | def verify(self):
"""
Returns True if the file contents match with the CRC32 attribute
note: reset
"""
# remember file pointer
pos = self.tell()
self.seek(0)
checksum = 0
for chunk in iter(lambda: self.read(1024), | python | {
"resource": ""
} |
q250680 | publish | train | def publish(ctx, test=False, force=False, draft=False):
""" Publish the project.
:param bool test: Publishes to PyPi test server (defaults to False)
:param bool force: Skip version check (defaults to False)
:param bool draft: Sample publish (has no effect) (defaults to False)
"""
previous_vers... | python | {
"resource": ""
} |
q250681 | _handle_dumps | train | def _handle_dumps(self, handler, **kwargs):
""" Dumps caller, used by partial method for dynamic handler assignments.
:param object handler: The dump handler
:return: The dumped | python | {
"resource": ""
} |
q250682 | _handle_dump | train | def _handle_dump(self, handler, file_object, **kwargs):
""" Dump caller, used by partial method for dynamic handler assignments.
:param object handler: The dump handler
:param file file_object: The file object to dump to
| python | {
"resource": ""
} |
q250683 | config | train | def config(maybe_cls=None, these=None, title=None, description=None):
""" File config class decorator.
Usage is to simply decorate a **class** to make it a
:func:`config <file_config._file_config.config>` class.
>>> import file_config
>>> @file_config.config(
title="My Config Title",
... | python | {
"resource": ""
} |
q250684 | var | train | def var(
type=None, # noqa
default=None,
name=None,
title=None,
description=None,
required=True,
examples=None,
encoder=None,
decoder=None,
min=None, # noqa
max=None, # noqa
unique=None,
contains=None,
**kwargs,
):
""" Creates a config variable.
Use th... | python | {
"resource": ""
} |
q250685 | make_config | train | def make_config(name, var_dict, title=None, description=None, **kwargs):
""" Creates a config instance from scratch.
Usage is virtually the same as :func:`attr.make_class`.
>>> import file_config
>>> MyConfig = file_config.make_config(
"MyConfig",
{"name": file_config.var(str)}... | python | {
"resource": ""
} |
q250686 | _build | train | def _build(config_cls, dictionary, validate=False): # noqa
""" Builds an instance of ``config_cls`` using ``dictionary``.
:param type config_cls: The class to use for building
:param dict dictionary: The dictionary to use for building ``config_cls``
:param bool validate: Performs validation before bui... | python | {
"resource": ""
} |
q250687 | _dump | train | def _dump(config_instance, dict_type=OrderedDict):
""" Dumps an instance from ``instance`` to a dictionary type mapping.
:param object instance: The instance to serialized to a dictionary
:param object dict_type: Some dictionary type, defaults to ``OrderedDict``
:return: Dumped dictionary
:rtype: c... | python | {
"resource": ""
} |
q250688 | validate | train | def validate(instance):
""" Validates a given ``instance``.
:param object instance: The instance to validate
:raises jsonschema.exceptions.ValidationError: On failed validation
""" | python | {
"resource": ""
} |
q250689 | from_dict | train | def from_dict(config_cls, dictionary, validate=False):
""" Loads an instance of ``config_cls`` from a dictionary.
:param type config_cls: The class to build an instance of
:param dict dictionary: The dictionary to load from
:param bool validate: Preforms validation before building ``config_cls``, | python | {
"resource": ""
} |
q250690 | BaseHandler.imported | train | def imported(self):
""" The imported handler module.
:return: The imported handler module.
| python | {
"resource": ""
} |
q250691 | BaseHandler.handler | train | def handler(self):
""" The current imported serialization handler module.
:return: The imported handler
| python | {
"resource": ""
} |
q250692 | BaseHandler.available | train | def available(self):
""" True if any of the supported modules from ``packages`` is available for use.
:return: True if any modules from ``packages`` | python | {
"resource": ""
} |
q250693 | BaseHandler._discover_import | train | def _discover_import(self, prefer=None):
""" Discovers and imports the best available module from ``packages``.
:raises ModuleNotFoundError: If no module is available
:return: The name of the module to use
:rtype: str
"""
available_packages = self.packages
if is... | python | {
"resource": ""
} |
q250694 | BaseHandler._prefer_package | train | def _prefer_package(self, package):
""" Prefer a serializtion handler over other handlers.
:param str package: The name of the package to use
:raises ValueError: When the given package name is not one of the available
supported serializtion packages for this handler
:return:... | python | {
"resource": ""
} |
q250695 | BaseHandler.dumps | train | def dumps(self, config, instance, prefer=None, **kwargs):
""" An abstract dumps method which dumps an instance into the subclasses format.
:param class config: The config class of the instance
:param object instance: The instance to dump
:param str prefer: The preferred serialization mo... | python | {
"resource": ""
} |
q250696 | BaseHandler.loads | train | def loads(self, config, content, prefer=None):
""" An abstract loads method which loads an instance from some content.
:param class config: The config class to load into
:param str content: The content to load from
:param str prefer: The preferred serialization module name
:rais... | python | {
"resource": ""
} |
q250697 | BaseHandler.dump | train | def dump(self, config, instance, file_object, prefer=None, **kwargs):
""" An abstract method that dumps to a given file object.
:param class config: The config class of the instance
:param object instance: The instance to dump
:param file file_object: The file object to dump to
| python | {
"resource": ""
} |
q250698 | BaseHandler.load | train | def load(self, config, file_object, prefer=None):
""" An abstract method that loads from a given file object.
:param class config: The config class to load into
:param file file_object: The | python | {
"resource": ""
} |
q250699 | _build_attribute_modifiers | train | def _build_attribute_modifiers(var, attribute_mapping, ignore=None):
""" Handles adding schema modifiers for a given config var and some mapping.
:param attr._make.Attribute var: The config var to build modifiers for
:param Dict[str, str] attribute_mapping: A mapping of attribute to jsonschema
modi... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.