text
stringlengths 0
828
|
|---|
return markdown.Markdown(extensions=extensions)"
|
704,"def setup_formats(self):
|
""""""
|
Inspects its methods to see what it can convert from and to
|
""""""
|
methods = self.get_methods()
|
for m in methods:
|
#Methods named ""from_X"" will be assumed to convert from format X to the common format
|
if m.startswith(""from_""):
|
self.input_formats.append(re.sub(""from_"" , """",m))
|
#Methods named ""to_X"" will be assumed to convert from the common format to X
|
elif m.startswith(""to_""):
|
self.output_formats.append(re.sub(""to_"","""",m))"
|
705,"def read_input(self, input_data, data_format):
|
""""""
|
Reads the input data and converts to common format
|
input_data - the output from one of the input classes (ie CSVInput)
|
data_format - the format of the data. See utils.input.dataformats
|
""""""
|
if data_format not in self.input_formats:
|
raise Exception(""Input format {0} not available with this class. Available formats are {1}."".format(data_format, self.input_formats))
|
data_converter = getattr(self, ""from_"" + data_format)
|
self.data = data_converter(input_data)"
|
706,"def get_data(self, data_format):
|
""""""
|
Reads the common format and converts to output data
|
data_format - the format of the output data. See utils.input.dataformats
|
""""""
|
if data_format not in self.output_formats:
|
raise Exception(""Output format {0} not available with this class. Available formats are {1}."".format(data_format, self.output_formats))
|
data_converter = getattr(self, ""to_"" + data_format)
|
return data_converter()"
|
707,"def from_csv(self, input_data):
|
""""""
|
Reads csv format input data and converts to json.
|
""""""
|
reformatted_data = []
|
for (i,row) in enumerate(input_data):
|
if i==0:
|
headers = row
|
else:
|
data_row = {}
|
for (j,h) in enumerate(headers):
|
data_row.update({h : row[j]})
|
reformatted_data.append(data_row)
|
return reformatted_data"
|
708,"def to_dataframe(self):
|
""""""
|
Reads the common format self.data and writes out to a dataframe.
|
""""""
|
keys = self.data[0].keys()
|
column_list =[]
|
for k in keys:
|
key_list = []
|
for i in xrange(0,len(self.data)):
|
key_list.append(self.data[i][k])
|
column_list.append(key_list)
|
df = DataFrame(np.asarray(column_list).transpose(), columns=keys)
|
for i in xrange(0,df.shape[1]):
|
if is_number(df.iloc[:,i]):
|
df.iloc[:,i] = df.iloc[:,i].astype(float)
|
return df"
|
709,"def check_extensions(extensions: Set[str], allow_multifile: bool = False):
|
""""""
|
Utility method to check that all extensions in the provided set are valid
|
:param extensions:
|
:param allow_multifile:
|
:return:
|
""""""
|
check_var(extensions, var_types=set, var_name='extensions')
|
# -- check them one by one
|
for ext in extensions:
|
check_extension(ext, allow_multifile=allow_multifile)"
|
710,"def check_extension(extension: str, allow_multifile: bool = False):
|
""""""
|
Utility method to check that the provided extension is valid. Extension should either be MULTIFILE_EXT
|
(='multifile') or start with EXT_SEPARATOR (='.') and contain only one occurence of EXT_SEPARATOR
|
:param extension:
|
:param allow_multifile:
|
:return:
|
""""""
|
check_var(extension, var_types=str, var_name='extension')
|
# Extension should either be 'multifile' or start with EXT_SEPARATOR and contain only one EXT_SEPARATOR
|
if (extension.startswith(EXT_SEPARATOR) and extension.count(EXT_SEPARATOR) == 1) \
|
or (allow_multifile and extension is MULTIFILE_EXT):
|
# ok
|
pass
|
else:
|
raise ValueError('\'extension\' should start with \'' + EXT_SEPARATOR + '\' and contain not other '
|
'occurrence of \'' + EXT_SEPARATOR + '\'' + (', or be equal to \'' + MULTIFILE_EXT + '\' (for '
|
'multifile object parsing)' if allow_multifile else ''))"
|
711,"def get_parsing_plan_log_str(obj_on_fs_to_parse, desired_type, log_only_last: bool, parser):
|
""""""
|
Utility method used by several classes to log a message indicating that a given file object is planned to be parsed
|
to the given object type with the given parser. It is in particular used in str(ParsingPlan), but not only.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.