Skip to content
This repository has been archived by the owner on Nov 23, 2024. It is now read-only.

Commit

Permalink
refactor: linter
Browse files Browse the repository at this point in the history
  • Loading branch information
Marsmaennchen221 committed May 8, 2024
1 parent 3256d2c commit d87f65a
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/safeds_datasets/image/_mnist/_mnist.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,22 @@
import os
import struct
import sys
import tempfile
import urllib.request
from array import array
from pathlib import Path
from typing import TYPE_CHECKING
from urllib.error import HTTPError

import torch
from safeds._config import _init_default_device
from safeds.data.image.containers import ImageList
from safeds.data.image.containers._single_size_image_list import _SingleSizeImageList
from safeds.data.labeled.containers import ImageDataset
from safeds.data.tabular.containers import Column

if TYPE_CHECKING:
from safeds.data.image.containers import ImageList

_mnist_links: list[str] = ["http://yann.lecun.com/exdb/mnist/", "https://ossci-datasets.s3.amazonaws.com/mnist/"]
_mnist_files: dict[str, str] = {
"train-images-idx3": "train-images-idx3-ubyte.gz",
Expand Down Expand Up @@ -158,7 +162,7 @@ def _load_mnist_like(path: str | Path, files: dict[str, str], labels: dict[int,
if magic != 2049:
raise ValueError(f"Magic number mismatch. Actual {magic} != Expected 2049.")
if "train" in file_name:
train_labels = Column(file_name, [labels[l] for l in array("B", label_file.read())])
train_labels = Column(file_name, [labels[label_index] for label_index in array("B", label_file.read())])

Check warning on line 165 in src/safeds_datasets/image/_mnist/_mnist.py

View check run for this annotation

Codecov / codecov/patch

src/safeds_datasets/image/_mnist/_mnist.py#L153-L165

Added lines #L153 - L165 were not covered by tests
else:
test_labels = Column(file_name, array("B", label_file.read()))

Check warning on line 167 in src/safeds_datasets/image/_mnist/_mnist.py

View check run for this annotation

Codecov / codecov/patch

src/safeds_datasets/image/_mnist/_mnist.py#L167

Added line #L167 was not covered by tests
else:
Expand Down Expand Up @@ -188,12 +192,12 @@ def _download_mnist_like(path: str | Path, files: dict[str, str], links: list[st
for file_name, file_path in files.items():
for link in links:
try:
print(f"Trying to download file {file_name} via {link + file_path}")
print(f"Trying to download file {file_name} via {link + file_path}") # noqa: T201
urllib.request.urlretrieve(link + file_path, path / file_path, reporthook=_report_download_progress)
print()
print() # noqa: T201
break
except HTTPError as e:
print(e)
print(f"An error occurred while downloading: {e}") # noqa: T201

Check warning on line 200 in src/safeds_datasets/image/_mnist/_mnist.py

View check run for this annotation

Codecov / codecov/patch

src/safeds_datasets/image/_mnist/_mnist.py#L191-L200

Added lines #L191 - L200 were not covered by tests


def _report_download_progress(current_packages: int, package_size: int, file_size: int) -> None:
Expand Down

0 comments on commit d87f65a

Please sign in to comment.