Skip to content

Commit

Permalink
Fix some assorted lints (#8460)
Browse files Browse the repository at this point in the history
### What

Not sure what changed to cause me to start hitting these locally in my
pre-push hook, but they all seem valid.
  • Loading branch information
jleibs authored Dec 14, 2024
1 parent 0c13f96 commit 0f81072
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions examples/python/arkit_scenes/arkit_scenes/download_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import subprocess
import zipfile
from pathlib import Path
from typing import Final
from typing import Final, Optional

import pandas as pd

Expand Down Expand Up @@ -196,14 +196,14 @@ def download_laser_scanner_point_clouds(laser_scanner_point_cloud_id: str, visit
download_file(file_url, filename, laser_scanner_point_clouds_folder_path)


def get_metadata(dataset: str, download_dir: Path) -> pd.DataFrame:
def get_metadata(dataset: str, download_dir: Path) -> Optional[pd.DataFrame]:
filename = "metadata.csv"
url = f"{ARkitscense_url}/threedod/{filename}" if "3dod" == dataset else f"{ARkitscense_url}/{dataset}/{filename}"
dst_folder = download_dir / dataset
dst_file = dst_folder / filename

if not download_file(url, filename, dst_folder):
return
return None

metadata = pd.read_csv(dst_file)
return metadata
Expand Down Expand Up @@ -235,7 +235,7 @@ def download_data(
"""
metadata = get_metadata(dataset, download_dir)
if None is metadata:
if metadata is None:
print(f"Error retrieving metadata for dataset {dataset}")
return

Expand Down
4 changes: 2 additions & 2 deletions rerun_py/rerun_sdk/rerun/_send_columns.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import Iterable, Protocol, TypeVar, Union
from typing import Iterable, Protocol, TypeVar

import pyarrow as pa
import rerun_bindings as bindings
Expand Down Expand Up @@ -121,7 +121,7 @@ def as_arrow_array(self) -> pa.Array:
def send_columns(
entity_path: str,
times: Iterable[TimeColumnLike],
components: Iterable[Union[ComponentBatchLike]],
components: Iterable[ComponentBatchLike],
recording: RecordingStream | None = None,
strict: bool | None = None,
) -> None:
Expand Down
9 changes: 8 additions & 1 deletion rerun_py/rerun_sdk/rerun/archetypes/image_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
from ..error_utils import _send_warning_or_raise, catch_and_log_exceptions

if TYPE_CHECKING:
from PIL import Image as PILImage

ImageLike = Union[
npt.NDArray[np.float16],
npt.NDArray[np.float32],
Expand All @@ -30,18 +32,23 @@
npt.NDArray[np.uint32],
npt.NDArray[np.uint64],
npt.NDArray[np.uint8],
PILImage.Image,
]
from . import EncodedImage, Image


def _to_numpy(tensor: ImageLike) -> npt.NDArray[Any]:
from PIL import Image as PILImage

# isinstance is 4x faster than catching AttributeError
if isinstance(tensor, np.ndarray):
return tensor
if isinstance(tensor, PILImage.Image):
return np.array(tensor, copy=False)

try:
# Make available to the cpu
return tensor.numpy(force=True) # type: ignore[union-attr]
return tensor.numpy(force=True) # type: ignore[union-attr, no-any-return]
except AttributeError:
return np.array(tensor, copy=False)

Expand Down

0 comments on commit 0f81072

Please sign in to comment.