Skip to content

Commit 6a1525f

Browse files
[rasterio] Add stubs (#15884)
1 parent b37153f commit 6a1525f

45 files changed

Lines changed: 2222 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Stubs-only helper modules with no runtime counterpart.
2+
rasterio\._typing
3+
rasterio\._affine_types
4+
5+
# Stubs-only type aliases referenced in signatures only.
6+
rasterio\.features\.Geometry
7+
rasterio\.merge\.MethodFunction
8+
9+
# Cython implementation-detail attributes auto-generated on every
10+
# Cython-compiled module and extension class.
11+
.*\.__pyx_capi__
12+
.*\.__test__
13+
.*\.__reduce_cython__
14+
.*\.__setstate_cython__
15+
16+
# attrs-generated introspection helpers on every @attr.s class.
17+
.*\.__attrs_attrs__
18+
.*\.__attrs_own_setattr__
19+
.*\.__attrs_props__
20+
21+
# attrs-generated comparators and pattern-matching dunders on the
22+
# specific @attr.s classes in the package (these are auto-generated by
23+
# `order=True` / `eq=True`; not part of the documented API surface).
24+
rasterio\._path\._ParsedPath\.__(ge|gt|le|lt|match_args|replace)__
25+
rasterio\._path\._UnparsedPath\.__(ge|gt|le|lt|match_args|replace)__
26+
rasterio\.env\.GDALVersion\.__(ge|gt|le|lt|match_args|replace)__
27+
rasterio\.rpc\.RPC\.__(ge|gt|le|lt|match_args|replace)__
28+
rasterio\.windows\.Window\.__(ge|gt|le|lt|match_args|replace)__
29+
30+
# Cython param-name drift and @disjoint_base markers for private
31+
# extension modules. Public API surface is reconciled in the
32+
# corresponding public `rasterio.*` modules.
33+
rasterio\._base.*
34+
rasterio\._io.*
35+
rasterio\._env.*
36+
rasterio\._err.*
37+
rasterio\._features.*
38+
rasterio\._transform.*
39+
40+
# Vendored third-party packages — not part of rasterio's public API.
41+
rasterio\._vendor\..*
42+
43+
# Click-based CLI subpackage — not exposed through type-checked imports.
44+
rasterio\.rio.*

stubs/rasterio/METADATA.toml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version = "1.5.*"
2+
upstream-repository = "https://github.com/rasterio/rasterio"
3+
requires-python = ">=3.12"
4+
dependencies = ["numpy>=2", "click>=8"]
5+
6+
[tool.stubtest]
7+
stubtest-dependencies = ["rasterio==1.5.*"]
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import logging
2+
import os
3+
from collections.abc import Callable, Sequence
4+
from typing import Any, Final, Literal, NamedTuple, TypeAlias, overload
5+
6+
from numpy.typing import DTypeLike, NDArray
7+
from rasterio._base import DatasetBase as DatasetBase
8+
from rasterio._io import Statistics as Statistics
9+
from rasterio._path import _parse_path as _parse_path, _UnparsedPath as _UnparsedPath
10+
from rasterio._show_versions import show_versions as show_versions
11+
from rasterio._typing import AnyDataset, CRSInput, _Opener, _OpenOption
12+
from rasterio._version import (
13+
gdal_version as gdal_version,
14+
get_geos_version as get_geos_version,
15+
get_proj_version as get_proj_version,
16+
)
17+
from rasterio._vsiopener import _opener_registration as _opener_registration
18+
from rasterio.crs import CRS as CRS
19+
from rasterio.drivers import driver_from_extension as driver_from_extension, is_blacklisted as is_blacklisted
20+
from rasterio.dtypes import (
21+
bool_ as bool_,
22+
check_dtype as check_dtype,
23+
complex_ as complex_,
24+
complex_int16 as complex_int16,
25+
float16 as float16,
26+
float32 as float32,
27+
float64 as float64,
28+
int8 as int8,
29+
int16 as int16,
30+
int32 as int32,
31+
int64 as int64,
32+
sbyte as sbyte,
33+
ubyte as ubyte,
34+
uint8 as uint8,
35+
uint16 as uint16,
36+
uint32 as uint32,
37+
uint64 as uint64,
38+
)
39+
from rasterio.env import Env as Env, ensure_env_with_credentials as ensure_env_with_credentials
40+
from rasterio.errors import (
41+
DriverCapabilityError as DriverCapabilityError,
42+
RasterioDeprecationWarning as RasterioDeprecationWarning,
43+
RasterioIOError as RasterioIOError,
44+
)
45+
from rasterio.io import (
46+
BufferedDatasetWriter as BufferedDatasetWriter,
47+
DatasetReader as DatasetReader,
48+
DatasetWriter as DatasetWriter,
49+
FilePath as FilePath,
50+
MemoryFile as MemoryFile,
51+
get_writer_for_driver as get_writer_for_driver,
52+
get_writer_for_path as get_writer_for_path,
53+
)
54+
from rasterio.profiles import default_gtiff_profile as default_gtiff_profile
55+
from rasterio.transform import Affine as Affine, guard_transform as guard_transform
56+
57+
__all__ = ["CRS", "Band", "Env", "band", "open", "pad"]
58+
59+
__version__: Final[str]
60+
__gdal_version__: Final[str]
61+
__proj_version__: Final[str]
62+
__geos_version__: Final[str]
63+
64+
have_vsi_plugin: Final[bool]
65+
log: logging.Logger
66+
67+
_Fp: TypeAlias = str | os.PathLike[str] | MemoryFile | FilePath
68+
69+
@overload
70+
def open(
71+
fp: _Fp,
72+
mode: Literal["r"] = "r",
73+
driver: str | Sequence[str] | None = None,
74+
width: int | None = None,
75+
height: int | None = None,
76+
count: int | None = None,
77+
crs: CRSInput | None = None,
78+
transform: Affine | None = None,
79+
dtype: DTypeLike | None = None,
80+
nodata: float | None = None,
81+
sharing: bool = False,
82+
thread_safe: bool = False,
83+
opener: _Opener | None = None,
84+
**kwargs: _OpenOption,
85+
) -> DatasetReader: ...
86+
@overload
87+
def open(
88+
fp: _Fp,
89+
mode: Literal["r+", "w", "w+"],
90+
driver: str | Sequence[str] | None = None,
91+
width: int | None = None,
92+
height: int | None = None,
93+
count: int | None = None,
94+
crs: CRSInput | None = None,
95+
transform: Affine | None = None,
96+
dtype: DTypeLike | None = None,
97+
nodata: float | None = None,
98+
sharing: bool = False,
99+
thread_safe: bool = False,
100+
opener: _Opener | None = None,
101+
**kwargs: _OpenOption,
102+
) -> DatasetWriter: ...
103+
@overload
104+
def open(
105+
fp: _Fp,
106+
mode: str = "r",
107+
driver: str | Sequence[str] | None = None,
108+
width: int | None = None,
109+
height: int | None = None,
110+
count: int | None = None,
111+
crs: CRSInput | None = None,
112+
transform: Affine | None = None,
113+
dtype: DTypeLike | None = None,
114+
nodata: float | None = None,
115+
sharing: bool = False,
116+
thread_safe: bool = False,
117+
opener: _Opener | None = None,
118+
**kwargs: _OpenOption,
119+
) -> DatasetReader | DatasetWriter: ...
120+
121+
class Band(NamedTuple):
122+
ds: AnyDataset
123+
bidx: int | Sequence[int]
124+
dtype: str
125+
shape: tuple[int, ...]
126+
127+
def band(ds: AnyDataset, bidx: int | Sequence[int]) -> Band: ...
128+
129+
# `mode` and `**kwargs` mirror `numpy.pad`'s signature; see numpy.pad documentation.
130+
def pad(
131+
array: NDArray[Any], transform: Affine, pad_width: int, mode: str | Callable[..., Any] | None = None, **kwargs: Any
132+
) -> tuple[NDArray[Any], Affine]: ...
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Swap to `from affine import Affine as Affine` once affine ships `py.typed` (v3).
2+
from typing import Any, TypeAlias
3+
4+
Affine: TypeAlias = Any

stubs/rasterio/rasterio/_base.pyi

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
import logging
2+
import os
3+
from collections.abc import Iterable, Sequence
4+
from types import TracebackType
5+
from typing import Any, Final, Self
6+
from typing_extensions import deprecated
7+
8+
from rasterio._affine_types import Affine
9+
from rasterio._path import _ParsedPath, _UnparsedPath
10+
from rasterio._typing import Colormap, CRSInput, _OpenOption
11+
from rasterio.control import GroundControlPoint
12+
from rasterio.coords import BoundingBox
13+
from rasterio.crs import CRS
14+
from rasterio.enums import ColorInterp, Compression, Interleaving, MaskFlags, PhotometricInterp
15+
from rasterio.profiles import Profile
16+
from rasterio.rpc import RPC
17+
from rasterio.windows import Window
18+
19+
log: Final[logging.Logger]
20+
21+
def get_dataset_driver(path: str) -> str: ...
22+
def driver_supports_mode(drivername: str, creation_mode: str) -> bool: ...
23+
def driver_can_create(drivername: str) -> bool: ...
24+
def driver_can_create_copy(drivername: str) -> bool: ...
25+
def tastes_like_gdal(seq: Affine | Sequence[float]) -> bool: ...
26+
def _raster_driver_extensions() -> dict[str, str]: ...
27+
def _can_create_osr(crs: CRSInput) -> bool: ...
28+
def _transform(
29+
src_crs: CRSInput, dst_crs: CRSInput, xs: Sequence[float], ys: Sequence[float], zs: Sequence[float] | None
30+
) -> tuple[list[float], list[float], list[float]]: ...
31+
32+
class DatasetBase:
33+
name: str
34+
mode: str
35+
options: dict[str, Any]
36+
width: int
37+
height: int
38+
shape: tuple[int, int]
39+
driver: str
40+
41+
def __init__(
42+
self,
43+
path: str | os.PathLike[str] | _ParsedPath | _UnparsedPath | None = None,
44+
driver: str | Sequence[str] | None = None,
45+
sharing: bool = False,
46+
thread_safe: bool = False,
47+
**kwargs: _OpenOption,
48+
) -> None: ...
49+
def __enter__(self) -> Self: ...
50+
def __exit__(
51+
self, exc_type: type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None
52+
) -> None: ...
53+
def read_crs(self) -> CRS | None: ...
54+
def read_transform(self) -> list[float]: ...
55+
def start(self) -> None: ...
56+
def stop(self) -> None: ...
57+
def close(self) -> None: ...
58+
@property
59+
def closed(self) -> bool: ...
60+
@property
61+
def count(self) -> int: ...
62+
@property
63+
def indexes(self) -> tuple[int, ...]: ...
64+
@property
65+
def dtypes(self) -> tuple[str, ...]: ...
66+
@property
67+
def block_shapes(self) -> tuple[tuple[int, int], ...]: ...
68+
def get_nodatavals(self) -> tuple[float | None, ...]: ...
69+
@property
70+
def nodatavals(self) -> tuple[float | None, ...]: ...
71+
72+
@property
73+
def nodata(self) -> float | None: ...
74+
@nodata.setter
75+
def nodata(self, value: float | None) -> None: ...
76+
77+
@property
78+
def mask_flag_enums(self) -> tuple[list[MaskFlags], ...]: ...
79+
80+
@property
81+
def crs(self) -> CRS: ...
82+
@crs.setter
83+
def crs(self, value: CRSInput) -> None: ...
84+
85+
@property
86+
def descriptions(self) -> tuple[str | None, ...]: ...
87+
@descriptions.setter
88+
def descriptions(self, value: Sequence[str | None]) -> None: ...
89+
90+
def write_transform(self, transform: Sequence[float]) -> None: ...
91+
92+
@property
93+
def transform(self) -> Affine: ...
94+
@transform.setter
95+
def transform(self, value: Affine) -> None: ...
96+
97+
@property
98+
def offsets(self) -> tuple[float, ...]: ...
99+
@offsets.setter
100+
def offsets(self, value: Sequence[float]) -> None: ...
101+
102+
@property
103+
def scales(self) -> tuple[float, ...]: ...
104+
@scales.setter
105+
def scales(self, value: Sequence[float]) -> None: ...
106+
107+
@property
108+
def units(self) -> tuple[str | None, ...]: ...
109+
@units.setter
110+
def units(self, value: Sequence[str | None]) -> None: ...
111+
112+
def block_window(self, bidx: int, i: int, j: int) -> Window: ...
113+
def block_size(self, bidx: int, i: int, j: int) -> int: ...
114+
def block_windows(self, bidx: int = 0) -> Iterable[tuple[tuple[int, int], Window]]: ...
115+
@property
116+
def bounds(self) -> BoundingBox: ...
117+
@property
118+
def res(self) -> tuple[float, float]: ...
119+
@property
120+
def meta(self) -> dict[str, Any]: ...
121+
@property
122+
def compression(self) -> Compression | None: ...
123+
@property
124+
def interleaving(self) -> Interleaving | None: ...
125+
@property
126+
def photometric(self) -> PhotometricInterp | None: ...
127+
@property
128+
@deprecated("DatasetBase.is_tiled will be removed in a future rasterio release; inspect block_shapes / profile directly.")
129+
def is_tiled(self) -> bool: ...
130+
@property
131+
def profile(self) -> Profile: ...
132+
def lnglat(self) -> tuple[float, float]: ...
133+
def get_transform(self) -> list[float]: ...
134+
@property
135+
def subdatasets(self) -> list[str]: ...
136+
def tag_namespaces(self, bidx: int = 0) -> list[str]: ...
137+
def tags(self, bidx: int = 0, ns: str | None = None) -> dict[str, str]: ...
138+
def get_tag_item(self, ns: str, dm: str | None = None, bidx: int = 0, ovr: int | None = None) -> str | None: ...
139+
140+
@property
141+
def colorinterp(self) -> tuple[ColorInterp, ...]: ...
142+
@colorinterp.setter
143+
def colorinterp(self, value: Sequence[ColorInterp]) -> None: ...
144+
145+
def colormap(self, bidx: int) -> Colormap: ...
146+
def overviews(self, bidx: int) -> list[int]: ...
147+
def checksum(self, bidx: int, window: Window | None = None) -> int: ...
148+
def get_gcps(self) -> tuple[list[GroundControlPoint], CRS]: ...
149+
150+
@property
151+
def gcps(self) -> tuple[list[GroundControlPoint], CRS]: ...
152+
@gcps.setter
153+
def gcps(self, value: tuple[Sequence[GroundControlPoint], CRSInput]) -> None: ...
154+
155+
@property
156+
def rpcs(self) -> RPC | None: ...
157+
@rpcs.setter
158+
def rpcs(self, value: RPC | None) -> None: ...
159+
160+
@property
161+
def files(self) -> list[str]: ...
162+
163+
_GDAL_AT_LEAST_3_10: Final[bool]
164+
165+
complex64: Final[str]
166+
complex128: Final[str]
167+
complex_int16: Final[str]
168+
float32: Final[str]
169+
float64: Final[str]
170+
int16: Final[str]
171+
172+
def _parse_path(path: str) -> _ParsedPath | _UnparsedPath: ...

0 commit comments

Comments
 (0)