output stringlengths 1 928k | instruction stringlengths 7 928k | system stringlengths 0 104k |
|---|---|---|
Link all the types in this module and all included modules. | Here you have a function in Python 3, explain what it does
def link(self):
if self.linked:
return self
self.linked = True
included_modules = []
# Link includes
for include in self.includes.values():
included_modules.append(include.link().surface)
... | As a Python code composer, you craft elegant and concise scripts. |
def compile(self, name, contents, path=None):
"""Compile the given Thrift document into a Python module.
The generated module contains,
.. py:attribute:: __services__
A collection of generated classes for all services defined in the
thrift file.
.. version... | Write a Python 3 script to
compile the given Thrift document into a Python module. | As a Python code translator, you convert algorithms and pseudocode into Python. |
t_LITERAL is a parser for the ISO - 8601 tag. | Make a summary of the following Python 3 code
def t_LITERAL(self, t):
r'(\"([^\\\n]|(\\.))*?\")|\'([^\\\n]|(\\.))*?\''
s = t.value[1:-1]
maps = {
't': '\t',
'r': '\r',
'n': '\n',
'\\': '\\',
'\'': '\'',
'"': '\"'
}
... | As a Python code analyst, you investigate and solve complex coding mysteries |
t_IDENTIFIER is a identifier | Can you generate the documentation for the following Python 3 function
def t_IDENTIFIER(self, t):
r'[a-zA-Z_](\.[a-zA-Z_0-9]|[a-zA-Z_0-9])*'
if t.value in THRIFT_KEYWORDS:
# Not an identifier after all.
t.type = t.value.upper()
return t | You are a Python code architect, reviewing and designing scalable and efficient code |
Reset the lexer and feed in new input. | Can you tell what is the following Python 3 function doing
def input(self, data):
# input(..) doesn't reset the lineno. We have to do that manually.
self._lexer.lineno = 1
return self._lexer.input(data) | As a Python code composer, you craft elegant and concise scripts. |
def from_json(cls, session, photo_json):
"""
https://vk.com/dev/objects/photo
"""
photo = cls()
photo.id = photo_json.get('id')
photo.album_id = photo_json.get('album_id')
photo.owner_id = photo_json.get('owner_id')
photo.user_id = photo_json.get('user_id'... | Can you create a Python 3 function that
creates a photo object from a JSON response. | You are a Python code architect, reviewing and designing scalable and efficient code |
def _get_photos(session, user_or_group_id):
"""
https://vk.com/dev/photos.getAll
"""
response = session.fetch_items("photos.getAll", Photo.from_json, count=200, owner_id=user_or_group_id)
return response | Write a Python 3 function for
getting all photos for a user or group. | As a python code expert, you are capable of creating scripts from specifications. |
Get owner cover photo upload server. | Can you generate the documentation for the following Python 3 function
def _get_owner_cover_photo_upload_server(session, group_id, crop_x=0, crop_y=0, crop_x2=795, crop_y2=200):
group_id = abs(group_id)
response = session.fetch("photos.getOwnerCoverPhotoUploadServer", group_id=group_id, crop_x=crop_x, c... | You are a Python code generator, capable of creating scripts from specifications. |
Save a photo to the owner cover. | Make a summary of the following Python 3 code
def _save_owner_cover_photo(session, hash, photo):
response = session.fetch('photos.saveOwnerCoverPhoto', hash=hash, photo=photo)
return response | You are a Python code architect, reviewing and designing scalable and efficient code |
Get the ID and owner ID of a save wall photo. | How would you explain what the following Python 3 function does
def _get_save_wall_photo(session, photo, server, hash, user_id=None, group_id=None):
if group_id < 0:
group_id = abs(group_id)
response = session.fetch("photos.saveWallPhoto", photo=photo, server=server, hash=hash, user_id=user... | As a Python code analyst, you investigate and solve complex coding mysteries |
def _get_save_messages_photo(session, photo, server, hash):
"""
https://vk.com/dev/photos.saveMessagesPhoto
"""
response = session.fetch("photos.saveMessagesPhoto", photo=photo, server=server, hash=hash)[0]
return response['id'], response['owner_id'] | Create a Python 3 function for
getting the ID and owner ID of a save messages photo. | As a Python code analyst, you investigate and solve complex coding mysteries |
Returns the city of the user if it exists else None. | Given the following Python 3 function, write the documentation
def get_city(self):
response = self._session.fetch("users.get", user_ids=self.id, fields="city")[0]
if response.get('city'):
return City.from_json(self._session, response.get('city')) | You are a Python code architect, reviewing and designing scalable and efficient code |
Get the country of the user. | Can you generate the documentation for the following Python 3 function
def get_country(self):
response = self._session.fetch("users.get", user_ids=self.id, fields="country")[0]
if response.get('country'):
return Country.from_json(self._session, response.get('country')) | As a python code expert, you are capable of creating scripts from specifications. |
Get a list of followers for this user. | Make a summary of the following Python 3 code
def get_followers(self):
response = self._session.fetch_items("users.getFollowers", self.from_json, self._session, count=1000, user_id=self.id, fields=self.USER_FIELDS)
return response | As a python code expert, you are capable of creating scripts from specifications. |
def _get_user(session, slug_or_user_id):
"""
:param slug_or_user_id: str or int
:return: User
"""
user_json_items = session.fetch('users.get', user_ids=slug_or_user_id, fields=User.USER_FIELDS)
return User.from_json(session, user_json_items[0]) | Can you implement a function in Python 3 that
gets a User object from the session. | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_data():
"""
Currently pretends to talk to an instrument and get back the magnitud
and phase of the measurement.
"""
# pretend we're measuring a noisy resonance at zero
y = 1.0 / (1.0 + 1j*(n_x.get_value()-0.002)*1000) + _n.random.rand()*0.1
# and that it takes time to do so
_t.... | Can you implement a function in Python 3 that
gets the data from the | As a python code expert, you are capable of creating scripts from specifications. |
def List(self):
"""
Lists the keys and values.
"""
print()
for key in list(self.keys()):
print(key,'=',self[key])
print() | Implement a function in Python 3 to
list the keys and values. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def Set(self, key, value):
"""
Sets the key-value pair and dumps to the preferences file.
"""
if not value == None: self.prefs[key] = value
else: self.prefs.pop(key)
self.Dump() | Write a Python 3 script to
set the key - value pair and dumps to the preferences file. | As a Python code translator, you convert algorithms and pseudocode into Python. |
def MakeDir(self, path="temp"):
"""
Creates a directory of the specified path in the .spinmob directory.
"""
full_path = _os.path.join(self.path_home, path)
# only make it if it doesn't exist!
if not _os.path.exists(full_path): _os.makedirs(full_path) | How would you implement a function in Python 3 that
creates a directory of the specified path in the spinmob directory. | You are a Python code generator, capable of creating scripts from specifications. |
def ListDir(self, path="temp"):
"""
Returns a list of files in the specified path (directory), or an
empty list if the directory doesn't exist.
"""
full_path = _os.path.join(self.path_home, path)
# only if the path exists!
if _os.path.exists(full_path) and _os.pa... | Write a Python 3 function for
listing the directory of the user s log files. | You are a Python code architect, reviewing and designing scalable and efficient code |
def _convert_list2str(self, fields):
"""
:param fields: ('bdate', 'domain')
:return: 'bdate,domain'
"""
if isinstance(fields, tuple) or isinstance(fields, list):
return ','.join(fields)
return fields | How would you code a function in Python 3 to
convert list to string | As a python code expert, you are capable of creating scripts from specifications. |
start : header definition | Here you have a function in Python 3, explain what it does
def p_start(self, p):
'''start : header definition'''
p[0] = ast.Program(headers=p[1], definitions=p[2]) | As a python code expert, you are capable of creating scripts from specifications. |
include : INCLUDE IDENTIFIER LITERAL
| INCLUDE LITERAL | Given the following Python 3 function, write the documentation
def p_include(self, p):
'''include : INCLUDE IDENTIFIER LITERAL
| INCLUDE LITERAL'''
if len(p) == 4:
p[0] = ast.Include(name=p[2], path=p[3], lineno=p.lineno(1))
else:
p[0] = ast.Include(nam... | You are a Python code generator, capable of creating scripts from specifications. |
parse a NAMESPACE node | Here you have a function in Python 3, explain what it does
def p_namespace(self, p):
'''namespace : NAMESPACE namespace_scope IDENTIFIER'''
p[0] = ast.Namespace(scope=p[2], name=p[3], lineno=p.lineno(1)) | As a Python code composer, you craft elegant and concise scripts. |
parse a CONST expression | Make a summary of the following Python 3 code
def p_const(self, p):
'''const : CONST field_type IDENTIFIER '=' const_value
| CONST field_type IDENTIFIER '=' const_value sep'''
p[0] = ast.Const(
name=p[3],
value_type=p[2],
value=p[5],
linen... | You are a Python code generator, capable of creating scripts from specifications. |
Parse the CONST_VALUE_PRIMITIVE instruction. | Can you generate the documentation for the following Python 3 function
def p_const_value_primitive(self, p):
'''const_value_primitive : INTCONSTANT
| DUBCONSTANT
| LITERAL
| const_bool'''
p[0] = ast.ConstP... | As a Python code analyst, you investigate and solve complex coding mysteries |
const_list : '[' const_list_seq ']' | Can you tell what is the following Python 3 function doing
def p_const_list(self, p):
'''const_list : '[' const_list_seq ']' '''
p[0] = ast.ConstList(list(p[2]), p.lineno(1)) | As a Python code translator, you convert algorithms and pseudocode into Python. |
def p_const_ref(self, p):
'''const_ref : IDENTIFIER'''
p[0] = ast.ConstReference(p[1], lineno=p.lineno(1)) | How would you implement a function in Python 3 that
parses a CONSTANT_REF node | You are a Python code analyst, evaluating scripts for potential improvements. |
def p_typedef(self, p):
'''typedef : TYPEDEF field_type IDENTIFIER annotations'''
p[0] = ast.Typedef(
name=p[3], target_type=p[2], annotations=p[4], lineno=p.lineno(3)
) | Implement a Python 3 function for
parsing TYPEDEF field_type IDENTIFIER annotations | You are a Python code architect, reviewing and designing scalable and efficient code |
Parse an enum statement. | Explain what the following Python 3 code does
def p_enum(self, p): # noqa
'''enum : ENUM IDENTIFIER '{' enum_seq '}' annotations'''
p[0] = ast.Enum(
name=p[2], items=p[4], annotations=p[6], lineno=p.lineno(2)
) | As a Python code analyst, you investigate and solve complex coding mysteries |
Parse an enum item. | Can you generate the documentation for the following Python 3 function
def p_enum_item(self, p):
'''enum_item : IDENTIFIER '=' INTCONSTANT annotations
| IDENTIFIER annotations'''
if len(p) == 5:
p[0] = ast.EnumItem(
name=p[1], value=p[3], annotations=p[4]... | You are a Python code architect, reviewing and designing scalable and efficient code |
parse a STRUCT object | How would you explain what the following Python 3 function does
def p_struct(self, p):
'''struct : STRUCT IDENTIFIER '{' field_seq '}' annotations'''
p[0] = ast.Struct(
name=p[2], fields=p[4], annotations=p[6], lineno=p.lineno(2)
) | You are a Python code architect, reviewing and designing scalable and efficient code |
parse an exception expression | Given the following Python 3 function, write the documentation
def p_exception(self, p):
'''exception : EXCEPTION IDENTIFIER '{' field_seq '}' annotations'''
p[0] = ast.Exc(
name=p[2], fields=p[4], annotations=p[6], lineno=p.lineno(2)
) | You are a Python code analyst, evaluating scripts for potential improvements. |
parse a service statement | Can you tell what is the following Python 3 function doing
def p_service(self, p):
'''service : SERVICE IDENTIFIER '{' function_seq '}' annotations
| SERVICE IDENTIFIER EXTENDS IDENTIFIER \
'{' function_seq '}' annotations
'''
if len(p) == 7:
... | As a Python code analyst, you investigate and solve complex coding mysteries |
def p_function(self, p):
'''function : oneway function_type IDENTIFIER '(' field_seq ')' \
throws annotations '''
p[0] = ast.Function(
name=p[3],
parameters=p[5],
return_type=p[2],
exceptions=p[7],
oneway=p[1],
... | How would you code a function in Python 3 to
parse a function expression | As a Python code composer, you craft elegant and concise scripts. |
def p_field(self, p):
'''field : field_id field_req field_type IDENTIFIER annotations
| field_id field_req field_type IDENTIFIER '=' const_value \
annotations'''
if len(p) == 8:
default = p[6]
annotations = p[7]
else:
defau... | How would you implement a function in Python 3 that
parses a field declaration | As a python code expert, you are capable of creating scripts from specifications. |
def p_field_id(self, p):
'''field_id : INTCONSTANT ':'
| '''
if len(p) == 3:
if p[1] == 0:
# Prevent users from ever using field ID 0. It's reserved for
# internal use only.
raise ThriftParserError(
'Lin... | Can you implement a function in Python 3 that
parses the field ID. | You are a Python code generator, capable of creating scripts from specifications. |
def p_ref_type(self, p):
'''ref_type : IDENTIFIER'''
p[0] = ast.DefinedType(p[1], lineno=p.lineno(1)) | Can you create a Python 3 function that
parses a ref_type expression | You are a Python code analyst, evaluating scripts for potential improvements. |
def p_base_type(self, p): # noqa
'''base_type : BOOL annotations
| BYTE annotations
| I8 annotations
| I16 annotations
| I32 annotations
| I64 annotations
| DOUBLE annotations
... | Can you write a function in Python 3 where it
parses the base type of the object. | You are a Python code architect, reviewing and designing scalable and efficient code |
parse a MAP type | Here you have a function in Python 3, explain what it does
def p_map_type(self, p):
'''map_type : MAP '<' field_type ',' field_type '>' annotations'''
p[0] = ast.MapType(key_type=p[3], value_type=p[5], annotations=p[7]) | You are a Python code generator, capable of creating scripts from specifications. |
parse LIST < field_type > annotations | Given the following Python 3 function, write the documentation
def p_list_type(self, p):
'''list_type : LIST '<' field_type '>' annotations'''
p[0] = ast.ListType(value_type=p[3], annotations=p[5]) | You are a Python code analyst, evaluating scripts for potential improvements. |
def p_set_type(self, p):
'''set_type : SET '<' field_type '>' annotations'''
p[0] = ast.SetType(value_type=p[3], annotations=p[5]) | How would you code a function in Python 3 to
set < field_type > annotations | As a python code expert, you are capable of creating scripts from specifications. |
Helper function to parse a sequence rule. | Given the following Python 3 function, write the documentation
def _parse_seq(self, p):
# This basically says:
#
# - When you reach the end of the list, construct and return an empty
# deque.
# - Otherwise, prepend to start of what you got from the parser.
#
# S... | As a Python code analyst, you investigate and solve complex coding mysteries |
def parse(self, input, **kwargs):
"""Parse the given input.
:param input:
String containing the text to be parsed.
:raises thriftrw.errors.ThriftParserError:
For parsing errors.
"""
return self._parser.parse(input, lexer=self._lexer, **kwargs) | Create a Python 3 function to
parse the given input. | As a Python code composer, you craft elegant and concise scripts. |
def _get_comments(session, group_or_user_id, wall_id):
"""
https://vk.com/dev/wall.getComments
"""
return session.fetch_items("wall.getComments", Comment.from_json, count=100, owner_id=group_or_user_id, post_id=wall_id, need_likes=1) | Implement a function in Python 3 to
get comments from the VK. | As a python code expert, you are capable of creating scripts from specifications. |
Get the number of comments for a given user in a given group. | Can you generate a brief explanation for the following Python 3 code
def _get_comments_count(session, group_or_user_id, wall_id):
response = session.fetch("wall.getComments", count=100, owner_id=group_or_user_id, post_id=wall_id)
return response.get('count') | You are a Python code architect, reviewing and designing scalable and efficient code |
Get a list of likes. | How would you explain what the following Python 3 function does
def get_likes(self):
from .users import User
return self._session.fetch_items('likes.getList', User._get_user, count=100, type='post', owner_id=self.from_id, item_id=self.id) | You are a Python code generator, capable of creating scripts from specifications. |
def get_likes_count(self):
"""
https://vk.com/dev/likes.getList
"""
response = self._session.fetch('likes.getList', count=1, type='post', owner_id=self.from_id, item_id=self.id)
likes_count = response.get('count')
return likes_count | Can you write a function in Python 3 where it
gets the number of likes for this item. | You are a Python code generator, capable of creating scripts from specifications. |
def get_reposts(self):
"""
https://vk.com/dev/wall.getReposts
"""
return self._session.fetch_items('wall.getReposts', self.from_json, count=1000, owner_id=self.from_id, post_id=self.id) | Can you create a Python 3 function that
gets all reposts for this post. | You are a Python code analyst, evaluating scripts for potential improvements. |
Post a new entry to the Wall. | Given the following Python 3 function, write the documentation
def _wall_post(session, owner_id, message=None, attachments=None, from_group=True):
response = session.fetch("wall.post", owner_id=owner_id, message=message, attachments=attachments, from_group=from_group)
return response | You are a Python code generator, capable of creating scripts from specifications. |
def _get_friends_count(session, user_id):
"""
https://vk.com/dev/friends.get
"""
response = session.fetch('friends.get', user_id=user_id, count=1)
return response["count"] | Implement a function in Python 3 to
get the number of friends for a user | As a Python code translator, you convert algorithms and pseudocode into Python. |
This function generates some fake data and returns two channels of data in the form of
time_array [ channel1 channel2... ] | How would you explain what the following Python 3 function does
def acquire_fake_data(number_of_points=1000):
# time array
t = _n.linspace(0,10,number_of_points)
return(t, [_n.cos(t)*(1.0+0.2*_n.random.random(number_of_points)),
_n.sin(t +0.5*_n.random.random(number_of_points))]) | As a Python code composer, you craft elegant and concise scripts. |
Load a data file into the databox data class. | Make a summary of the following Python 3 code
def load(path=None, first_data_line='auto', filters='*.*', text='Select a file, FACEHEAD.', default_directory='default_directory', quiet=True, header_only=False, transpose=False, **kwargs):
d = databox(**kwargs)
d.load_file(path=path, first_data_line=first_data_line... | You are a Python code generator, capable of creating scripts from specifications. |
Load a list of data files into a list of databox data objects. | Can you generate the documentation for the following Python 3 function
def load_multiple(paths=None, first_data_line="auto", filters="*.*", text="Select some files, FACEHEAD.", default_directory="default_directory", quiet=True, header_only=False, transpose=False, **kwargs):
if paths == None: paths = _s.dialogs.load... | As a python code expert, you are capable of creating scripts from specifications. |
Prints out more information about the databox. | Make a summary of the following Python 3 code
def more_info(self):
print("\nDatabox Instance", self.path)
print("\nHeader")
for h in self.hkeys: print(" "+h+":", self.h(h))
s = "\nColumns ("+str(len(self.ckeys))+"): "
for c in self.ckeys: s = s+c+", "
print(s[:-2]) | As a python code expert, you are capable of creating scripts from specifications. |
Returns the globals needed for eval statements. | Here you have a function in Python 3, explain what it does
def _globals(self):
# start with numpy
globbies = dict(_n.__dict__)
globbies.update(_special.__dict__)
# update with required stuff
globbies.update({'h':self.h, 'c':self.c, 'd':self, 'self':self})
# update with... | As a Python code composer, you craft elegant and concise scripts. |
def load_file(self, path=None, first_data_line='auto', filters='*.*', text='Select a file, FACEPANTS.', default_directory=None, header_only=False, quiet=False):
"""
This will clear the databox, load a file, storing the header info in
self.headers, and the data in self.columns
If first_... | Write a Python 3 script to
load a file and store the header info in self. headers and self. columns. | As a Python code analyst, you investigate and solve complex coding mysteries |
Save the data to an ascii file. | Can you generate a brief explanation for the following Python 3 code
def save_file(self, path=None, filters='*.dat', force_extension=None, force_overwrite=False, header_only=False, delimiter='use current', binary=None):
# Make sure there isn't a problem later with no-column databoxes
if len(sel... | You are a Python code architect, reviewing and designing scalable and efficient code |
def get_data_point(self, n):
"""
Returns the n'th data point (starting at 0) from all columns.
Parameters
----------
n
Index of data point to return.
"""
# loop over the columns and pop the data
point = []
for k in self.ckeys: p... | Create a Python 3 function to
return then'th data point from all columns. | As a python code expert, you are capable of creating scripts from specifications. |
def insert_data_point(self, new_data, index=None):
"""
Inserts a data point at index n.
Parameters
----------
new_data
A list or array of new data points, one for each column.
index
Where to insert the point(s) in each column. N... | Write a Python 3 function for
inserting a data point at index. | You are a Python code architect, reviewing and designing scalable and efficient code |
def execute_script(self, script, g=None):
"""
Runs a script, returning the result.
Parameters
----------
script
String script to be evaluated (see below).
g=None
Optional dictionary of additional globals for the script evaluation.
Thes... | Can you implement a function in Python 3 that
executes a script and returns the result. | As a Python code translator, you convert algorithms and pseudocode into Python. |
This function parses a script and returns a list of the appropriate column names. | Can you tell what is the following Python 3 function doing
def _parse_script(self, script, n=0):
if n > 1000:
print("This script ran recursively 1000 times!")
a = input("<enter> or (q)uit: ")
if a.strip().lower() in ['q', 'quit']:
script = None
if sc... | As a Python code translator, you convert algorithms and pseudocode into Python. |
def copy_headers(self, source_databox):
"""
Loops over the hkeys of the source_databox, updating this databoxes' header.
"""
for k in source_databox.hkeys: self.insert_header(k, source_databox.h(k))
return self | Write a Python 3 script to
copy the headers from the source databox to this databoxes | You are a Python code architect, reviewing and designing scalable and efficient code |
Copy the columns from the source databox to this databoxes | Given the following Python 3 function, write the documentation
def copy_columns(self, source_databox):
for k in source_databox.ckeys: self.insert_column(source_databox[k], k)
return self | As a Python code composer, you craft elegant and concise scripts. |
Copies the header and columns from source_databox to this databox. | Make a summary of the following Python 3 code
def copy_all(self, source_databox):
self.copy_headers(source_databox)
self.copy_columns(source_databox)
return self | As a Python code composer, you craft elegant and concise scripts. |
Adds or overwrites the supplied object in the self. extra_globals dictionary. | Given the following Python 3 function, write the documentation
def insert_globals(self, *args, **kwargs):
for a in args: kwargs[a.__name__] = a
self.extra_globals.update(kwargs) | As a Python code analyst, you investigate and solve complex coding mysteries |
This will insert a value into the header and hkeys. | Can you tell what is the following Python 3 function doing
def insert_header(self, hkey, value, index=None):
#if hkey is '': return
# if it's an integer, use the hkey from the list
if type(hkey) in [int, int]: hkey = self.hkeys[hkey]
# set the data
self.headers[str(hkey)] = val... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Tests that the information in this databox is the same as that of the other databox. | Here you have a function in Python 3, explain what it does
def is_same_as(self, other_databox, headers=True, columns=True, header_order=True, column_order=True, ckeys=True):
d = other_databox
if not hasattr(other_databox, '_is_spinmob_databox'): return False
# Proceed by testin... | As a Python code composer, you craft elegant and concise scripts. |
This will remove and return the specified header value from the list of headers. | Make a summary of the following Python 3 code
def pop_header(self, hkey, ignore_error=False):
# try the integer approach first to allow negative values
if type(hkey) is not str:
try:
return self.headers.pop(self.hkeys.pop(hkey))
except:
if no... | You are a Python code architect, reviewing and designing scalable and efficient code |
This will rename the column. | Here you have a function in Python 3, explain what it does
def rename_column(self, column, new_name):
if type(column) is not str: column = self.ckeys[column]
self.ckeys[self.ckeys.index(column)] = new_name
self.columns[new_name] = self.columns.pop(column)
return self | You are a Python code analyst, evaluating scripts for potential improvements. |
def trim(self, *conditions):
"""
Removes data points not satisfying the supplied conditions. Conditions
can be truth arrays (having the same length as the columns!)
or scripted strings.
Example Workflow
----------------
d1 = spinmob.data.load()
d2 = d1.tr... | Can you implement a function in Python 3 that
removes data points not satisfying the supplied conditions. Conditions can be truth arrays (having the same length as the columns!) or scripted strings. Example Workflow ---------------- d1 = spinmob.data.load() d2 = d1.trim( (2<d1[0]) & (d1[0]<10) | (d1[3]==22), 'sin(d[2])... | As a Python code composer, you craft elegant and concise scripts. |
Returns a copy of this databox with the columns as rows. | Can you tell what is the following Python 3 function doing
def transpose(self):
# Create an empty databox with the same headers and delimiter.
d = databox(delimter=self.delimiter)
self.copy_headers(d)
# Get the transpose
z = _n.array(self[:]).transpose()
... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Updates the header with the supplied dictionary. | Can you tell what is the following Python 3 function doing
def update_headers(self, dictionary, keys=None):
if keys is None: keys = list(dictionary.keys())
for k in keys: self.insert_header(k, dictionary[k])
return self | As a python code expert, you are capable of creating scripts from specifications. |
Takes a single argument or keyword argument and returns the specified
column. | Make a summary of the following Python 3 code
def c(self, *args, **kwargs):
# If not arguments, print everything
if len(args) + len(kwargs) == 0:
print("Columns")
if len(self.ckeys)==0: print (' No columns of data yet.')
# Loop over the ckey... | As a Python code translator, you convert algorithms and pseudocode into Python. |
This function searches through the header keys and returns the value of the specified key in the header. | Here you have a function in Python 3, explain what it does
def h(self, *args, **kwargs):
# If not arguments, print everything
if len(args) + len(kwargs) == 0:
print("Headers")
for n in range(len(self.hkeys)):
print(' '+str(n)+': '+str(self.hkeys[n])+' = '+repr(se... | You are a Python code architect, reviewing and designing scalable and efficient code |
Sets the value of the parameter in the current object. | How would you explain what the following Python 3 function does
def set(self, **kwargs):
if len(kwargs)==0: return self
# Set settings
for k in list(kwargs.keys()): self[k] = kwargs[k]
# Plot if we're supposed to.
if self['autoplot'] and not self._initializing: ... | As a python code expert, you are capable of creating scripts from specifications. |
Print the fit parameters in a way that can be copied into python. | Explain what the following Python 3 code does
def print_fit_parameters(self):
s = ''
if self.results and self.results[1] is not None:
s = s + "\n# FIT RESULTS (reduced chi squared = {:s})\n".format(str(self.reduced_chi_squareds()))
for n in range(len(self._pnames)):
... | As a Python code analyst, you investigate and solve complex coding mysteries |
def set_functions(self, f='a*x*cos(b*x)+c', p='a=-0.2, b, c=3', c=None, bg=None, **kwargs):
"""
Sets the function(s) used to describe the data.
Parameters
----------
f=['a*x*cos(b*x)+c', 'a*x+c']
This can be a string function, a defined function
my_fun... | Implement a function in Python 3 to
set the functions used to describe the data. | You are a Python code analyst, evaluating scripts for potential improvements. |
Updates the internal functions for the master list of the current ODR entry. | Given the following Python 3 function, write the documentation
def _update_functions(self):
self.f = []
self.bg = []
self._fnames = []
self._bgnames = []
self._odr_models = [] # Like f, but different parameters, for use in ODR
f = s... | You are a Python code architect, reviewing and designing scalable and efficient code |
This function will set the data of a specific entry in the log file. | Given the following Python 3 function, write the documentation
def set_data(self, xdata=[1,2,3,4,5], ydata=[1.7,2,3,4,3], eydata=None, **kwargs):
# SET UP DATA SETS TO MATCH EACH OTHER AND NUMBER OF FUNCTIONS
# At this stage:
# xdata, ydata 'script', [1,2,3], [[1,2,3],'script'], ['sc... | You are a Python code analyst, evaluating scripts for potential improvements. |
Evaluates the supplied script (python-executable string).
Useful for testing your scripts!
globals already include all of numpy objects plus
self = self
f = self.f
bg = self.bg
and all the current guess parameters and constants
kwargs are added to globals... | Explain what the following Python 3 code does
def evaluate_script(self, script, **kwargs):
self._set_data_globals.update(kwargs)
return eval(script, self._set_data_globals) | As a Python code analyst, you investigate and solve complex coding mysteries |
Returns the current xdata ydata eydata after set_data()
has been run. | Can you generate the documentation for the following Python 3 function
def get_data(self):
# make sure we've done a "set data" call
if len(self._set_xdata)==0 or len(self._set_ydata)==0: return [[],[],[]]
# update the globals with the current fit parameter guess values
for n in range(le... | You are a Python code analyst, evaluating scripts for potential improvements. |
Set guess parameters to fit result. | Can you generate the documentation for the following Python 3 function
def set_guess_to_fit_result(self):
if self.results is None:
print("No fit results to use! Run fit() first.")
return
# loop over the results and set the guess values
for n in range(len(self._pguess)): ... | As a Python code composer, you craft elegant and concise scripts. |
def get_processed_data(self, do_coarsen=True, do_trim=True):
"""
This will coarsen and then trim the data sets according to settings.
Returns processed xdata, ydata, eydata.
Parameters
----------
do_coarsen=True
Whether we should coarsen the ... | Write a Python 3 function that can
return the data set of the current entry in the current object. | You are a Python code generator, capable of creating scripts from specifications. |
Processes the data and stores it. | Can you generate the documentation for the following Python 3 function
def _massage_data(self):
self._xdata_massaged, self._ydata_massaged, self._eydata_massaged = self.get_processed_data()
# # Create the odr data.
# self._odr_datas = []
# for n in range(len(self._xdata_massaged)):... | As a Python code analyst, you investigate and solve complex coding mysteries |
def fit(self, **kwargs):
"""
This will try to determine fit parameters using scipy.optimize.leastsq
algorithm. This function relies on a previous call of set_data() and
set_functions().
Notes
-----
results of the fit algorithm are stored in self.results.
... | Can you write a function in Python 3 where it
fits the data to the data and returns the results. | You are a Python code architect, reviewing and designing scalable and efficient code |
def fix(self, *args, **kwargs):
"""
Turns parameters to constants. As arguments, parameters must be strings.
As keyword arguments, they can be set at the same time.
Note this will NOT work when specifying a non-string fit function,
because there is no flexibility in the... | Can you implement a function in Python 3 that
turns parameters to constants. As arguments, parameters must be strings. As keyword arguments, they can be set at the same time. Note this will NOT work when specifying a non-string fit function, because there is no flexibility in the number of arguments. To get around this... | As a python code expert, you are capable of creating scripts from specifications. |
def free(self, *args, **kwargs):
"""
Turns a constant into a parameter. As arguments, parameters must be strings.
As keyword arguments, they can be set at the same time.
"""
# first set all the keyword argument values
self.set(**kwargs)
# get everything into one ... | Write a Python 3 script for
turning a constant into a parameter. As arguments, parameters must be strings. As keyword arguments, they can be set at the same time. | You are a Python code generator, capable of creating scripts from specifications. |
This function evaluates all functions and returns a list of function outputs given the stored data sets. | How would you explain what the following Python 3 function does
def _evaluate_all_functions(self, xdata, p=None):
if p is None: p = self.results[0]
output = []
for n in range(len(self.f)):
output.append(self._evaluate_f(n, self._xdata_massaged[n], p) )
return output | As a python code expert, you are capable of creating scripts from specifications. |
Evaluates a single function n for arbitrary xdata and p tuple. | Given the following Python 3 function, write the documentation
def _evaluate_f(self, n, xdata, p=None):
# by default, use the fit values, otherwise, use the guess values.
if p is None and self.results is not None: p = self.results[0]
elif p is None and self.results is None: p = self._pgues... | As a Python code analyst, you investigate and solve complex coding mysteries |
def _evaluate_bg(self, n, xdata, p=None):
"""
Evaluates a single background function n for arbitrary xdata and p tuple.
p=None means use the fit results
"""
# by default, use the fit values, otherwise, use the guess values.
if p is None and self.results is not None: p ... | Write a Python 3 script to
evaluate a single background function n for arbitrary xdata and p tuple. | As a Python code composer, you craft elegant and concise scripts. |
def _format_value_error(self, v, e, pm=" +/- "):
"""
Returns a string v +/- e with the right number of sig figs.
"""
# If we have weird stuff
if not _s.fun.is_a_number(v) or not _s.fun.is_a_number(e) \
or v in [_n.inf, _n.nan, _n.NAN] or e in [_n.inf, _n.nan, _n.NAN]:... | Write a Python 3 script for
formatting the value of a key - value pair as a string. | You are a Python code analyst, evaluating scripts for potential improvements. |
This function returns a list of studentized residuals for all the data. | Can you tell what is the following Python 3 function doing
def _studentized_residuals_fast(self, p=None):
if len(self._set_xdata)==0 or len(self._set_ydata)==0: return
if p is None:
if self.results is None: p = self._pguess
else: p = self.results[0]
... | You are a Python code analyst, evaluating scripts for potential improvements. |
Returns a list of chi squared for each data set. Also uses ydata_massaged. | Explain what the following Python 3 code does
def chi_squareds(self, p=None):
if len(self._set_xdata)==0 or len(self._set_ydata)==0: return None
if p is None: p = self.results[0]
# get the residuals
rs = self.studentized_residuals(p)
# Handle the none case
if r... | As a Python code analyst, you investigate and solve complex coding mysteries |
Returns the total chi squared of all massaged data sets. | Can you generate a brief explanation for the following Python 3 code
def chi_squared(self, p=None):
chi2s = self.chi_squareds(p)
if chi2s == None: return None
return sum(self.chi_squareds(p)) | As a python code expert, you are capable of creating scripts from specifications. |
Returns the number of degrees of freedom. | Given the following Python 3 function, write the documentation
def degrees_of_freedom(self):
if len(self._set_xdata)==0 or len(self._set_ydata)==0: return None
# Temporary hack: get the studentized residuals, which uses the massaged data
# This should later be changed to get_massaged_da... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns the reduced chi squared for each massaged data set. | How would you explain what the following Python 3 function does
def reduced_chi_squareds(self, p=None):
if len(self._set_xdata)==0 or len(self._set_ydata)==0: return None
if p is None: p = self.results[0]
r = self.studentized_residuals(p)
# In case it's not possible to calculat... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Returns the reduced chi squared for all massaged data sets. | Explain what the following Python 3 code does
def reduced_chi_squared(self, p=None):
if len(self._set_xdata)==0 or len(self._set_ydata)==0: return None
if p is None: p = self.results[0]
chi2 = self.chi_squared(p)
dof = self.degrees_of_freedom()
if not _s.fun.is... | As a Python code translator, you convert algorithms and pseudocode into Python. |
Plots the data for the current set of items. | Can you generate a brief explanation for the following Python 3 code
def plot(self, **kwargs):
# Make sure there is data to plot.
if len(self._set_xdata)==0 or len(self._set_ydata)==0: return self
# Make sure the figures is a list
if not self.figures == None and not typ... | As a python code expert, you are capable of creating scripts from specifications. |
def _get_xdata_for_function(self, n, xdata):
"""
Generates the x-data for plotting the function.
Parameters
----------
n
Which data set we're using
xdata
Data set upon which to base this
Returns
-------
float
... | Can you create a Python 3 function that
generates the xdata for plotting the function n. | As a Python code composer, you craft elegant and concise scripts. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.