Skip to content

Commit

Permalink
Bump ruff from 0.4.4 to 0.4.5 in /requirements (microsoft#2080)
Browse files Browse the repository at this point in the history
* Bump ruff from 0.4.4 to 0.4.5 in /requirements

Bumps [ruff](https://github.com/astral-sh/ruff) from 0.4.4 to 0.4.5.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](astral-sh/ruff@v0.4.4...v0.4.5)

---
updated-dependencies:
- dependency-name: ruff
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <[email protected]>

* min version of numpy now supports type hints

* pre-commit: update ruff

---------

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Adam J. Stewart <[email protected]>
  • Loading branch information
dependabot[bot] and adamjstewart authored May 23, 2024
1 parent 2aecee9 commit 5cfbd65
Show file tree
Hide file tree
Showing 35 changed files with 52 additions and 52 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.3.7
rev: v0.4.5
hooks:
- id: ruff
types_or:
Expand Down
2 changes: 1 addition & 1 deletion experiments/ssl4eo/landsat/chip_landsat_benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def retrieve_mask_chip(
mask array
"""
out_shape = (1, *img_src.shape)
mask_chip: 'np.typing.NDArray[np.uint8]' = mask_src.read(
mask_chip: np.typing.NDArray[np.uint8] = mask_src.read(
out_shape=out_shape, window=from_bounds(*img_src.bounds, mask_src.transform)
)

Expand Down
2 changes: 1 addition & 1 deletion requirements/style.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# style
mypy==1.10.0
ruff==0.4.4
ruff==0.4.5
4 changes: 2 additions & 2 deletions tests/datasets/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,7 @@ def test_nonexisting_directory(tmp_path: Path) -> None:


def test_percentile_normalization() -> None:
img: 'np.typing.NDArray[np.int_]' = np.array([[1, 2], [98, 100]])
img: np.typing.NDArray[np.int_] = np.array([[1, 2], [98, 100]])

img = percentile_normalization(img, 2, 98)
assert img.min() == 0
Expand All @@ -573,7 +573,7 @@ def test_percentile_normalization() -> None:
[np.uint8, np.uint16, np.uint32, np.int8, np.int16, np.int32, np.int64],
)
def test_array_to_tensor(array_dtype: 'np.typing.DTypeLike') -> None:
array: 'np.typing.NDArray[Any]' = np.zeros((2,), dtype=array_dtype)
array: np.typing.NDArray[Any] = np.zeros((2,), dtype=array_dtype)
array[0] = np.iinfo(array.dtype).min
array[1] = np.iinfo(array.dtype).max
tensor = array_to_tensor(array)
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/advance.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ def _load_image(self, path: str) -> Tensor:
the image
"""
with Image.open(path) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
tensor = torch.from_numpy(array)
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/bigearthnet.py
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ def _load_image(self, index: int) -> Tensor:
resampling=Resampling.bilinear,
)
images.append(array)
arrays: 'np.typing.NDArray[np.int_]' = np.stack(images, axis=0)
arrays: np.typing.NDArray[np.int_] = np.stack(images, axis=0)
tensor = torch.from_numpy(arrays).float()
return tensor

Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/biomassters.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _load_target(self, filename: str) -> Tensor:
target mask
"""
with rasterio.open(os.path.join(self.root, 'train_agbm', filename), 'r') as src:
arr: 'np.typing.NDArray[np.float_]' = src.read()
arr: np.typing.NDArray[np.float_] = src.read()

target = torch.from_numpy(arr).float()
return target
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/cloud_cover.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def _load_image(self, index: int) -> Tensor:
with rasterio.open(path) as image_data:
image_array = image_data.read(1).astype(np.int32)
images.append(image_array)
image_stack: 'np.typing.NDArray[np.int_]' = np.stack(images, axis=0)
image_stack: np.typing.NDArray[np.int_] = np.stack(images, axis=0)
image_tensor = torch.from_numpy(image_stack)
return image_tensor

Expand All @@ -200,7 +200,7 @@ def _load_target(self, index: int) -> Tensor:
with rasterio.open(label_asset_path) as target_data:
target_img = target_data.read(1).astype(np.int32)

target_array: 'np.typing.NDArray[np.int_]' = np.array(target_img)
target_array: np.typing.NDArray[np.int_] = np.array(target_img)
target_tensor = torch.from_numpy(target_array)
return target_tensor

Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/cowc.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _load_image(self, index: int) -> Tensor:
"""
filename = os.path.join(self.root, self.images[index])
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img)
array: np.typing.NDArray[np.int_] = np.array(img)
tensor = torch.from_numpy(array).float()
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/cv4a_kenya_crop_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _load_label_tile(self, tile_name: str) -> tuple[Tensor, Tensor]:
)

