text stringlengths 0 828 |
|---|
assert type(df) is pd.DataFrame |
# Diagnose problems with the data formats that can be addressed in cleaning |
# Get initial display settings |
initial_max_cols = pd.get_option('display.max_columns') |
initial_max_rows = pd.get_option('display.max_rows') |
initial_width = pd.get_option('display.width') |
# Reformat displays |
pd.set_option('display.max_columns', display_max_cols) |
pd.set_option('display.max_rows',None) |
if display_width is not None: |
pd.set_option('display.width',display_width) |
# --------Values of data----------- |
df_preview = _io.preview(df,preview_rows) |
df_info = _io.get_info(df,verbose = True, max_cols = display_max_cols, |
memory_usage = 'deep',null_counts = True) |
dtypes = stats.dtypes_summary(df).apply(_io.format_row,args = [_utils.rows(df)],axis = 1) |
potential_outliers = stats.df_outliers(df).dropna(axis = 1,how = 'all') |
potential_outliers = potential_outliers if _utils.rows(potential_outliers) \ |
else None |
# ----------Build lists------------ |
title_list = \ |
['Preview','Info', |
'Data Types Summary','Potential Outliers'] |
info_list = \ |
[df_preview,df_info, |
dtypes,potential_outliers] |
error_list = [None,None, |
None,'No potential outliers.'] |
# ----------Build output------------ |
output = '' |
for title, value,error_text in zip(title_list,info_list,error_list): |
if value is None: |
value = ""{} skipped: {}"".format(title,error_text) |
if str(value).endswith('\n'): |
value = value[:-1] |
output+='{}\n{}\n\n'.format(_io.title_line(title),value) |
# ----------Send to file/print to console------------ |
# Potentially could change this to allow for output_safe to work with directories |
print(output) |
# Reset display settings |
pd.set_option('display.max_columns', initial_max_cols) |
pd.set_option('display.max_rows', initial_max_rows) |
pd.set_option('display.width', initial_width)" |
4180,"def cut_spectrum(sp, l0, lf): |
"""""" |
Cuts spectrum given a wavelength interval, leaving origina intact |
Args: |
sp: Spectrum instance |
l0: initial wavelength |
lf: final wavelength |
Returns: |
Spectrum: cut spectrum |
"""""" |
if l0 >= lf: |
raise ValueError(""l0 must be lower than lf"") |
idx0 = np.argmin(np.abs(sp.x - l0)) |
idx1 = np.argmin(np.abs(sp.x - lf)) |
out = copy.deepcopy(sp) |
out.x = out.x[idx0:idx1] |
out.y = out.y[idx0:idx1] |
return out" |
4181,"def remove_nongenerating_nonterminals(grammar, inplace=False): |
# type: (Grammar, bool) -> Grammar |
"""""" |
Remove nongenerating symbols from the grammar. |
Nongenerating symbols are symbols, that don't generate sequence of terminals. |
For example never ending recursion. |
:param grammar: Grammar where to remove nongenerating symbols. |
:param inplace: True if transformation should be performed in place. False by default. |
:return: Grammar without nongenerating symbols. |
"""""" |
# copy if required |
if inplace is False: |
grammar = copy(grammar) |
# create working sets |
generates = grammar.terminals.copy() |
generates.add(EPSILON) |
rules = grammar.rules.copy() |
# iterate until the set doesn't change |
while True: |
# create set for the next iteration |
additional = generates.copy() |
# iterate over unprocessed rules |
for rule in rules.copy(): |
rightPart = rule.right |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.