Skip to content

Commit

Permalink
run pyupgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
rwood-97 committed Oct 27, 2023
1 parent b1626ed commit 50c6c03
Show file tree
Hide file tree
Showing 21 changed files with 441 additions and 475 deletions.
1 change: 0 additions & 1 deletion Contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,3 @@ You can request contact information through the project members above, or tag th
| Andy Smith<br>([@andrewphilipsmith](https://github.com/andrewphilipsmith)) | Research Data Scientist (Turing) | 2022 - 2023 |
| Daniel van Strien<br>([@davanstrien ](https://github.com/davanstrien)) | Data Librarian (British Library) | 2019-2021 |
| Olivia Vane<br>([@ov212 ](https://github.com/ov212)) | Research Software Engineer (British Library) | 2019-2021 |

15 changes: 7 additions & 8 deletions mapreader/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import re
import subprocess
import sys
from typing import Callable, Dict
from typing import Callable


def get_keywords():
Expand Down Expand Up @@ -55,8 +55,8 @@ class NotThisMethod(Exception):
"""Exception raised if a method is not valid for the current scenario."""


LONG_VERSION_PY: Dict[str, str] = {}
HANDLERS: Dict[str, Dict[str, Callable]] = {}
LONG_VERSION_PY: dict[str, str] = {}
HANDLERS: dict[str, dict[str, Callable]] = {}


def register_vcs_handler(vcs, method): # decorator
Expand Down Expand Up @@ -107,7 +107,7 @@ def run_command(commands, args, cwd=None, verbose=False, hide_stderr=False, env=
return None, None
else:
if verbose:
print("unable to find command, tried %s" % (commands,))
print(f"unable to find command, tried {commands}")
return None, None
stdout = process.communicate()[0].strip().decode()
if process.returncode != 0:
Expand Down Expand Up @@ -142,8 +142,7 @@ def versions_from_parentdir(parentdir_prefix, root, verbose):

if verbose:
print(
"Tried directories %s but none started with prefix %s"
% (str(rootdirs), parentdir_prefix)
"Tried directories {} but none started with prefix {}".format(str(rootdirs), parentdir_prefix)
)
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")

Expand All @@ -157,7 +156,7 @@ def git_get_keywords(versionfile_abs):
# _version.py.
keywords = {}
try:
with open(versionfile_abs, "r") as fobj:
with open(versionfile_abs) as fobj:
for line in fobj:
if line.strip().startswith("git_refnames ="):
mo = re.search(r'=\s*"(.*)"', line)
Expand Down Expand Up @@ -359,7 +358,7 @@ def git_pieces_from_vcs(tag_prefix, root, verbose, runner=run_command):
if verbose:
fmt = "tag '%s' doesn't start with prefix '%s'"
print(fmt % (full_tag, tag_prefix))
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
pieces["error"] = "tag '{}' doesn't start with prefix '{}'".format(
full_tag,
tag_prefix,
)
Expand Down
68 changes: 33 additions & 35 deletions mapreader/annotate/utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import annotations

import os
import random
import sys
from typing import Dict, List, Optional, Tuple, Union

import matplotlib.pyplot as plt
import numpy as np
Expand All @@ -30,7 +28,7 @@
from mapreader import load_patches, loader


def display_record(record: Tuple[str, str, str, int, int]) -> None:
def display_record(record: tuple[str, str, str, int, int]) -> None:
"""
Displays an image and optionally, a context image with a patch border.
Expand Down Expand Up @@ -175,13 +173,13 @@ def display_record(record: Tuple[str, str, str, int, int]) -> None:

def prepare_data(
df: pd.DataFrame,
col_names: Optional[List[str]] = None,
annotation_set: Optional[str] = "001",
label_col_name: Optional[str] = "label",
redo: Optional[bool] = False,
random_state: Optional[Union[int, str]] = "random",
num_samples: Optional[int] = 100,
) -> List[List[Union[str, int]]]:
col_names: list[str] | None = None,
annotation_set: str | None = "001",
label_col_name: str | None = "label",
redo: bool | None = False,
random_state: int | str | None = "random",
num_samples: int | None = 100,
) -> list[list[str | int]]:
"""
Prepare data for image annotation by selecting a subset of images from a
DataFrame.
Expand Down Expand Up @@ -265,12 +263,12 @@ def prepare_data(


def annotation_interface(
data: List,
list_labels: List,
list_colors: Optional[List[str]] = None,
annotation_set: Optional[str] = "001",
method: Optional[str] = "ipyannotate",
list_shortcuts: Optional[List[str]] = None,
data: list,
list_labels: list,
list_colors: list[str] | None = None,
annotation_set: str | None = "001",
method: str | None = "ipyannotate",
list_shortcuts: list[str] | None = None,
) -> Annotation:
"""
Create an annotation interface for a list of patches with corresponding
Expand Down Expand Up @@ -379,25 +377,25 @@ def prepare_annotation(
userID: str,
task: str,
annotation_tasks_file: str,
custom_labels: List[str] = None,
annotation_set: Optional[str] = "001",
redo_annotation: Optional[bool] = False,
patch_paths: Optional[Union[str, bool]] = False,
parent_paths: Optional[str] = False,
tree_level: Optional[str] = "patch",
sortby: Optional[str] = None,
min_alpha_channel: Optional[float] = None,
min_mean_pixel: Optional[float] = None,
max_mean_pixel: Optional[float] = None,
min_std_pixel: Optional[float] = None,
max_std_pixel: Optional[float] = None,
context_image: Optional[bool] = False,
xoffset: Optional[int] = 500,
yoffset: Optional[int] = 500,
urlmain: Optional[str] = "https://maps.nls.uk/view/",
random_state: Optional[Union[str, int]] = "random",
list_shortcuts: Optional[List[tuple]] = None,
) -> Dict:
custom_labels: list[str] = None,
annotation_set: str | None = "001",
redo_annotation: bool | None = False,
patch_paths: str | bool | None = False,
parent_paths: str | None = False,
tree_level: str | None = "patch",
sortby: str | None = None,
min_alpha_channel: float | None = None,
min_mean_pixel: float | None = None,
max_mean_pixel: float | None = None,
min_std_pixel: float | None = None,
max_std_pixel: float | None = None,
context_image: bool | None = False,
xoffset: int | None = 500,
yoffset: int | None = 500,
urlmain: str | None = "https://maps.nls.uk/view/",
random_state: str | int | None = "random",
list_shortcuts: list[tuple] | None = None,
) -> dict:
"""Prepare image data for annotation and launch the annotation interface.
Parameters
Expand Down
Loading

0 comments on commit 50c6c03

Please sign in to comment.