output
stringlengths
1
928k
instruction
stringlengths
7
928k
system
stringlengths
0
104k
Get an IP by ID.
Can you generate the documentation for the following Python 3 function def find_ip4_by_id(self, id_ip): 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 = s...
You are a Python code analyst, evaluating scripts for potential improvements.
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 zero. :return: Dictionary with the following structure: { ips: { ipv4:[ id: <id_ip4>, oct...
Can you write a function in Python 3 where it gets Ips related to an equipment by its identifier.
You are a Python code analyst, evaluating scripts for potential improvements.
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 structure: :: {'ip': {'id': < id >, 'block1': <block1>, 'block2': <block2>, ...
Can you implement a function in Python 3 that gets an IP6 by ID.
You are a Python code analyst, evaluating scripts for potential improvements.
Save an IP6 and associate with equipment.
Here you have a function in Python 3, explain what it does def save_ipv6(self, ip6, id_equip, descricao, id_net): 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): ...
You are a Python code analyst, evaluating scripts for potential improvements.
Delete an IP4 from the database.
Given the following Python 3 function, write the documentation def delete_ip4(self, id_ip): 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...
As a python code expert, you are capable of creating scripts from specifications.
List IPv6 from network.
Can you generate the documentation for the following Python 3 function def find_ip6_by_network(self, id_network): 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_...
You are a Python code analyst, evaluating scripts for potential improvements.
Search IPv6 with an associated environment.
Can you tell what is the following Python 3 function doing def search_ipv6_environment(self, ipv6, id_environment): if not is_valid_int_param(id_environment): raise InvalidParameterError( u'Environment identifier is invalid or was not informed.') ipv6_map = dict() i...
As a Python code composer, you craft elegant and concise scripts.
Associate an IP4 with an equipment.
Explain what the following Python 3 code does def assoc_ipv4(self, id_ip, id_equip, id_net): 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 InvalidParamete...
You are a Python code architect, reviewing and designing scalable and efficient code
Associate an IPv6 with an equipment.
How would you explain what the following Python 3 function does def assoc_ipv6(self, id_ip, id_equip, id_net): 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): r...
As a Python code analyst, you investigate and solve complex coding mysteries
List all network types.
Explain what the following Python 3 code does def listar(self): code, xml = self.submit(None, 'GET', 'net_type/') key = 'net_type' return get_list_map(self.response(code, xml, [key]), key)
You are a Python code analyst, evaluating scripts for potential improvements.
Insert a new network type and return its identifier.
Given the following Python 3 function, write the documentation def inserir(self, name): 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)
You are a Python code architect, reviewing and designing scalable and efficient code
Edit network type by its identifier.
Given the following Python 3 function, write the documentation def alterar(self, id_net_type, name): 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...
As a python code expert, you are capable of creating scripts from specifications.
Remove network type by its identifier.
Can you generate the documentation for the following Python 3 function def remover(self, id_net_type): 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) + '/' co...
As a python code expert, you are capable of creating scripts from specifications.
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' = 'unname'): """ rbnf source code compiler. """ lang = Language(name) with Path(filename).open('r') as fr: build_l...
Write a Python 3 function that can compile rbnf source code file
As a Python code translator, you convert algorithms and pseudocode into Python.
def run(filename: 'python file generated by `rbnf` command, or rbnf sour file', opt: 'optimize switch' = False): """ You can apply immediate tests on your parser. P.S: use `--opt` option takes longer starting time. """ from rbnf.easy import build_parser import importlib.util import t...
Write a Python 3 function for running the parser and returns a tree of all the modules that are parsed.
As a Python code translator, you convert algorithms and pseudocode into Python.
Read loudly for documentation.
Can you tell what is the following Python 3 function doing def rbnf_lexing(text: str): 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(te...
As a Python code translator, you convert algorithms and pseudocode into Python.
def recover_codes(tokens: Iterator[Tokenizer]) -> str: """ from a series of tokenizers to code string. (preserve the indentation) """ tokens = iter(tokens) s = [] try: head = next(tokens) except StopIteration: return s append = s.append lineno = head.lineno ...
Can you implement a function in Python 3 that recovers the code string from a series of tokenizers to a series of code strings.
You are a Python code generator, capable of creating scripts from specifications.
generate token strings cache
Make a summary of the following Python 3 code def str_lexer(mode): cast_to_const = ConstStrPool.cast_to_const def f_raw(inp_str, pos): return cast_to_const(mode) if inp_str.startswith(mode, pos) else None def f_collection(inp_str, pos): for each in mode: if inp_str.startswith(e...
You are a Python code architect, reviewing and designing scalable and efficient code
Dispatcher function dispatching tree type T to method _T.
Here you have a function in Python 3, explain what it does def dispatch(self, tree): "Dispatcher function, dispatching tree type T to method _T." if isinstance(tree, list): for t in tree: self.dispatch(t) return meth = getattr(self, "_" + tree.__class__.__...
As a python code expert, you are capable of creating scripts from specifications.
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: ...
Implement a function in Python 3 to process a function and its ast.
As a Python code analyst, you investigate and solve complex coding mysteries
ignore a set of tokens with specific names
Explain what the following Python 3 code does def ignore(self, *ignore_lst: str): def stream(): for each in ignore_lst: each = ConstStrPool.cast_to_const(each) yield id(each), each self.ignore_lst.update(stream())
You are a Python code analyst, evaluating scripts for potential improvements.
def build_language(source_code: str, lang: Language, filename: str): """ lang: language object represents your language. """ state = MetaState(rbnf.implementation, requires=_Wild(), filename=filename) state.data = lang _build_language(source_code, state) lang.build()
Create a Python 3 function to build a language from a source code.
You are a Python code generator, capable of creating scripts from specifications.
Helper function to decode a request field into unicode based on charsets encoding.
Can you generate the documentation for the following Python 3 function def _decode_POST_value(request, field_name, default=None): 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...
As a python code expert, you are capable of creating scripts from specifications.
def _get_addresses(self, address_data, retain_name=False): """ Takes RFC-compliant email addresses in both terse (email only) and verbose (name + email) forms and returns a list of email address strings (TODO: breaking change that returns a tuple of (name, email) per string) ...
Can you write a function in Python 3 where it takes a list of RFC - compliant email addresses and returns a list of strings each containing the name and email addresses.
As a Python code analyst, you investigate and solve complex coding mysteries
Parse an incoming request and return an EmailMultiAlternatives instance.
Can you generate the documentation for the following Python 3 function def parse(self, request): assert isinstance(request, HttpRequest), "Invalid request type: %s" % type(request) try: # from_email should never be a list (unless we change our API) from_email = self._get_address...
You are a Python code analyst, evaluating scripts for potential improvements.
def parse(self, request): """Parse incoming request and return an email instance. Mailgun does a lot of the heavy lifting at their end - requests come in from them UTF-8 encoded, and with the message reply and signature stripped out for you. Args: request: an HttpRe...
Write a Python 3 function for parsing an incoming request and return an EmailMultiAlternatives instance.
As a Python code analyst, you investigate and solve complex coding mysteries
def _get_recipients(self, array): """Returns an iterator of objects in the form ["Name <address@example.com", ...] from the array [["address@example.com", "Name"]] """ for address, name in array: if not name: yield address else: ...
Create a Python 3 function to return an iterator of objects from the array
As a Python code composer, you craft elegant and concise scripts.
Parse an incoming request and return an EmailMultiAlternatives instance.
Make a summary of the following Python 3 code def parse(self, request): assert isinstance(request, HttpRequest), "Invalid request type: %s" % type(request) if settings.INBOUND_MANDRILL_AUTHENTICATION_KEY: _check_mandrill_signature( request=request, key=settin...
As a python code expert, you are capable of creating scripts from specifications.
Receives the inbound email from SendGrid.
Can you generate the documentation for the following Python 3 function def receive_inbound_email(request): # 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'...
As a Python code composer, you craft elegant and concise scripts.
Return reference to the configured backed class.
Can you tell what is the following Python 3 function doing def get_backend_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_PAR...
As a Python code analyst, you investigate and solve complex coding mysteries
Returns the insert position for item x and whether the item already exists in the list.
Can you tell what is the following Python 3 function doing def sorted_exists(values, x): i = bisect_left(values, x) j = bisect_right(values, x) exists = x in values[i:j] return exists, i
As a Python code analyst, you investigate and solve complex coding mysteries
def sorted_list_indexes(list_to_sort, key=None, reverse=False): """ Sorts a list but returns the order of the index values of the list for the sort and not the values themselves. For example is the list provided is ['b', 'a', 'c'] then the result will be [2, 1, 3] :param list_to_sort: list to sort ...
Write a Python 3 function that can sort a list but returns the order of the index values of the list.
As a Python code translator, you convert algorithms and pseudocode into Python.
Generate the diagrams using Dia.
Here you have a function in Python 3, explain what it does def runDia(diagram): 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
You are a Python code analyst, evaluating scripts for potential improvements.
def init2( self, input_tube, # Read task from the input tube. output_tubes, # Send result on all the output tubes. num_workers, # Total number of workers in the stage. disable_result, # Whether to override any result with None. do_stop_task, # Whether to ...
Write a Python 3 script for initializing the ordered worker.
You are a Python code architect, reviewing and designing scalable and efficient code
Assemble and start workers.
Make a summary of the following Python 3 code def assemble( cls, args, input_tube, output_tubes, size, disable_result=False, do_stop_task=False, ): """Create, assemble and start workers. Workers are created of class *cls*, initialized ...
As a python code expert, you are capable of creating scripts from specifications.
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() ...
Can you create a Python 3 function that links the worker to the given next worker object.
As a Python code translator, you convert algorithms and pseudocode into Python.
def putResult(self, result): """Register the *result* by putting it on all the output tubes.""" self._lock_prev_output.acquire() for tube in self._tubes_result_output: tube.put((result, 0)) self._lock_next_output.release()
Create a Python 3 function for registering the result by putting it on all the output tubes.
You are a Python code generator, capable of creating scripts from specifications.
Initialize the unordered worker.
Can you generate a brief explanation for the following Python 3 code def init2( self, input_tube, # Read task from the input tube. output_tubes, # Send result on all the output tubes. num_workers, # Total number of workers in the stage. disable_result, # Whether to ...
You are a Python code analyst, evaluating scripts for potential improvements.
def assemble( cls, args, input_tube, output_tubes, size, disable_result, do_stop_task, ): """Create, assemble and start workers. Workers are created of class *cls*, initialized with *args*, and given task/result communication c...
Implement a function in Python 3 to assemble and start workers.
As a Python code translator, you convert algorithms and pseudocode into Python.
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 pass along any arguments to the tabulate function. :param index: If True then include the indexes as a column in the output, if...
Can you implement a function in Python 3 that prints the contents of the Series.
As a python code expert, you are capable of creating scripts from specifications.
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 are passed in for the indexes. The type of the return is determined by the types of the parameters. :param indexes: i...
Write a Python 3 script for giving indexes will return a sub-set of the Series. This method will direct to the specific methods based on what types are passed in for the indexes. The type of the return is determined by the types of the parameters. :param indexes: index value, list of index values, or a list of booleans...
You are a Python code analyst, evaluating scripts for potential improvements.
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]
How would you code a function in Python 3 to return the value of the key - value pair for a single index and return the value
As a Python code composer, you craft elegant and concise scripts.
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 values or a list of booleans with same length as all indexes :param as_list: if True return a list, if False return Series ...
Write a Python 3 script for returning the rows of the table.
As a Python code analyst, you investigate and solve complex coding mysteries
Returns a dictionary of the index and value for the specified index location
How would you explain what the following Python 3 function does def get_location(self, location): return {self.index_name: self._index[location], self.data_name: self._data[location]}
As a python code expert, you are capable of creating scripts from specifications.
Get the values for a list of locations.
Make a summary of the following Python 3 code def get_locations(self, locations, as_list=False): indexes = [self._index[x] for x in locations] return self.get(indexes, as_list)
You are a Python code analyst, evaluating scripts for potential improvements.
def get_slice(self, start_index=None, stop_index=None, as_list=False): """ For sorted Series will return either a Series or list of all of the rows where the index is greater than or equal to the start_index if provided and less than or equal to the stop_index if provided. If either the ...
Implement a function in Python 3 to return a slice of the data from the index.
As a Python code translator, you convert algorithms and pseudocode into Python.
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. :param index: If True then include the index in the dict with the index_name as the key :param ordered: If True then return an Orde...
Can you create a Python 3 function that returns a dict containing the data and index names and the values are the data and index names.
You are a Python code analyst, evaluating scripts for potential improvements.
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)
Write a Python 3 script for returning a Series of the first N rows
You are a Python code generator, capable of creating scripts from specifications.
Select the elements in the index that match the compare parameter and returns either a list of booleans or values that match the compare parameter.
Here you have a function in Python 3, explain what it does def select_index(self, compare, result='boolean'): if isinstance(compare, tuple): # this crazy list comprehension will match all the tuples in the list with None being an * wildcard booleans = [all([(compare[i] == w if compare[i]...
You are a Python code analyst, evaluating scripts for potential improvements.
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 value for that index in the DataFrame to the value parameter. :param indexes: list of index values or list of booleans. If a li...
Write a Python 3 script for returning a list of booleans on the equality of the value for the given indexes.
As a python code expert, you are capable of creating scripts from specifications.
Pad the data in Series with None to ensure that data is the same length as index
Here you have a function in Python 3, explain what it does def _pad_data(self, index_len): self._data.extend([None] * (index_len - len(self._data)))
You are a Python code analyst, evaluating scripts for potential improvements.
Sort the Series by the index. The sort modifies the Series inplace
Make a summary of the following Python 3 code def sort_index(self): 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 s...
You are a Python code architect, reviewing and designing scalable and efficient code
This method will set the values of the given indexes in the Series.
Can you generate the documentation for the following Python 3 function def set(self, indexes, values=None): if isinstance(indexes, (list, blist)): self.set_rows(indexes, values) else: self.set_cell(indexes, values)
As a Python code analyst, you investigate and solve complex coding mysteries
Add a new row to the Series
Given the following Python 3 function, write the documentation def _add_row(self, index): self._index.append(index) self._data.append(None)
You are a Python code generator, capable of creating scripts from specifications.
Insert a new row in the Series.
Can you generate a brief explanation for the following Python 3 code def _insert_row(self, i, index): if i == len(self._index): self._add_row(index) else: self._index.insert(i, index) self._data.insert(i, None)
As a python code expert, you are capable of creating scripts from specifications.
Given a list of indexes add missing rows to the Series.
Here you have a function in Python 3, explain what it does def _add_missing_rows(self, indexes): new_indexes = [x for x in indexes if x not in self._index] for x in new_indexes: self._add_row(x)
As a python code expert, you are capable of creating scripts from specifications.
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, inserting into the index. This requires the Series to be sorted=True :param indexes: list of indexes :return: nothin...
How would you code a function in Python 3 to give a list of indexes find all the indexes that are not currently in the Series and insert a new row for those that are not in the index.
As a Python code composer, you craft elegant and concise scripts.
Sets the value of a single cell.
How would you explain what the following Python 3 function does def set_cell(self, index, value): if self._sort: exists, i = sorted_exists(self._index, index) if not exists: self._insert_row(i, index) else: try: i = self._index.index(in...
You are a Python code architect, reviewing and designing scalable and efficient code
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 row will be created. :param index: list of index values or list of booleans. If a list of booleans then the list must be the sam...
Write a Python 3 function that can set the rows of the current DataFrame to a single value or list of values.
You are a Python code generator, capable of creating scripts from specifications.
Set the values for a list of locations.
Can you tell what is the following Python 3 function doing def set_locations(self, locations, values): indexes = [self._index[x] for x in locations] self.set(indexes, values)
As a python code expert, you are capable of creating scripts from specifications.
Appends a row of value to the end of the data.
Here you have a function in Python 3, explain what it does def append_row(self, index, value): if index in self._index: raise IndexError('index already in Series') self._index.append(index) self._data.append(value)
You are a Python code architect, reviewing and designing scalable and efficient code
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 sort order. Use this only for speed when needed, be careful. :param indexes: list of indexes to append :param values:...
Create a Python 3 function to append the values to the end of the data.
As a Python code translator, you convert algorithms and pseudocode into Python.
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, ...
Create a Python 3 function to delete rows from the DataFrame COOKIE table.
As a Python code analyst, you investigate and solve complex coding mysteries
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'
Write a Python 3 function that can reset the index of the Series to simple integer list and the index name to index.
As a Python code analyst, you investigate and solve complex coding mysteries
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 they are locations unless int_as_index = True. If the indexes are locations then they will be rotated to the left by offset nu...
Can you create a Python 3 function that wraps function for get. It will return a list of values or booleans.
As a Python code analyst, you investigate and solve complex coding mysteries
def from_dataframe(cls, dataframe, column, offset=0): """ Creates and return a Series from a DataFrame and specific column :param dataframe: raccoon DataFrame :param column: column name :param offset: offset value must be provided as there is no equivalent for a DataFrame ...
Create a Python 3 function to create and return a Series from a DataFrame and specific columnname
As a Python code composer, you craft elegant and concise scripts.
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 as there is no equivalent for a DataFrame :return: Series """ return cls(data=series.data, index=serie...
Can you create a Python 3 function that creates and return a Series from a Series
You are a Python code architect, reviewing and designing scalable and efficient code
Get the next available item from the tube.
Here you have a function in Python 3, explain what it does def get(self, timeout=None): if timeout: try: result = self._queue.get(True, timeout) except multiprocessing.Queue.Empty: return(False, None) return(True, result) return self._q...
You are a Python code architect, reviewing and designing scalable and efficient code
Retrieve results from all the output tubes.
Can you generate the documentation for the following Python 3 function def get(self, timeout=None): valid = False result = None for tube in self._output_tubes: if timeout: valid, result = tube.get(timeout) if valid: result = result[...
As a python code expert, you are capable of creating scripts from specifications.
Link this stage to the given downstream stage.
Can you generate the documentation for the following Python 3 function def link(self, next_stage): if next_stage is self: raise ValueError('cannot link stage to itself') self._output_tubes.append(next_stage._input_tube) self._next_stages.append(next_stage) return self
As a Python code translator, you convert algorithms and pseudocode into Python.
Return the downstream leaf stages of this stage.
How would you explain what the following Python 3 function does def getLeaves(self): result = list() if not self._next_stages: result.append(self) else: for stage in self._next_stages: leaves = stage.getLeaves() result += leaves ret...
You are a Python code analyst, evaluating scripts for potential improvements.
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...
Write a Python 3 function that can create and start up the internal workers.
You are a Python code generator, capable of creating scripts from specifications.
Return the next available item from the tube.
Given the following Python 3 function, write the documentation def get(self, timeout=None): if timeout: # Todo: Consider locking the poll/recv block. # Otherwise, this method is not thread safe. if self._conn1.poll(timeout): return (True, self._conn1.recv()) ...
As a Python code translator, you convert algorithms and pseudocode into Python.
This function will sort the columns of the DataFrame to match the given order.
Can you tell what is the following Python 3 function doing def _sort_columns(self, columns_list): 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 curr...
As a Python code composer, you craft elegant and concise scripts.
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 extend all columns to this length, if not then will use the longest column :return: nothing """ if not max_len: ...
Create a Python 3 function to pad the data in DataFrame with [ None ] to ensure that all columns have the same length.
As a Python code analyst, you investigate and solve complex coding mysteries
This method will return a sub - set of the DataFrame.
Given the following Python 3 function, write the documentation def get(self, indexes=None, columns=None, as_list=False, as_dict=False): 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 ...
You are a Python code architect, reviewing and designing scalable and efficient code
Returns the value of the cell with the given index and column.
Can you generate the documentation for the following Python 3 function def get_cell(self, index, column): i = sorted_index(self._index, index) if self._sort else self._index.index(index) c = self._columns.index(column) return self._data[c][i]
As a Python code composer, you craft elegant and concise scripts.
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 indexes: either a list of index values or a list of booleans with same length as all indexes :param column: single column name ...
How would you implement a function in Python 3 that returns a DataFrame containing the values of the indexes in that column.
As a Python code composer, you craft elegant and concise scripts.
Get the columns of a single index and list of column names
Can you generate a brief explanation for the following Python 3 code def get_columns(self, index, columns=None, as_dict=False): i = sorted_index(self._index, index) if self._sort else self._index.index(index) return self.get_location(i, columns, as_dict)
You are a Python code analyst, evaluating scripts for potential improvements.
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 faster than the more general method. :param column: single column name :param as_list: if True return a list, if Fals...
Create a Python 3 function to get the entire column of the data table.
As a Python code translator, you convert algorithms and pseudocode into Python.
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 values or a list of booleans with same length as all indexes :param columns: list of column names :return: DataFrame ...
Write a Python 3 script for returning a DataFrame of the values for a list of indexes and columns.
As a python code expert, you are capable of creating scripts from specifications.
def get_location(self, location, columns=None, as_dict=False, index=True): """ For an index location and either (1) list of columns return a DataFrame or dictionary of the values or (2) single column name and return the value of that cell. This is optimized for speed because it does not need ...
How would you implement a function in Python 3 that returns a DataFrame or dictionary of the values of the column with the given location.
As a Python code composer, you craft elegant and concise scripts.
def get_slice(self, start_index=None, stop_index=None, columns=None, as_dict=False): """ For sorted DataFrames will return either a DataFrame or dict of all of the rows where the index is greater than or equal to the start_index if provided and less than or equal to the stop_index if provided. I...
Write a Python 3 script to return a DataFrame or tuple of the index and data values of the entry in the table.
You are a Python code analyst, evaluating scripts for potential improvements.
Insert a new row in the DataFrame.
Here you have a function in Python 3, explain what it does def _insert_row(self, i, index): 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)
As a python code expert, you are capable of creating scripts from specifications.
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)
Write a Python 3 function for adding a new row to the DataFrame.
As a python code expert, you are capable of creating scripts from specifications.
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....
Can you create a Python 3 function that adds a new column to the DataFrame.
As a python code expert, you are capable of creating scripts from specifications.
def set(self, indexes=None, columns=None, values=None): """ Given indexes and columns will set a sub-set of the DataFrame to the values provided. This method will direct to the below methods based on what types are passed in for the indexes and columns. If the indexes or columns contains...
Create a Python 3 function for giving indexes and columns will set a sub-set of the DataFrame to the values provided. This method will direct to the below methods based on what types are passed in for the indexes and columns. If the indexes or columns contains values not in the DataFrame then new rows or columns will b...
As a Python code composer, you craft elegant and concise scripts.
def set_cell(self, index, column, value): """ Sets the value of a single cell. If the index and/or column is not in the current index/columns then a new index and/or column will be created. :param index: index value :param column: column name :param value: value to set ...
Can you implement a function in Python 3 that sets the value of a single cell.
You are a Python code architect, reviewing and designing scalable and efficient code
Sets the values of the columns in a single row.
Can you generate the documentation for the following Python 3 function def set_row(self, index, values): if self._sort: exists, i = sorted_exists(self._index, index) if not exists: self._insert_row(i, index) else: try: i = self._index.i...
As a Python code translator, you convert algorithms and pseudocode into Python.
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 current indexes then a new row will be created. :param index: list of index values or list of booleans. If a list of booleans then ...
Write a Python 3 function that can set a column to a single value or list of values.
As a Python code translator, you convert algorithms and pseudocode into Python.
def set_location(self, location, values, missing_to_none=False): """ Sets the column values, as given by the keys of the values dict, for the row at location to the values of the values dict. If missing_to_none is False then columns not in the values dict will be left unchanged, if it is ...
Can you create a Python 3 function that sets the values for the column values for the row at the given location.
As a Python code composer, you craft elegant and concise scripts.
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 True they will be added. Be very careful with this function as for sort DataFrames it will not enforce sort order. Use this only...
Can you create a Python 3 function that appends a row of values to the end of the data.
As a python code expert, you are capable of creating scripts from specifications.
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 True they will be added. Be very careful with this function as for sort DataFrames it will not enforce sort order. Use this on...
Write a Python 3 function that can append rows of values to the end of the data.
As a python code expert, you are capable of creating scripts from specifications.
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. :param index: If True then include the index in the dict with the index_name as the key :param ordered: If True then return an Ord...
Write a Python 3 script for returning a dict containing the key - value pairs of column names and the values of that column.
As a Python code analyst, you investigate and solve complex coding mysteries
def to_json(self): """ Returns a JSON of the entire DataFrame that can be reconstructed back with raccoon.from_json(input). Any object that cannot be serialized will be replaced with the representation of the object using repr(). In that instance the DataFrame will have a string represen...
Write a Python 3 function that can return a JSON string of the entire DataFrame that can be reconstructed back with raccoon. from_json.
As a Python code composer, you craft elegant and concise scripts.
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 names :return: nothing """ if not all([x in self._columns for x in rename_dict.keys()]): raise Value...
Implement a function in Python 3 to rename the columns of the table.
You are a Python code analyst, evaluating scripts for potential improvements.
Deletes all rows in the DataFrame.
Make a summary of the following Python 3 code def delete_all_rows(self): del self._index[:] for c in range(len(self._columns)): del self._data[c][:]
As a Python code analyst, you investigate and solve complex coding mysteries
Delete columns from the DataFrame
Can you generate the documentation for the following Python 3 function def delete_columns(self, columns): 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') ...
As a Python code analyst, you investigate and solve complex coding mysteries
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] fo...
Implement a Python 3 function for sorting the DataFrame by the index. The sort modifies the DataFrame inplace
You are a Python code architect, reviewing and designing scalable and efficient code
Sort the DataFrame by one of the columns.
Make a summary of the following Python 3 code def sort_columns(self, column, key=None, reverse=False): if isinstance(column, (list, blist)): raise TypeError('Can only sort by a single column ') sort = sorted_list_indexes(self._data[self._columns.index(column)], key, reverse) # sort ...
As a python code expert, you are capable of creating scripts from specifications.