with Image.open(os.path.join(directory, 'labels.tif')) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img)
array: np.typing.NDArray[np.int_] = np.array(img)
labels = torch.from_numpy(array)

with Image.open(os.path.join(directory, 'field_ids.tif')) as img:
Expand Down Expand Up @@ -332,7 +332,7 @@ def _load_single_image_tile(
f'{band_name}.tif',
)
with Image.open(filepath) as band_img:
array: 'np.typing.NDArray[np.int_]' = np.array(band_img)
array: np.typing.NDArray[np.int_] = np.array(band_img)
img[band_index] = torch.from_numpy(array)

return img
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/cyclone.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def _load_image(self, directory: str) -> Tensor:
except AttributeError:
resample = Image.BILINEAR # type: ignore[attr-defined]
img = img.resize(size=(self.size, self.size), resample=resample)
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
tensor = torch.from_numpy(array)
tensor = tensor.permute((2, 0, 1)).float()
return tensor
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/deepglobelandcover.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ def _load_image(self, index: int) -> Tensor:
path = self.image_fns[index]

with Image.open(path) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img)
array: np.typing.NDArray[np.int_] = np.array(img)
tensor = torch.from_numpy(array)
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1)).to(torch.float32)
Expand All @@ -201,7 +201,7 @@ def _load_target(self, index: int) -> Tensor:
"""
path = self.mask_fns[index]
with Image.open(path) as img:
array: 'np.typing.NDArray[np.uint8]' = np.array(img)
array: np.typing.NDArray[np.uint8] = np.array(img)
array = rgb_to_mask(array, self.colormap)
tensor = torch.from_numpy(array)
# Convert from HxWxC to CxHxW
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/dfc2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def _load_image(self, path: str, shape: Sequence[int] | None = None) -> Tensor:
the image
"""
with rasterio.open(path) as f:
array: 'np.typing.NDArray[np.float_]' = f.read(
array: np.typing.NDArray[np.float_] = f.read(
out_shape=shape, out_dtype='float32', resampling=Resampling.bilinear
)
tensor = torch.from_numpy(array)
Expand All @@ -251,7 +251,7 @@ def _load_target(self, path: str) -> Tensor:
the target mask
"""
with rasterio.open(path) as f:
array: 'np.typing.NDArray[np.int_]' = f.read(
array: np.typing.NDArray[np.int_] = f.read(
indexes=1, out_dtype='int32', resampling=Resampling.bilinear
)
tensor = torch.from_numpy(array)
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/etci2021.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def _load_image(self, path: str) -> Tensor:
"""
filename = os.path.join(path)
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
tensor = torch.from_numpy(array).float()
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand All @@ -221,7 +221,7 @@ def _load_target(self, path: str) -> Tensor:
"""
filename = os.path.join(path)
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
tensor = torch.from_numpy(array)
tensor = torch.clamp(tensor, min=0, max=1)
tensor = tensor.to(torch.long)
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/eurocrops.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ def plot(
def apply_cmap(arr: 'np.typing.NDArray[Any]') -> 'np.typing.NDArray[np.float_]':
# Color 0 as black, while applying default color map for the class indices.
cmap = plt.get_cmap('viridis')
im: 'np.typing.NDArray[np.float_]' = cmap(arr / len(self.class_map))
im: np.typing.NDArray[np.float_] = cmap(arr / len(self.class_map))
im[arr == 0] = 0
return im

Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/fair1m.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def _load_image(self, path: str) -> Tensor:
the image
"""
with Image.open(path) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
tensor = torch.from_numpy(array)
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/forestdamage.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def _load_image(self, path: str) -> Tensor:
the image
"""
with Image.open(path) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
tensor: Tensor = torch.from_numpy(array)
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ def _load_image(self, index: int) -> tuple[Tensor, Tensor]:
the image and class label
"""
img, label = ImageFolder.__getitem__(self, index)
array: 'np.typing.NDArray[np.int_]' = np.array(img)
array: np.typing.NDArray[np.int_] = np.array(img)
tensor = torch.from_numpy(array).float()
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/gid15.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ def _load_image(self, path: str) -> Tensor:
"""
filename = os.path.join(path)
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
tensor = torch.from_numpy(array)
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1)).float()
Expand All @@ -206,7 +206,7 @@ def _load_target(self, path: str) -> Tensor:
"""
filename = os.path.join(path)
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
tensor = torch.from_numpy(array)
tensor = tensor.to(torch.long)
return tensor
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/idtrees.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ def _load_las(self, path: str) -> Tensor:
"""
laspy = lazy_import('laspy')
las = laspy.read(path)
array: 'np.typing.NDArray[np.int_]' = np.stack([las.x, las.y, las.z], axis=0)
array: np.typing.NDArray[np.int_] = np.stack([las.x, las.y, las.z], axis=0)
tensor = torch.from_numpy(array)
return tensor

Expand Down Expand Up @@ -570,7 +570,7 @@ def plot_las(self, index: int) -> 'pyvista.Plotter': # type: ignore[name-define
path = self.images[index]
path = path.replace('RGB', 'LAS').replace('.tif', '.las')
las = laspy.read(path)
points: 'np.typing.NDArray[np.int_]' = np.stack(
points: np.typing.NDArray[np.int_] = np.stack(
[las.x, las.y, las.z], axis=0
).transpose((1, 0))
point_cloud = pyvista.PolyData(points)
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/landcoverai.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ def _load_image(self, id_: str) -> Tensor:
"""
filename = os.path.join(self.root, 'output', id_ + '.jpg')
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img)
array: np.typing.NDArray[np.int_] = np.array(img)
tensor = torch.from_numpy(array).float()
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand All @@ -378,7 +378,7 @@ def _load_target(self, id_: str) -> Tensor:
"""
filename = os.path.join(self.root, 'output', id_ + '_m.png')
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
tensor = torch.from_numpy(array).long()
return tensor

Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/levircd.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ def _load_image(self, path: str) -> Tensor:
"""
filename = os.path.join(path)
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
tensor = torch.from_numpy(array).float()
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand All @@ -122,7 +122,7 @@ def _load_target(self, path: str) -> Tensor:
"""
filename = os.path.join(path)
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
tensor = torch.from_numpy(array)
tensor = torch.clamp(tensor, min=0, max=1)
tensor = tensor.to(torch.long)
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/loveda.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def _load_image(self, path: str) -> Tensor:
"""
filename = os.path.join(path)
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
tensor = torch.from_numpy(array).float()
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand All @@ -225,7 +225,7 @@ def _load_target(self, path: str) -> Tensor:
"""
filename = os.path.join(path)
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
tensor = torch.from_numpy(array)
tensor = tensor.to(torch.long)
return tensor
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/mapinwild.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def _load_raster(self, filename: int, source: str) -> Tensor:
"""
with rasterio.open(os.path.join(self.root, source, f'{filename}.tif')) as f:
raw_array = f.read()
array: 'np.typing.NDArray[np.int_]' = np.stack(raw_array, axis=0)
array: np.typing.NDArray[np.int_] = np.stack(raw_array, axis=0)
if array.dtype == np.uint16:
array = array.astype(np.int32)
tensor = torch.from_numpy(array).float()
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/millionaid.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ def _load_image(self, path: str) -> Tensor:
the image
"""
with Image.open(path) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('RGB'))
tensor: Tensor = torch.from_numpy(array)
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand Down
8 changes: 4 additions & 4 deletions torchgeo/datasets/oscd.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,11 @@ def _load_image(self, paths: Sequence[str]) -> Tensor:
Returns:
the image
"""
images: list['np.typing.NDArray[np.int_]'] = []
images: list[np.typing.NDArray[np.int_]] = []
for path in paths:
with Image.open(path) as img:
images.append(np.array(img))
array: 'np.typing.NDArray[np.int_]' = np.stack(images, axis=0).astype(np.int_)
array: np.typing.NDArray[np.int_] = np.stack(images, axis=0).astype(np.int_)
tensor = torch.from_numpy(array).float()
return tensor

