text_prompt stringlengths 157 13.1k | code_prompt stringlengths 7 19.8k ⌀ |
|---|---|
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def search(self, **kwargs):
""" Method to search environments vip based on extends search. :param search: Dict containing QuerySets to find environments vip. :pa... |
return super(ApiEnvironmentVip, self).get(
self.prepare_url('api/v3/environment-vip/', kwargs)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get(self, ids, **kwargs):
""" Method to get environments vip by their ids :param ids: List containing identifiers of environments vip :param include: Array c... |
uri = build_uri_with_ids('api/v3/environment-vip/%s/', ids)
return super(ApiEnvironmentVip, self).get(
self.prepare_url(uri, kwargs)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def delete(self, ids):
""" Method to delete environments vip by their id's. :param ids: Identifiers of environments vip :return: None """ |
url = build_uri_with_ids('api/v3/environment-vip/%s/', ids)
return super(ApiEnvironmentVip, self).delete(url) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def update(self, environments):
""" Method to update environments vip :param environments vip: List containing environments vip desired to updated :return: None ... |
data = {'environments_vip': environments}
environments_ids = [str(env.get('id')) for env in environments]
uri = 'api/v3/environment-vip/%s/' % ';'.join(environments_ids)
return super(ApiEnvironmentVip, self).put(uri, data) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def create(self, environments):
""" Method to create environments vip :param environments vip: Dict containing environments vip desired to be created on database... |
data = {'environments_vip': environments}
uri = 'api/v3/environment-vip/'
return super(ApiEnvironmentVip, self).post(uri, data) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_ipv4(self, id_ip):
"""Get IPv4 by id. :param id_ip: ID of IPv4. :return: Dictionary with the following structure: :: {'ip': {'id': < id >, 'networkipv4':... |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'The IPv4 identifier is invalid or was not informed.')
url = 'ip/get-ipv4/' + str(id_ip) + '/'
code, xml = self.submit(None, 'GET', url)
key = 'ipv4'
return get_list_map(self.response... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_ipv6(self, id_ip):
"""Get IPv6 by id. :param id_ip: ID of IPv6. :return: Dictionary with the following structure: :: {'ip': {'id': < id >, 'networkipv6':... |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'The IPv6 identifier is invalid or was not informed.')
url = 'ip/get-ipv6/' + str(id_ip) + '/'
code, xml = self.submit(None, 'GET', url)
key = 'ipv6'
return get_list_map(self.response... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def buscar_por_ip_ambiente(self, ip, id_environment):
"""Get IP with an associated environment. :param ip: IP address in the format x1.x2.x3.x4. :param id_enviro... |
if not is_valid_int_param(id_environment):
raise InvalidParameterError(
u'Environment identifier is invalid or was not informed.')
if not is_valid_ip(ip):
raise InvalidParameterError(u'IP is invalid or was not informed.')
url = 'ip/' + str(ip) + '/ambi... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_available_ip4(self, id_network):
""" Get a available IP in the network ipv4 :param id_network: Network identifier. Integer value and greater than zero. :... |
if not is_valid_int_param(id_network):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
url = 'ip/availableip4/' + str(id_network) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_ip_by_equip_and_vip(self, equip_name, id_evip):
""" Get a available IP in the Equipment related Environment VIP :param equip_name: Equipment Name. :param... |
if not is_valid_int_param(id_evip):
raise InvalidParameterError(
u'Vip environment is invalid or was not informed.')
ip_map = dict()
ip_map['equip_name'] = equip_name
ip_map['id_evip'] = id_evip
url = "ip/getbyequipandevip/"
code, xml = se... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_ipv4_or_ipv6(self, ip):
""" Get a Ipv4 or Ipv6 by IP :param ip: IPv4 or Ipv6. 'xxx.xxx.xxx.xxx or xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx' :return: Dicti... |
ip_map = dict()
ip_map['ip'] = ip
url = "ip/getbyoctblock/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def check_vip_ip(self, ip, id_evip):
""" Get a Ipv4 or Ipv6 for Vip request :param ip: IPv4 or Ipv6. 'xxx.xxx.xxx.xxx or xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx'... |
ip_map = dict()
ip_map['ip'] = ip
ip_map['id_evip'] = id_evip
url = "ip/checkvipip/"
code, xml = self.submit({'ip_map': ip_map}, 'POST', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_available_ip6(self, id_network6):
""" Get a available IP in Network ipv6 :param id_network6: Network ipv6 identifier. Integer value and greater than zero... |
if not is_valid_int_param(id_network6):
raise InvalidParameterError(
u'Network ipv6 identifier is invalid or was not informed.')
url = 'ip/availableip6/' + str(id_network6) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_available_ip6_for_vip(self, id_evip, name):
""" Get and save a available IP in the network ipv6 for vip request :param id_evip: Vip environment identifie... |
if not is_valid_int_param(id_evip):
raise InvalidParameterError(
u'Vip environment identifier is invalid or was not informed.')
url = 'ip/availableip6/vip/' + str(id_evip) + "/"
ip_map = dict()
ip_map['id_evip'] = id_evip
ip_map['name'] = name
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def edit_ipv4(self, ip4, descricao, id_ip):
""" Edit a IP4 :param ip4: An IP4 available to save in format x.x.x.x. :param id_ip: IP identifier. Integer value and... |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ip identifier is invalid or was not informed.')
if ip4 is None or ip4 == "":
raise InvalidParameterError(
u'The IP4 is invalid or was not informed.')
ip_map = dict()
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def save_ipv4(self, ip4, id_equip, descricao, id_net):
""" Save a IP4 and associate with equipment :param ip4: An IP4 available to save in format x.x.x.x. :param... |
if not is_valid_int_param(id_net):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
if not is_valid_int_param(id_equip):
raise InvalidParameterError(
u'Equipment identifier is invalid or was not informed.')
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def edit_ipv6(self, ip6, descricao, id_ip):
""" Edit a IP6 :param ip6: An IP6 available to save in format xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx. :param descric... |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ipv6 identifier is invalid or was not informed.')
if ip6 is None or ip6 == "":
raise InvalidParameterError(u'IP6 is invalid or was not informed.')
ip_map = dict()
ip_map['descrica... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def find_ip4_by_id(self, id_ip):
""" Get an IP by ID :param id_ip: IP identifier. Integer value and greater than zero. :return: Dictionary with the following str... |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ip identifier is invalid or was not informed.')
url = 'ip/get/' + str(id_ip) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def find_ips_by_equip(self, id_equip):
""" Get Ips related to equipment by its identifier :param id_equip: Equipment identifier. Integer value and greater than z... |
url = 'ip/getbyequip/' + str(id_equip) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml, ['ipv4', 'ipv6']) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def find_ip6_by_id(self, id_ip):
""" Get an IP6 by ID :param id_ip: IP6 identifier. Integer value and greater than zero. :return: Dictionary with the following s... |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ipv6 identifier is invalid or was not informed.')
url = 'ipv6/get/' + str(id_ip) + "/"
code, xml = self.submit(None, 'GET', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def save_ipv6(self, ip6, id_equip, descricao, id_net):
""" Save an IP6 and associate with equipment :param ip6: An IP6 available to save in format xxxx:xxxx:xxxx... |
if not is_valid_int_param(id_net):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
if not is_valid_int_param(id_equip):
raise InvalidParameterError(
u'Equipment identifier is invalid or was not informed.')
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def delete_ip4(self, id_ip):
""" Delete an IP4 :param id_ip: Ipv4 identifier. Integer value and greater than zero. :return: None :raise IpNotFoundError: IP is no... |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(u'Ipv4 identifier is invalid or was not informed.')
url = 'ip4/delete/' + str(id_ip) + "/"
code, xml = self.submit(None, 'DELETE', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def find_ip6_by_network(self, id_network):
"""List IPv6 from network. :param id_network: Network ipv6 identifier. Integer value and greater than zero. :return: D... |
if not is_valid_int_param(id_network):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
url = 'ip/id_network_ipv6/' + str(id_network) + "/"
code, xml = self.submit(None, 'GET', url)
key = "ips"
return get_list_ma... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def search_ipv6_environment(self, ipv6, id_environment):
"""Get IPv6 with an associated environment. :param ipv6: IPv6 address in the format x1:x2:x3:x4:x5:x6:x7... |
if not is_valid_int_param(id_environment):
raise InvalidParameterError(
u'Environment identifier is invalid or was not informed.')
ipv6_map = dict()
ipv6_map['ipv6'] = ipv6
ipv6_map['id_environment'] = id_environment
code, xml = self.submit(
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def assoc_ipv4(self, id_ip, id_equip, id_net):
""" Associate an IP4 with equipment. :param id_ip: IPv4 identifier. :param id_equip: Equipment identifier. Integer... |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ip identifier is invalid or was not informed.')
if not is_valid_int_param(id_net):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
if n... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def assoc_ipv6(self, id_ip, id_equip, id_net):
""" Associate an IP6 with equipment. :param id_ip: IPv6 identifier. :param id_equip: Equipment identifier. Integer... |
if not is_valid_int_param(id_ip):
raise InvalidParameterError(
u'Ipv6 identifier is invalid or was not informed.')
if not is_valid_int_param(id_net):
raise InvalidParameterError(
u'Network identifier is invalid or was not informed.')
if... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def listar(self):
"""List all network types. :return: Following dictionary: :: {'net_type': [{'id': < id_tipo_rede >, :raise DataBaseError: Networkapi failed to ... |
code, xml = self.submit(None, 'GET', 'net_type/')
key = 'net_type'
return get_list_map(self.response(code, xml, [key]), key) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def inserir(self, name):
"""Insert new network type and return its identifier. :param name: Network type name. :return: Following dictionary: {'net_type': {'id':... |
net_type_map = dict()
net_type_map['name'] = name
code, xml = self.submit(
{'net_type': net_type_map}, 'POST', 'net_type/')
return self.response(code, xml) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def alterar(self, id_net_type, name):
"""Edit network type by its identifier. :param id_net_type: Network type identifier. :param name: Network type name. :retur... |
if not is_valid_int_param(id_net_type):
raise InvalidParameterError(
u'Network type is invalid or was not informed.')
url = 'net_type/' + str(id_net_type) + '/'
net_type_map = dict()
net_type_map['name'] = name
code, xml = self.submit({'net_type':... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def remover(self, id_net_type):
"""Remove network type by its identifier. :param id_net_type: Network type identifier. :return: None :raise TipoRedeNaoExisteErro... |
if not is_valid_int_param(id_net_type):
raise InvalidParameterError(
u'Network type is invalid or was not informed.')
url = 'net_type/' + str(id_net_type) + '/'
code, xml = self.submit(None, 'DELETE', url)
return self.response(code, xml) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def cc(filename: 'input source file', output: 'output file name. default to be replacing input file\'s suffix with ".py"' = None, name: 'name of language' = 'unna... |
lang = Language(name)
with Path(filename).open('r') as fr:
build_language(fr.read(), lang, filename)
if not output:
base, _ = os.path.splitext(filename)
output = base + '.py'
lang.dump(output) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def rbnf_lexing(text: str):
"""Read loudly for documentation.""" |
cast_map: const = _cast_map
lexer_table: const = _lexer_table
keyword: const = _keyword
drop_table: const = _DropTable
end: const = _END
unknown: const = _UNKNOWN
text_length = len(text)
colno = 0
lineno = 0
position = 0
cast_const = Con... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def regex_lexer(regex_pat):
""" generate token names' cache """ |
if isinstance(regex_pat, str):
regex_pat = re.compile(regex_pat)
def f(inp_str, pos):
m = regex_pat.match(inp_str, pos)
return m.group() if m else None
elif hasattr(regex_pat, 'match'):
def f(inp_str, pos):
m = regex_pat.match(inp_str, pos)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def process(fn, bound_names):
""" process automatic context variable capturing. return the transformed function and its ast. """ |
if isinstance(fn, _AutoContext):
fn = fn.fn
# noinspection PyArgumentList,PyArgumentList
if isinstance(fn, _FnCodeStr):
if bound_names:
assign_code_str = '{syms} = map(state.ctx.get, {names})'.format(
syms=', '.join(bound_names) + ',', names=repr(bound_names))
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def ignore(self, *ignore_lst: str):
""" ignore a set of tokens with specific names """ |
def stream():
for each in ignore_lst:
each = ConstStrPool.cast_to_const(each)
yield id(each), each
self.ignore_lst.update(stream()) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _decode_POST_value(request, field_name, default=None):
"""Helper to decode a request field into unicode based on charsets encoding. Args: request: the HttpRe... |
if default is None:
value = request.POST[field_name]
else:
value = request.POST.get(field_name, default)
# it's inefficient to load this each time it gets called, but we're
# not anticipating incoming email being a performance bottleneck right now!
charsets = json.loads(request.POS... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _get_recipients(self, array):
"""Returns an iterator of objects from the array [["address@example.com", "Name"]] """ |
for address, name in array:
if not name:
yield address
else:
yield "\"%s\" <%s>" % (name, address) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _log_request(request):
"""Helper function to dump out debug info.""" |
logger.debug("Inbound email received")
for k, v in list(request.POST.items()):
logger.debug("- POST['%s']='%s'" % (k, v))
for n, f in list(request.FILES.items()):
logger.debug("- FILES['%s']: '%s', %sB", n, f.content_type, f.size) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def receive_inbound_email(request):
"""Receives inbound email from SendGrid. This view receives the email from SendGrid, parses the contents, logs the message an... |
# log the request.POST and request.FILES contents
if log_requests is True:
_log_request(request)
# HEAD requests are used by some backends to validate the route
if request.method == 'HEAD':
return HttpResponse('OK')
try:
# clean up encodings and extract relevant fields fro... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_backend_class():
"""Return reference to the configured backed class.""" |
# this will (intentionally) blow up if the setting does not exist
assert hasattr(settings, 'INBOUND_EMAIL_PARSER')
assert getattr(settings, 'INBOUND_EMAIL_PARSER') is not None
package, klass = settings.INBOUND_EMAIL_PARSER.rsplit('.', 1)
module = import_module(package)
return getattr(module, k... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sorted_exists(values, x):
""" For list, values, returns the insert position for item x and whether the item already exists in the list. This allows one funct... |
i = bisect_left(values, x)
j = bisect_right(values, x)
exists = x in values[i:j]
return exists, i |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sorted_index(values, x):
""" For list, values, returns the index location of element x. If x does not exist will raise an error. :param values: list :param x... |
i = bisect_left(values, x)
j = bisect_right(values, x)
return values[i:j].index(x) + i |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def runDia(diagram):
"""Generate the diagrams using Dia.""" |
ifname = '{}.dia'.format(diagram)
ofname = '{}.png'.format(diagram)
cmd = 'dia -t png-libart -e {} {}'.format(ofname, ifname)
print(' {}'.format(cmd))
subprocess.call(cmd, shell=True)
return True |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _link(self, next_worker, next_is_first=False):
"""Link the worker to the given next worker object, connecting the two workers with communication tubes.""" |
lock = multiprocessing.Lock()
next_worker._lock_prev_input = lock
self._lock_next_input = lock
lock.acquire()
lock = multiprocessing.Lock()
next_worker._lock_prev_output = lock
self._lock_next_output = lock
lock.acquire()
# If the next worker i... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def show(self, index=True, **kwargs):
""" Print the contents of the Series. This method uses the tabulate function from the tabulate package. Use the kwargs to p... |
print(self._make_table(index=index, **kwargs)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get(self, indexes, as_list=False):
""" Given indexes will return a sub-set of the Series. This method will direct to the specific methods based on what types... |
if isinstance(indexes, (list, blist)):
return self.get_rows(indexes, as_list)
else:
return self.get_cell(indexes) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_cell(self, index):
""" For a single index and return the value :param index: index value :return: value """ |
i = sorted_index(self._index, index) if self._sort else self._index.index(index)
return self._data[i] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_rows(self, indexes, as_list=False):
""" For a list of indexes return the values of the indexes in that column. :param indexes: either a list of index val... |
if all([isinstance(i, bool) for i in indexes]): # boolean list
if len(indexes) != len(self._index):
raise ValueError('boolean index list must be same size of existing index')
if all(indexes): # the entire column
data = self._data
index =... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_locations(self, locations, as_list=False):
""" For list of locations return a Series or list of the values. :param locations: list of index locations :pa... |
indexes = [self._index[x] for x in locations]
return self.get(indexes, as_list) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def to_dict(self, index=True, ordered=False):
""" Returns a dict where the keys are the data and index names and the values are list of the data and index. :para... |
result = OrderedDict() if ordered else dict()
if index:
result.update({self._index_name: self._index})
if ordered:
data_dict = [(self._data_name, self._data)]
else:
data_dict = {self._data_name: self._data}
result.update(data_dict)
ret... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def head(self, rows):
""" Return a Series of the first N rows :param rows: number of rows :return: Series """ |
rows_bool = [True] * min(rows, len(self._index))
rows_bool.extend([False] * max(0, len(self._index) - rows))
return self.get(indexes=rows_bool) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def equality(self, indexes=None, value=None):
""" Math helper method. Given a column and optional indexes will return a list of booleans on the equality of the v... |
indexes = [True] * len(self._index) if indexes is None else indexes
compare_list = self.get_rows(indexes, as_list=True)
return [x == value for x in compare_list] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sort_index(self):
""" Sort the Series by the index. The sort modifies the Series inplace :return: nothing """ |
sort = sorted_list_indexes(self._index)
# sort index
self._index = blist([self._index[x] for x in sort]) if self._blist else [self._index[x] for x in sort]
# sort data
self._data = blist([self._data[x] for x in sort]) if self._blist else [self._data[x] for x in sort] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set(self, indexes, values=None):
""" Given indexes will set a sub-set of the Series to the values provided. This method will direct to the below methods base... |
if isinstance(indexes, (list, blist)):
self.set_rows(indexes, values)
else:
self.set_cell(indexes, values) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _add_row(self, index):
""" Add a new row to the Series :param index: index of the new row :return: nothing """ |
self._index.append(index)
self._data.append(None) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _insert_row(self, i, index):
""" Insert a new row in the Series. :param i: index location to insert :param index: index value to insert into the index list :... |
if i == len(self._index):
self._add_row(index)
else:
self._index.insert(i, index)
self._data.insert(i, None) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _add_missing_rows(self, indexes):
""" Given a list of indexes, find all the indexes that are not currently in the Series and make a new row for that index by... |
new_indexes = [x for x in indexes if x not in self._index]
for x in new_indexes:
self._add_row(x) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _insert_missing_rows(self, indexes):
""" Given a list of indexes, find all the indexes that are not currently in the Series and make a new row for that index... |
new_indexes = [x for x in indexes if x not in self._index]
for x in new_indexes:
self._insert_row(bisect_left(self._index, x), x) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_cell(self, index, value):
""" Sets the value of a single cell. If the index is not in the current index then a new index will be created. :param index: i... |
if self._sort:
exists, i = sorted_exists(self._index, index)
if not exists:
self._insert_row(i, index)
else:
try:
i = self._index.index(index)
except ValueError:
i = len(self._index)
self._ad... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_rows(self, index, values=None):
""" Set rows to a single value or list of values. If any of the index values are not in the current indexes then a new ro... |
if all([isinstance(i, bool) for i in index]): # boolean list
if not isinstance(values, (list, blist)): # single value provided, not a list, so turn values into list
values = [values for x in index if x]
if len(index) != len(self._index):
raise ValueErro... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_locations(self, locations, values):
""" For a list of locations set the values. :param locations: list of index locations :param values: list of values o... |
indexes = [self._index[x] for x in locations]
self.set(indexes, values) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def append_row(self, index, value):
""" Appends a row of value to the end of the data. Be very careful with this function as for sorted Series it will not enforc... |
if index in self._index:
raise IndexError('index already in Series')
self._index.append(index)
self._data.append(value) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def append_rows(self, indexes, values):
""" Appends values to the end of the data. Be very careful with this function as for sort DataFrames it will not enforce ... |
# check that the values data is less than or equal to the length of the indexes
if len(values) != len(indexes):
raise ValueError('length of values is not equal to length of indexes')
# check the indexes are not duplicates
combined_index = self._index + indexes
if l... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
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 ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def reset_index(self):
""" Resets the index of the Series to simple integer list and the index name to 'index'. :return: nothing """ |
self.index = list(range(self.__len__()))
self.index_name = 'index' |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def value(self, indexes, int_as_index=False):
""" Wrapper function for get. It will return a list, no index. If the indexes are integers it will be assumed that ... |
# single integer value
if isinstance(indexes, int):
if int_as_index:
return self.get(indexes, as_list=True)
else:
indexes = indexes - self._offset
return self._data[indexes]
# slice
elif isinstance(indexes, slice):... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def from_dataframe(cls, dataframe, column, offset=0):
""" Creates and return a Series from a DataFrame and specific column :param dataframe: raccoon DataFrame :p... |
return cls(data=dataframe.get_entire_column(column, as_list=True), index=dataframe.index,
data_name=column, index_name=dataframe.index_name, sort=dataframe.sort, offset=offset) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def from_series(cls, series, offset=0):
""" Creates and return a Series from a Series :param series: raccoon Series :param offset: offset value must be provided ... |
return cls(data=series.data, index=series.index, data_name=series.data_name, index_name=series.index_name,
sort=series.sort, offset=offset) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get(self, timeout=None):
"""Retrieve results from all the output tubes.""" |
valid = False
result = None
for tube in self._output_tubes:
if timeout:
valid, result = tube.get(timeout)
if valid:
result = result[0]
else:
result = tube.get()[0]
if timeout:
return ... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def getLeaves(self):
"""Return the downstream leaf stages of this stage.""" |
result = list()
if not self._next_stages:
result.append(self)
else:
for stage in self._next_stages:
leaves = stage.getLeaves()
result += leaves
return result |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def build(self):
"""Create and start up the internal workers.""" |
# If there's no output tube, it means that this stage
# is at the end of a fork (hasn't been linked to any stage downstream).
# Therefore, create one output tube.
if not self._output_tubes:
self._output_tubes.append(self._worker_class.getTubeClass()())
self._worker... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _sort_columns(self, columns_list):
""" Given a list of column names will sort the DataFrame columns to match the given order :param columns_list: list of col... |
if not (all([x in columns_list for x in self._columns]) and all([x in self._columns for x in columns_list])):
raise ValueError(
'columns_list must be all in current columns, and all current columns must be in columns_list')
new_sort = [self._columns.index(x) for x in columns... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _pad_data(self, max_len=None):
""" Pad the data in DataFrame with [None} to ensure that all columns have the same length. :param max_len: If provided will ex... |
if not max_len:
max_len = max([len(x) for x in self._data])
for _, col in enumerate(self._data):
col.extend([None] * (max_len - len(col))) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get(self, indexes=None, columns=None, as_list=False, as_dict=False):
""" Given indexes and columns will return a sub-set of the DataFrame. This method will d... |
if (indexes is None) and (columns is not None) and (not isinstance(columns, (list, blist))):
return self.get_entire_column(columns, as_list)
if indexes is None:
indexes = [True] * len(self._index)
if columns is None:
columns = [True] * len(self._columns)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_cell(self, index, column):
""" For a single index and column value return the value of the cell :param index: index value :param column: column name :ret... |
i = sorted_index(self._index, index) if self._sort else self._index.index(index)
c = self._columns.index(column)
return self._data[c][i] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_rows(self, indexes, column, as_list=False):
""" For a list of indexes and a single column name return the values of the indexes in that column. :param in... |
c = self._columns.index(column)
if all([isinstance(i, bool) for i in indexes]): # boolean list
if len(indexes) != len(self._index):
raise ValueError('boolean index list must be same size of existing index')
if all(indexes): # the entire column
d... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_columns(self, index, columns=None, as_dict=False):
""" For a single index and list of column names return a DataFrame of the values in that index as eith... |
i = sorted_index(self._index, index) if self._sort else self._index.index(index)
return self.get_location(i, columns, as_dict) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_entire_column(self, column, as_list=False):
""" Shortcut method to retrieve a single column all rows. Since this is a common use case this method will be... |
c = self._columns.index(column)
data = self._data[c]
return data if as_list else DataFrame(data={column: data}, index=self._index, index_name=self._index_name,
sort=self._sort) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_matrix(self, indexes, columns):
""" For a list of indexes and list of columns return a DataFrame of the values. :param indexes: either a list of index va... |
if all([isinstance(i, bool) for i in indexes]): # boolean list
is_bool_indexes = True
if len(indexes) != len(self._index):
raise ValueError('boolean index list must be same size of existing index')
bool_indexes = indexes
indexes = list(compress(s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def get_locations(self, locations, columns=None, **kwargs):
""" For list of locations and list of columns return a DataFrame of the values. :param locations: lis... |
indexes = [self._index[x] for x in locations]
return self.get(indexes, columns, **kwargs) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _insert_row(self, i, index):
""" Insert a new row in the DataFrame. :param i: index location to insert :param index: index value to insert into the index lis... |
if i == len(self._index):
self._add_row(index)
else:
self._index.insert(i, index)
for c in range(len(self._columns)):
self._data[c].insert(i, None) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _add_row(self, index):
""" Add a new row to the DataFrame :param index: index of the new row :return: nothing """ |
self._index.append(index)
for c, _ in enumerate(self._columns):
self._data[c].append(None) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def _add_column(self, column):
""" Add a new column to the DataFrame :param column: column name :return: nothing """ |
self._columns.append(column)
if self._blist:
self._data.append(blist([None] * len(self._index)))
else:
self._data.append([None] * len(self._index)) |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
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 wil... |
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.s... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_row(self, index, values):
""" Sets the values of the columns in a single row. :param index: index value :param values: dict with the keys as the column n... |
if self._sort:
exists, i = sorted_exists(self._index, index)
if not exists:
self._insert_row(i, index)
else:
try:
i = self._index.index(index)
except ValueError: # new row
i = len(self._index)
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def set_column(self, index=None, column=None, values=None):
""" Set a column to a single value or list of values. If any of the index values are not in the curre... |
try:
c = self._columns.index(column)
except ValueError: # new column
c = len(self._columns)
self._add_column(column)
if index: # index was provided
if all([isinstance(i, bool) for i in index]): # boolean list
if not isinstance(v... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def append_row(self, index, values, new_cols=True):
""" Appends a row of values to the end of the data. If there are new columns in the values and new_cols is Tr... |
if index in self._index:
raise IndexError('index already in DataFrame')
if new_cols:
for col in values:
if col not in self._columns:
self._add_column(col)
# append index value
self._index.append(index)
# add data va... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def append_rows(self, indexes, values, new_cols=True):
""" Appends rows of values to the end of the data. If there are new columns in the values and new_cols is ... |
# check that the values data is less than or equal to the length of the indexes
for column in values:
if len(values[column]) > len(indexes):
raise ValueError('length of %s column in values is longer than indexes' % column)
# check the indexes are not duplicates
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def to_dict(self, index=True, ordered=False):
""" Returns a dict where the keys are the column names and the values are lists of the values for that column. :par... |
result = OrderedDict() if ordered else dict()
if index:
result.update({self._index_name: self._index})
if ordered:
data_dict = [(column, self._data[i]) for i, column in enumerate(self._columns)]
else:
data_dict = {column: self._data[i] for i, column i... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def rename_columns(self, rename_dict):
""" Renames the columns :param rename_dict: dict where the keys are the current column names and the values are the new na... |
if not all([x in self._columns for x in rename_dict.keys()]):
raise ValueError('all dictionary keys must be in current columns')
for current in rename_dict.keys():
self._columns[self._columns.index(current)] = rename_dict[current] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
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]
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def sort_index(self):
""" Sort the DataFrame by the index. The sort modifies the DataFrame inplace :return: nothing """ |
sort = sorted_list_indexes(self._index)
# 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.... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def validate_integrity(self):
""" Validate the integrity of the DataFrame. This checks that the indexes, column names and internal data are not corrupted. Will r... |
self._validate_columns(self._columns)
self._validate_index(self._index)
self._validate_data() |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def append(self, data_frame):
""" Append another DataFrame to this DataFrame. If the new data_frame has columns that are not in the current DataFrame then new co... |
if len(data_frame) == 0: # empty DataFrame, do nothing
return
data_frame_index = data_frame.index
combined_index = self._index + data_frame_index
if len(set(combined_index)) != len(combined_index):
raise ValueError('duplicate indexes in DataFrames')
for... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def add(self, left_column, right_column, indexes=None):
""" Math helper method that adds element-wise two columns. If indexes are not None then will only perform... |
left_list, right_list = self._get_lists(left_column, right_column, indexes)
return [l + r for l, r in zip(left_list, right_list)] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def isin(self, column, compare_list):
""" Returns a boolean list where each elements is whether that element in the column is in the compare_list. :param column:... |
return [x in compare_list for x in self._data[self._columns.index(column)]] |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def iterrows(self, index=True):
""" Iterates over DataFrame rows as dictionary of the values. The index will be included. :param index: if True include the index... |
for i in range(len(self._index)):
row = {self._index_name: self._index[i]} if index else dict()
for c, col in enumerate(self._columns):
row[col] = self._data[c][i]
yield row |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def itertuples(self, index=True, name='Raccoon'):
""" Iterates over DataFrame rows as tuple of the values. :param index: if True then include the index :param na... |
fields = [self._index_name] if index else list()
fields.extend(self._columns)
row_tuple = namedtuple(name, fields)
for i in range(len(self._index)):
row = {self._index_name: self._index[i]} if index else dict()
for c, col in enumerate(self._columns):
... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def from_json(cls, json_string):
""" Creates and return a DataFrame from a JSON of the type created by to_json :param json_string: JSON :return: DataFrame """ |
input_dict = json.loads(json_string)
# convert index to tuple if required
if input_dict['index'] and isinstance(input_dict['index'][0], list):
input_dict['index'] = [tuple(x) for x in input_dict['index']]
# convert index_name to tuple if required
if isinstance(input_... |
<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
def assert_frame_equal(left, right, data_function=None, data_args=None):
""" For unit testing equality of two DataFrames. :param left: first DataFrame :param rig... |
if data_function:
data_args = {} if not data_args else data_args
data_function(left.data, right.data, **data_args)
else:
assert left.data == right.data
assert left.index == right.index
assert left.columns == right.columns
assert left.index_name == right.index_name
assert... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.