diff --git a/mediapy/__init__.py b/mediapy/__init__.py index a1b505e..f44995f 100644 --- a/mediapy/__init__.py +++ b/mediapy/__init__.py @@ -47,17 +47,18 @@ Show titled images side-by-side: ```python +rng = np.random.default_rng(1) images = { 'original': checkerboard, 'darkened': checkerboard * 0.7, - 'random': np.random.rand(32, 32, 3), + 'random': rng.random((32, 32, 3)), } show_images(images, vmin=0.0, vmax=1.0, border=True, height=64) ``` Compare two images using an interactive slider: ```python -compare_images([checkerboard, np.random.rand(128, 128, 3)]) +compare_images([checkerboard, rng.random((128, 128, 3))]) ``` ## Video examples @@ -86,7 +87,7 @@ Create and display a looping two-frame GIF video: ```python -image1 = resize_image(np.random.rand(10, 10, 3), (50, 50)) +image1 = resize_image(np.random.default_rng(1).random((10, 10, 3)), (50, 50)) show_video([image1, image1 * 0.8], fps=2, codec='gif') ``` @@ -108,7 +109,6 @@ __version_info__ = tuple(int(num) for num in __version__.split('.')) import base64 -from collections.abc import Callable, Iterable, Iterator, Mapping, Sequence import contextlib import functools import importlib @@ -125,9 +125,10 @@ import sys import tempfile import typing -from typing import Any import urllib.request import warnings +from collections.abc import Callable, Generator, Iterable, Iterator, Mapping, Sequence +from typing import Any, TypeVar import IPython.display import matplotlib.pyplot @@ -136,12 +137,11 @@ import PIL.Image import PIL.ImageOps - if not hasattr(PIL.Image, 'Resampling'): # Allow Pillow<9.0. PIL.Image.Resampling = PIL.Image # type: ignore # Selected and reordered here for pdoc documentation. -__all__ = [ +__all__ = [ # noqa: RUF022 'show_image', 'show_images', 'compare_images', @@ -180,16 +180,18 @@ _DTypeLike = npt.DTypeLike _NDArray = npt.NDArray[Any] _DType = np.dtype[Any] + _BaseArray = npt.NDArray[Any] # Satisfies mypy. else: # Create named types for use in the `pdoc` documentation. - _ArrayLike = typing.TypeVar('_ArrayLike') - _DTypeLike = typing.TypeVar('_DTypeLike') - _NDArray = typing.TypeVar('_NDArray') - _DType = typing.TypeVar('_DType') # pylint: disable=invalid-name + _ArrayLike = TypeVar('_ArrayLike') + _DTypeLike = TypeVar('_DTypeLike') + _NDArray = TypeVar('_NDArray') + _DType = TypeVar('_DType') # pylint: disable=invalid-name + _BaseArray = np.ndarray # Avoids runtime errors in Python 3.14+. _IPYTHON_HTML_SIZE_LIMIT = 10**10 # Unlimited seems to be OK now. -_T = typing.TypeVar('_T') -_Path = typing.Union[str, 'os.PathLike[str]'] +_T = TypeVar('_T') +_Path = str | os.PathLike[str] _IMAGE_COMPARISON_HTML = """\