Expand All @@ -235,7 +235,7 @@ def _load_target(self, path: str) -> Tensor:
"""
filename = os.path.join(path)
with Image.open(filename) as img:
array: 'np.typing.NDArray[np.int_]' = np.array(img.convert('L'))
array: np.typing.NDArray[np.int_] = np.array(img.convert('L'))
tensor = torch.from_numpy(array)
tensor = torch.clamp(tensor, min=0, max=1)
tensor = tensor.to(torch.long)
Expand Down Expand Up @@ -314,7 +314,7 @@ def get_masked(img: Tensor) -> 'np.typing.NDArray[np.uint8]':
rgb_img = (np.clip((rgb_img - per02) / (per98 - per02), 0, 1) * 255).astype(
np.uint8
)
array: 'np.typing.NDArray[np.uint8]' = draw_semantic_segmentation_masks(
array: np.typing.NDArray[np.uint8] = draw_semantic_segmentation_masks(
torch.from_numpy(rgb_img),
sample['mask'],
alpha=alpha,
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/potsdam.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def _load_target(self, index: int) -> Tensor:
"""
path = self.files[index]['mask']
with Image.open(path) as img:
array: 'np.typing.NDArray[np.uint8]' = np.array(img.convert('RGB'))
array: np.typing.NDArray[np.uint8] = np.array(img.convert('RGB'))
array = rgb_to_mask(array, self.colormap)
tensor = torch.from_numpy(array)
# Convert from HxWxC to CxHxW
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/reforestree.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def _load_image(self, path: str) -> Tensor:
the image
"""
with Image.open(path) as img:
array: 'np.typing.NDArray[np.uint8]' = np.array(img)
array: np.typing.NDArray[np.uint8] = np.array(img)
tensor = torch.from_numpy(array)
# Convert from HxWxC to CxHxW
tensor = tensor.permute((2, 0, 1))
Expand Down
4 changes: 2 additions & 2 deletions torchgeo/datasets/so2sat.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ def __init__(
assert split in self.filenames_by_version[version]

self._validate_bands(bands)
self.s1_band_indices: 'np.typing.NDArray[np.int_]' = np.array(
self.s1_band_indices: np.typing.NDArray[np.int_] = np.array(
[
self.all_s1_band_names.index(b)
for b in bands
Expand All @@ -240,7 +240,7 @@ def __init__(

self.s1_band_names = [self.all_s1_band_names[i] for i in self.s1_band_indices]

self.s2_band_indices: 'np.typing.NDArray[np.int_]' = np.array(
self.s2_band_indices: np.typing.NDArray[np.int_] = np.array(
[
self.all_s2_band_names.index(b)
for b in bands
Expand Down
2 changes: 1 addition & 1 deletion torchgeo/datasets/spacenet.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def _load_mask(
max_speed_bin = 65
speed_arr_bin = np.arange(min_speed_bin, max_speed_bin + 1)
bin_size_mph = 10.0
speed_cls_arr: 'np.typing.NDArray[np.int_]' = np.array(
speed_cls_arr: np.typing.NDArray[np.int_] = np.array(
[math.ceil(s / bin_size_mph) for s in speed_arr_bin]
)

Expand Down
Loading

0 comments on commit 5cfbd65

Please sign in to comment.