Skip to content

Commit

Permalink
Merge pull request #21 from syngenta/ci/add-pyupgrade
Browse files Browse the repository at this point in the history
ci: add pyupgrade to pre-commit
  • Loading branch information
oleksii-leonov authored Mar 23, 2023
2 parents 64d02a4 + 42529f6 commit f43ddf1
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 7 deletions.
6 changes: 6 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,9 @@ repos:
hooks:
- id: isort
files: '^src/.*\.pyi?$'
- repo: https://github.com/asottile/pyupgrade
rev: v3.3.1
hooks:
- id: pyupgrade
args: [--py38-plus, --keep-runtime-typing]
files: '.*\.pyi?$'
4 changes: 2 additions & 2 deletions src/linchemin/IO/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def write_json(data, file_path: Union[Path, str], indent=4, overwrite=True):

def read_json(file_path: Union[Path, str]):
file_path = get_file_path(file_path, 'r')
with open(file_path, 'r') as f:
with open(file_path) as f:
data = json.load(f)
return data

Expand All @@ -46,7 +46,7 @@ def dict_list_to_csv(data: List[dict], file_path: Union[Path, str], delimiter: s

def csv_to_dict_list(file_path: Union[Path, str], delimiter: str = ','):
file_path = get_file_path(file_path=file_path, mode='r')
with open(file_path, 'r') as file:
with open(file_path) as file:
content = csv.DictReader(file, delimiter=delimiter)
return [dict(row) for row in content]

Expand Down
2 changes: 1 addition & 1 deletion src/linchemin/cgu/discgraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,5 +72,5 @@ def __str__(self):
if connections:
text = text + '{} -> {} \n'.format(r, *connections)
else:
text = text + '{}\n'.format(r)
text = text + f'{r}\n'
return text
2 changes: 1 addition & 1 deletion src/linchemin/cgu/syngraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def __str__(self):
if connections:
text = text + '{} -> {} \n'.format(r, *connections)
else:
text = text + '{}\n'.format(r)
text = text + f'{r}\n'
return text

def add_node(self, nodes_tup: tuple):
Expand Down
2 changes: 1 addition & 1 deletion src/linchemin/configuration/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def create(self):
if not file.exists():
write = True
else:
with open(file, 'r') as stream:
with open(file) as stream:
content_old = yaml.load(stream, Loader=yaml.Loader)
message = f'\nThe {name} file was found in {file} \n' \
f' current file content: {content_old}\n' \
Expand Down
4 changes: 2 additions & 2 deletions src/linchemin/rem/clustering.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def get_clustering(self, dist_matrix, save_dist_matrix, **kwargs):
logger.error('Hdbscan found only noise. This can occur if less than 15 routes were given')
raise OnlyNoiseClustering
s_score = compute_silhouette_score(dist_matrix, clustering.labels_)
print('The Silhouette score is {:.3f}'.format(round(s_score, 3)))
print(f'The Silhouette score is {round(s_score, 3):.3f}')
return (clustering, s_score, dist_matrix) if save_dist_matrix is True else (clustering, s_score)


Expand All @@ -101,7 +101,7 @@ def get_clustering(self, dist_matrix, save_dist_matrix, **kwargs):
raise OnlyNoiseClustering
print(f'The number of clusters with the best Silhouette score is {best_n_cluster}')

print('The Silhouette score is {:.3f}'.format(round(s_score, 3)))
print(f'The Silhouette score is {round(s_score, 3):.3f}')
return (clustering, s_score, dist_matrix) if save_dist_matrix is True else (clustering, s_score)


Expand Down

0 comments on commit f43ddf1

Please sign in to comment.