-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #407
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ def compute_segments(line): | |
if len(data) != 4: | ||
print("### error: can only plot 2D data", file=sys.stderr) | ||
sys.exit(1) | ||
center = data[0:2] | ||
center = data[:2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
extent = data[2:4] | ||
ur = (center[0] + extent[0], center[1] + extent[1]) | ||
ul = (center[0] - extent[0], center[1] + extent[1]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,10 @@ | |
for line in file: | ||
match = re.match(r'^time: ([^s]+)\s+s$', line) | ||
if match is not None: | ||
time_avg = float(match.group(1)) | ||
time_avg = float(match[1]) | ||
nr_timings += 1 | ||
continue | ||
match = re.match('^procs: (\d+)$', line) | ||
if match is not None: | ||
nr_procs = int(match.group(1)) | ||
nr_procs = int(match[1]) | ||
Comment on lines
-20
to
+25
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
print('{0:d} {1:.6f}'.format(nr_procs, time_avg/nr_timings)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,10 +17,7 @@ | |
arg_parser.add_argument('-v', dest='version', choices=['3', '4'], | ||
default='3', help='NetCDF version to create') | ||
options = arg_parser.parse_args() | ||
if options.version == '3': | ||
version = 'NETCDF3_CLASSIC' | ||
else: | ||
version = 'NETCDF4' | ||
version = 'NETCDF3_CLASSIC' if options.version == '3' else 'NETCDF4' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
rootgrp = Dataset(options.file, 'w', format='NETCDF3_CLASSIC') | ||
x_dim = rootgrp.createDimension('x', options.x) | ||
y_dim = rootgrp.createDimension('y', options.y) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,7 @@ def available_nucl(nucl_left): | |
|
||
def get_nucl(nucl_left): | ||
while True: | ||
avail_nucls = available_nucl(nucl_left) | ||
if avail_nucls: | ||
if avail_nucls := available_nucl(nucl_left): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
nucl = random.choice(avail_nucls) | ||
nucl_left[nucl] -= 1 | ||
yield nucl | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,8 @@ def compute_y(x, radius): | |
[0.0, 0.0, 2.0, 1.0, compute_y(1.0, 2.0)], | ||
] | ||
|
||
cmd = './on_circle_c.exe' | ||
for case in cases: | ||
cmd = './on_circle_c.exe' | ||
Comment on lines
+16
to
-17
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
args = ['{0:.15f}'.format(x) for x in case] | ||
print(cmd, ' '.join(args)) | ||
output = check_output([cmd, *args]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,9 +17,10 @@ | |
arg_parser.add_argument('--show', action='store_true', | ||
help='show MUSCLE output') | ||
options = arg_parser.parse_args() | ||
seqs = {} | ||
for seq_record in SeqIO.parse(options.file, options.format): | ||
seqs[seq_record.id] = seq_record.seq | ||
seqs = { | ||
seq_record.id: seq_record.seq | ||
for seq_record in SeqIO.parse(options.file, options.format) | ||
} | ||
Comment on lines
-20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
if options.alignment: | ||
with open(options.alignment, 'r') as alignment_file: | ||
stdout = alignment_file.read() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,8 @@ | |
record = Entrez.read(handle) | ||
db_info = record['DbInfo'] | ||
print(db_info['Description']) | ||
print('Count: {}'.format(db_info['Count'])) | ||
print('Last update: {}'.format(db_info['LastUpdate'])) | ||
print(f"Count: {db_info['Count']}") | ||
print(f"Last update: {db_info['LastUpdate']}") | ||
Comment on lines
-21
to
+22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
if options.fields: | ||
print('Fields:') | ||
fmt_str = '{Name} ({FullName}): {Description}' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,9 +23,10 @@ def compute_stats(seq): | |
arg_parser.add_argument('file', help='sequence file to parse') | ||
arg_parser.add_argument('--format', default='fasta', help='file format') | ||
options = arg_parser.parse_args() | ||
seqs = {} | ||
for seq_record in SeqIO.parse(options.file, options.format): | ||
seqs[seq_record.id] = seq_record.seq | ||
seqs = { | ||
seq_record.id: seq_record.seq | ||
for seq_record in SeqIO.parse(options.file, options.format) | ||
} | ||
Comment on lines
-26
to
+29
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
fmt_str = ('id: {id}\n\t' | ||
'length: {stats.length}\n\t' | ||
'gc: {stats.gc}\n\t' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,9 @@ | |
if options.summary: | ||
handle = Entrez.esummary(db='nucleotide', id=seq_id) | ||
summary = Entrez.read(handle) | ||
print('ID {}:'.format(seq_id)) | ||
print(' {}'.format(summary[0]['Title'])) | ||
print(' Updated: {}'.format(summary[0]['UpdateDate'])) | ||
print(f'ID {seq_id}:') | ||
print(f" {summary[0]['Title']}") | ||
print(f" Updated: {summary[0]['UpdateDate']}") | ||
Comment on lines
-29
to
+31
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
else: | ||
file_name = os.path.join('Data', '{0}.gbk'.format(seq_id)) | ||
if not os.path.isfile(file_name): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import textwrap | ||
|
||
def print_seq_record(seq_record, indent_with=' ', indent=''): | ||
print('Sequence ID: {}'.format(seq_record.id)) | ||
print(f'Sequence ID: {seq_record.id}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
indent += indent_with | ||
print('{0}Name: {1}'.format(indent, seq_record.name)) | ||
print('{0}Description: {1}'.format(indent, seq_record.description)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,9 +42,7 @@ def normalize(signal, ampl): | |
arg_parser.add_argument('--out', action='store_true', | ||
help='print signal to standard output') | ||
options = arg_parser.parse_args() | ||
if options.specs_file: | ||
pass | ||
else: | ||
if not options.specs_file: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
if len(options.freqs) != len(options.ampls): | ||
msg = '# error: {0:d} frequencies for {1:d} amplitudes\n' | ||
sys.stderr.write(msg.format(len(options.freqs), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,5 @@ | ||
def fac_r(n): | ||
if n < 2: | ||
return 1 | ||
else: | ||
return n*fac_r(n - 1) | ||
return 1 if n < 2 else n*fac_r(n - 1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def fac_i(n): | ||
result = 1 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
def fac(n): | ||
if n < 2: | ||
return 1 | ||
else: | ||
return n*fac(n-1) | ||
return 1 if n < 2 else n*fac(n-1) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,2 @@ | ||
def fib(n): | ||
if n == 0 or n == 1: | ||
return 1 | ||
else: | ||
return fib(n-1) + fib(n-2) | ||
return 1 if n in [0, 1] else fib(n-1) + fib(n-2) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,10 +4,7 @@ def fac(n): | |
'''compute the factorial of given number''' | ||
assert type(n) == int, 'argument must be integer' | ||
assert n >= 0, 'argument must be positive' | ||
if n > 1: | ||
return n*fac(n - 1) | ||
else: | ||
return 1 | ||
return n*fac(n - 1) if n > 1 else 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
if __name__ == '__main__': | ||
for i in range(5): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,11 +41,10 @@ def get_value(self, name): | |
WHERE name = ?''', (name, )) | ||
rows = cursor.fetchall() | ||
cursor.close() | ||
if not rows: | ||
msg = "constant '{0}' is undefined".format(name) | ||
raise UnknownConstantError(msg) | ||
else: | ||
if rows: | ||
return rows[0][0] | ||
msg = "constant '{0}' is undefined".format(name) | ||
raise UnknownConstantError(msg) | ||
Comment on lines
-44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def get_names(self): | ||
cursor = self._conn.cursor() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,5 @@ | |
options.resoure_specs)) | ||
print('resources: ' + ', '.join(specs)) | ||
if options.account: | ||
print('account: ' + options.account) | ||
print(f'account: {options.account}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
print('unparsed: ' + ', '.join(unparsed)) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
|
||
|
||
def parse_job_script(file_name): | ||
args = list() | ||
args = [] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
with open(file_name) as file: | ||
for line in file: | ||
if line.lstrip().startswith('#PBS '): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,10 +5,7 @@ | |
|
||
|
||
def main(): | ||
if len(sys.argv) > 1: | ||
cfg_file = sys.argv[1] | ||
else: | ||
cfg_file = 'defaults.conf' | ||
cfg_file = sys.argv[1] if len(sys.argv) > 1 else 'defaults.conf' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
cfg_parser = SafeConfigParser() | ||
cfg_parser.read(cfg_file) | ||
print('Sections:') | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,10 +37,9 @@ def main(): | |
print('in context {0}'.format(c2._context_nr)) | ||
with label('foo') as foo, label('bar') as bar: | ||
print(foo, bar) | ||
with ContextTest(1) as c1, ContextTest(2) as c2: | ||
with (ContextTest(1) as c1, ContextTest(2) as c2): | ||
print('in context {0}'.format(c1._context_nr)) | ||
raise Exception() | ||
print('in context {0}'.format(c2._context_nr)) | ||
Comment on lines
-40
to
-43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return 0 | ||
|
||
if __name__ == '__main__': | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,15 +26,12 @@ def process_line(line, mode=float): | |
if not line: | ||
return None | ||
items = [item.strip() for item in line.split(',')] | ||
if mode == float: | ||
return [float(item) for item in items] | ||
else: | ||
return items | ||
return [float(item) for item in items] if mode == float else items | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
if __name__ == '__main__': | ||
line = sys.stdin.readline() | ||
names = process_line(line, mode='text') | ||
averagers = [stats() for name in names] | ||
averagers = [stats() for _ in names] | ||
Comment on lines
-37
to
+34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
for averager in averagers: | ||
next(averager) | ||
for line in sys.stdin: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ def py_sum(a): | |
for func in [array_sum, np.sum, py_sum]: | ||
total = 0.0 | ||
start_time = timeit.default_timer() | ||
for iter_nr in range(options.iter): | ||
for _ in range(options.iter): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
total += func(a) | ||
total_time = timeit.default_timer() - start_time | ||
print('{0:s}: {1:.6f} s ({2})'.format(func.__name__, total_time, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,17 +4,16 @@ | |
def primes(kmax): | ||
p = array('i', [0]*1000) | ||
result = [] | ||
if kmax > 1000: | ||
kmax = 1000 | ||
kmax = min(kmax, 1000) | ||
k = 0 | ||
n = 2 | ||
while k < kmax: | ||
i = 0 | ||
while i < k and n % p[i] != 0: | ||
i = i + 1 | ||
i += 1 | ||
if i == k: | ||
p[k] = n | ||
k = k + 1 | ||
k += 1 | ||
Comment on lines
-7
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
result.append(n) | ||
n = n + 1 | ||
return result |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,8 +10,10 @@ | |
|
||
def write_file(args): | ||
file_name, rows, curr_time, delta_time, curr_vals, delta_val = args | ||
fieldnames = ['timestamp'] | ||
fieldnames.extend(['C{0:d}'.format(i + 1) for i in range(len(curr_vals))]) | ||
fieldnames = [ | ||
'timestamp', | ||
*['C{0:d}'.format(i + 1) for i in range(len(curr_vals))], | ||
] | ||
Comment on lines
-13
to
+16
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
with open(file_name, 'w', newline='') as csv_file: | ||
writer = csv.DictWriter(csv_file, fieldnames=fieldnames) | ||
writer.writeheader() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,7 +39,7 @@ def get_hostname(i): | |
if options.verbose: | ||
print('task placement:') | ||
print('\t' + '\n\t'.join(process_locations)) | ||
count = dict() | ||
count = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
||
for process_location in process_locations: | ||
_, _, hostname = process_location.split() | ||
if hostname not in count: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ def parse_config_line(meta_data, line): | |
meta_data[symbol] = demangle_name(name) | ||
|
||
def parse_config(vcd_file): | ||
meta_data = dict() | ||
meta_data = {} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
for line in vcd_file: | ||
line = line.strip() | ||
if line == '$end': | ||
|
@@ -37,16 +37,15 @@ def update_buffer(buffer, line, meta_data): | |
buffer[key] = value | ||
|
||
def init_data(meta_data): | ||
data = dict() | ||
data['time'] = list() | ||
data = {'time': []} | ||
for var in meta_data: | ||
data[meta_data[var]] = list() | ||
data[meta_data[var]] = [] | ||
Comment on lines
-40
to
+42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return data | ||
|
||
def parse_data(vcd_file, meta_data): | ||
data = init_data(meta_data) | ||
time_stamp = None | ||
buffer = dict() | ||
buffer = {} | ||
Comment on lines
-49
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
for line in vcd_file: | ||
line = line.strip() | ||
if line.startswith('#'): | ||
|
@@ -68,9 +67,7 @@ def write_vcd_data_structure(out_file, data, sep=' '): | |
columns = list(data.keys()) | ||
out_file.write(sep.join(columns) + '\n') | ||
for time_step in range(len(data['time'])): | ||
data_line = list() | ||
for var in columns: | ||
data_line.append(data[var][time_step]) | ||
data_line = [data[var][time_step] for var in columns] | ||
Comment on lines
-71
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
out_file.write(sep.join(str(data_item) for data_item in data_line)) | ||
out_file.write('\n') | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,7 +106,7 @@ def _parse_data(self, agt_file): | |
if not match: | ||
msg = "line {0:d}: invalid number of measurements '{1}'" | ||
raise AgtDataError(msg.format(self._current_line, nr_lines_str)) | ||
nr_lines = int(match.group(1)) | ||
nr_lines = int(match[1]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
self._current_line += 1 | ||
# ignore header line | ||
agt_file.readline() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,11 +47,10 @@ def __iter__(self): | |
return self | ||
|
||
def __next__(self): | ||
if self._current < self.n: | ||
self._current += 1 | ||
return self._distr(*self._params) | ||
else: | ||
if self._current >= self.n: | ||
raise StopIteration() | ||
self._current += 1 | ||
return self._distr(*self._params) | ||
Comment on lines
-50
to
+53
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
class DistributionCreator(object): | ||
|
@@ -108,9 +107,9 @@ def __init__(self, file_name, table_name, col_defs): | |
self._row = self._table.row | ||
|
||
def _create_table(self, table_name, col_defs): | ||
description = {} | ||
for col_def in col_defs: | ||
description[col_def['name']] = self._typemap[col_def['type']] | ||
description = { | ||
col_def['name']: self._typemap[col_def['type']] for col_def in col_defs | ||
} | ||
Comment on lines
-111
to
+112
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
return self._file.create_table('/', table_name, description) | ||
|
||
def set_headers(self, headers): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ def main(): | |
print('{name} --- {weight}'.format(name=row['name'], | ||
weight=row['weight'])) | ||
sum += float(row['weight']) | ||
print('sum = {}'.format(sum)) | ||
print(f'sum = {sum}') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
if __name__ == '__main__': | ||
main() |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,10 +13,8 @@ def read_array(data_file, length): | |
arg_parser.add_argument('file', help='binary file to read') | ||
options = arg_parser.parse_args() | ||
with open(options.file, 'rb') as data_file: | ||
buffer = data_file.read(4); | ||
while buffer: | ||
while buffer := data_file.read(4): | ||
length = unpack('I', buffer)[0] | ||
values = read_array(data_file, length) | ||
value_str = ' '.join(f'{x:.2f}' for x in values) | ||
print(f'{length:d}: {value_str:s}') | ||
buffer = data_file.read(4) | ||
Comment on lines
-16
to
-22
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lines
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
train
refactored with the following changes:replace-interpolation-with-fstring
)