Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion stubs/rasterio/rasterio/_base.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class DatasetBase:
def mask_flag_enums(self) -> tuple[list[MaskFlags], ...]: ...

@property
def crs(self) -> CRS: ...
def crs(self) -> CRS | None: ...
@crs.setter
def crs(self, value: CRSInput) -> None: ...

Expand Down
20 changes: 18 additions & 2 deletions stubs/rasterio/rasterio/_io.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import os
from collections.abc import Iterator, Sequence
from typing import Any, BinaryIO, Final
from typing import Any, BinaryIO, Final, Literal, overload
from typing_extensions import Self, deprecated

import numpy as np
from affine import Affine as Affine
from numpy import ma
from numpy.typing import DTypeLike, NDArray
from rasterio._base import DatasetBase
from rasterio._path import _ParsedPath, _UnparsedPath
Expand Down Expand Up @@ -42,6 +43,20 @@ class Statistics:
def __init__(self, min: float, max: float, mean: float, std: float) -> None: ...

class DatasetReaderBase(DatasetBase):
@overload
def read(
self,
indexes: Indexes | None = None,
out: NDArray[Any] | None = None,
window: WindowInput | None = None,
masked: Literal[True] = True,

@thomas-maschler thomas-maschler Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The runtime default is False. Make masked a kwarg and don't pass a default to avoid matches with this overload in case users don't pass masked

Suggested change
masked: Literal[True] = True,
*,
masked: Literal[True],

out_shape: ShapeND | None = None,
boundless: bool = False,
resampling: Resampling = ...,
fill_value: NumType | None = None,
out_dtype: DTypeLike | None = None,
) -> ma.MaskedArray[Any, Any]: ...
@overload
def read(
self,
indexes: Indexes | None = None,
Expand All @@ -53,7 +68,8 @@ class DatasetReaderBase(DatasetBase):
resampling: Resampling = ...,
fill_value: NumType | None = None,
out_dtype: DTypeLike | None = None,
) -> NDArray[Any]: ...
) -> NDArray[Any] | ma.MaskedArray[Any, Any]: ...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With masked=False results will always be a simple NDArray

Suggested change
) -> NDArray[Any] | ma.MaskedArray[Any, Any]: ...
) -> NDArray[Any]: ...


def read_masks(
self,
indexes: Indexes | None = None,
Expand Down
Loading