Skip to content

Commit ef586b4

Browse files
authored
Pull geopandas changes from typeshed and mark as moved upstream (#21)
1 parent f0129dc commit ef586b4

File tree

10 files changed

+91
-60
lines changed

10 files changed

+91
-60
lines changed

README.md

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,17 +79,6 @@ This project is licensed under the MIT License.
7979
<th>Yes</th>
8080
<th>No</th>
8181
</tr>
82-
<tr>
83-
<th>geopandas</th>
84-
<th><code>geopandas</code></th>
85-
<th>
86-
<a href="https://pypi.org/project/geopandas">PyPI</a>,
87-
<a href="https://github.com/geopandas/geopandas">GitHub</a>
88-
</th>
89-
<th>Complete</th>
90-
<th>Yes</th>
91-
<th>Yes</th>
92-
</tr>
9382
</table>
9483

9584
## Upstreamed stubs
@@ -112,4 +101,9 @@ These stubs were included here in the past and have been moved to typeshed or to
112101
<th><a href="https://github.com/python/typeshed/tree/main/stubs/shapely">typeshed</a></th>
113102
<th><code>pip install types-shapely</code></th>
114103
</tr>
104+
<tr>
105+
<th><a href="https://pypi.org/project/geopandas">geopandas</a></th>
106+
<th><a href="https://github.com/python/typeshed/tree/main/stubs/geopandas">typeshed</a></th>
107+
<th><code>pip install types-geopandas</code></th>
108+
</tr>
115109
</table>

stubs/geopandas-stubs/_config.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ class Option(NamedTuple):
77
default_value: Any
88
doc: str
99
validator: Callable[[object], Unused]
10-
callback: Callable[[str, Any], Unused] | None
10+
callback: Callable[[str, object], Unused] | None
1111

1212
class Options:
1313
def __init__(self, options: SupportsItems[str, Option]) -> None: ...

stubs/geopandas-stubs/array.pyi

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ from geopandas.sindex import SpatialIndex
1717

1818
_ScalarType = TypeVar("_ScalarType", bound=np.generic)
1919
_Array1D: TypeAlias = np.ndarray[tuple[int], np.dtype[_ScalarType]]
20+
_Array2D: TypeAlias = np.ndarray[tuple[int, int], np.dtype[_ScalarType]]
2021
_ArrayOrGeom: TypeAlias = GeometryArray | ArrayLike | Geometry
2122

2223
TransformerFromCRS = Transformer.from_crs
@@ -89,14 +90,14 @@ class GeometryArray(ExtensionArray):
8990
@property
9091
def has_z(self) -> _Array1D[np.bool]: ...
9192
@property
92-
def geom_type(self) -> _Array1D[np.int64]: ...
93+
def geom_type(self) -> _Array1D[np.str_]: ...
9394
@property
9495
def area(self) -> _Array1D[np.float64]: ...
9596
@property
9697
def length(self) -> _Array1D[np.float64]: ...
97-
def count_coordinates(self) -> _Array1D[np.int64]: ...
98-
def count_geometries(self) -> _Array1D[np.int64]: ...
99-
def count_interior_rings(self) -> _Array1D[np.int64]: ...
98+
def count_coordinates(self) -> _Array1D[np.int32]: ...
99+
def count_geometries(self) -> _Array1D[np.int32]: ...
100+
def count_interior_rings(self) -> _Array1D[np.int32]: ...
100101
def get_precision(self) -> _Array1D[np.float64]: ...
101102
def get_geometry(self, index: SupportsIndex | ArrayLike) -> _Array1D[np.object_]: ...
102103
@property
@@ -163,18 +164,19 @@ class GeometryArray(ExtensionArray):
163164
def snap(self, other: _ArrayOrGeom, tolerance: float | ArrayLike) -> GeometryArray: ...
164165
def shared_paths(self, other: _ArrayOrGeom) -> GeometryArray: ...
165166
def distance(self, other: _ArrayOrGeom) -> _Array1D[np.float64]: ...
166-
def hausdorff_distance(self, other: _ArrayOrGeom, **kwargs: Any) -> _Array1D[np.float64]: ...
167+
def hausdorff_distance(self, other: _ArrayOrGeom, **kwargs) -> _Array1D[np.float64]: ...
167168
def frechet_distance(self, other: _ArrayOrGeom, **kwargs) -> _Array1D[np.float64]: ...
168169
def buffer(self, distance: float | ArrayLike, resolution: int = 16, **kwargs) -> GeometryArray: ...
169-
def interpolate(self, distance, normalized: bool = False) -> GeometryArray: ...
170+
def interpolate(self, distance: float | ArrayLike, normalized: bool = False) -> GeometryArray: ...
170171
def simplify(self, tolerance: float | ArrayLike, preserve_topology: bool = True) -> GeometryArray: ...
171172
def project(self, other: _ArrayOrGeom, normalized: bool = False) -> _Array1D[np.float64]: ...
172173
def relate(self, other: _ArrayOrGeom) -> _Array1D[np.str_]: ...
173-
def relate_pattern(self, other, pattern: str) -> _Array1D[np.bool]: ...
174+
def relate_pattern(self, other: _ArrayOrGeom, pattern: str) -> _Array1D[np.bool]: ...
175+
@deprecated("Use method `union_all` instead.")
174176
def unary_union(self) -> BaseGeometry: ...
175177
def union_all(self, method: Literal["coverage", "unary"] = "unary") -> BaseGeometry: ...
176178
def intersection_all(self) -> BaseGeometry: ...
177-
def affine_transform(self, matrix: Incomplete) -> GeometryArray: ...
179+
def affine_transform(self, matrix) -> GeometryArray: ...
178180
def translate(self, xoff: float = 0.0, yoff: float = 0.0, zoff: float = 0.0) -> GeometryArray: ...
179181
def rotate(self, angle: float, origin: _AffinityOrigin = "center", use_radians: bool = False) -> GeometryArray: ...
180182
def scale(
@@ -192,7 +194,7 @@ class GeometryArray(ExtensionArray):
192194
@property
193195
def z(self) -> _Array1D[np.float64]: ...
194196
@property
195-
def bounds(self) -> _Array1D[np.float64]: ...
197+
def bounds(self) -> _Array2D[np.float64]: ...
196198
@property
197199
def total_bounds(self) -> _Array1D[np.float64]: ...
198200
@property
@@ -215,7 +217,12 @@ class GeometryArray(ExtensionArray):
215217
limit: int | None = None,
216218
copy: bool = True,
217219
) -> GeometryArray: ...
218-
def astype(self, dtype: DTypeLike, copy: bool = True) -> GeometryArray | ExtensionArray | NDArray[Any]: ...
220+
@overload
221+
def astype(self, dtype: GeometryDtype, copy: bool = True) -> GeometryArray: ...
222+
@overload
223+
def astype(self, dtype: ExtensionDtype | Literal["string"], copy: bool = True) -> ExtensionArray: ... # type: ignore[overload-overlap]
224+
@overload
225+
def astype(self, dtype: DTypeLike, copy: bool = True) -> _Array1D[Incomplete]: ...
219226
def isna(self) -> _Array1D[np.bool]: ...
220227
def value_counts(self, dropna: bool = True) -> pd.Series[int]: ...
221228
def unique(self) -> GeometryArray: ...

stubs/geopandas-stubs/base.pyi

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from _typeshed import Incomplete, SupportsGetItem
1+
from _typeshed import SupportsGetItem
22
from collections.abc import Callable, Hashable, Iterable, Mapping, Sequence
33
from typing import Any, Literal, Protocol, SupportsIndex, overload, type_check_only
44
from typing_extensions import Self, TypeAlias, deprecated
@@ -13,7 +13,7 @@ from pyproj import CRS
1313
from shapely import Geometry, MultiPolygon, Point, Polygon
1414
from shapely.geometry.base import BaseGeometry
1515

16-
from geopandas.array import GeometryArray
16+
from geopandas.array import GeometryArray, _Array1D
1717
from geopandas.geodataframe import GeoDataFrame
1818
from geopandas.geoseries import GeoSeries
1919
from geopandas.sindex import SpatialIndex
@@ -34,7 +34,7 @@ _BboxLike: TypeAlias = Sequence[float] | NDArray[np.floating[Any]] | Geometry |
3434
_MaskLike: TypeAlias = dict[str, Any] | Geometry | GeoDataFrame | GeoSeries # noqa: PYI047
3535

3636
# XXX: cannot use IndexOpsMixin[Geometry] because of IndexOpsMixin type variable bounds
37-
_GeoListLike: TypeAlias = ArrayLike | Sequence[Geometry] | IndexOpsMixin[Incomplete]
37+
_GeoListLike: TypeAlias = ArrayLike | Sequence[Geometry] | IndexOpsMixin[Any]
3838
_ConvertibleToGeoSeries: TypeAlias = Geometry | Mapping[int, Geometry] | Mapping[str, Geometry] | _GeoListLike # noqa: PYI047
3939

4040
# XXX: cannot use pd.Series[Geometry] because of pd.Series type variable bounds
@@ -162,7 +162,7 @@ class GeoPandasBase:
162162
@property
163163
def bounds(self) -> pd.DataFrame: ...
164164
@property
165-
def total_bounds(self) -> NDArray[np.float64]: ...
165+
def total_bounds(self) -> _Array1D[np.float64]: ...
166166
@property
167167
def sindex(self) -> SpatialIndex: ...
168168
@property
@@ -182,7 +182,7 @@ class GeoPandasBase:
182182
def relate_pattern(self, other: GeoSeries | Geometry, pattern: str, align: bool | None = None) -> pd.Series[bool]: ...
183183
def project(self, other: GeoSeries | Geometry, normalized: bool = False, align: bool | None = None) -> pd.Series[float]: ...
184184
def interpolate(self, distance: float | ArrayLike, normalized: bool = False) -> GeoSeries: ...
185-
def affine_transform(self, matrix: Incomplete) -> GeoSeries: ...
185+
def affine_transform(self, matrix) -> GeoSeries: ...
186186
def translate(self, xoff: float = 0.0, yoff: float = 0.0, zoff: float = 0.0) -> GeoSeries: ...
187187
def rotate(self, angle: float, origin: _AffinityOrigin = "center", use_radians: bool = False) -> GeoSeries: ...
188188
def scale(

stubs/geopandas-stubs/geodataframe.pyi

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import io
22
import os
3-
from _typeshed import Incomplete, SupportsGetItem, SupportsRead, SupportsWrite
4-
from collections.abc import Callable, Hashable, Iterable, Iterator, Mapping
3+
from _typeshed import Incomplete, SupportsGetItem, SupportsLenAndGetItem, SupportsRead, SupportsWrite
4+
from collections.abc import Callable, Container, Hashable, Iterable, Iterator, Mapping
55
from json import JSONEncoder
66
from typing import Any, Literal, overload
77
from typing_extensions import Self
@@ -97,7 +97,12 @@ class GeoDataFrame(GeoPandasBase, pd.DataFrame): # type: ignore[misc]
9797
def crs(self, value: _ConvertibleToCRS | None) -> None: ...
9898
@classmethod
9999
def from_dict( # type: ignore[override]
100-
cls, data: Mapping[Hashable, Any], geometry: _GeomCol | None = None, crs: _ConvertibleToCRS | None = None, **kwargs
100+
# Mapping[Any, Any] because of invariance keys and arbitrary values
101+
cls,
102+
data: Mapping[Any, Any],
103+
geometry: _GeomCol | None = None,
104+
crs: _ConvertibleToCRS | None = None,
105+
**kwargs,
101106
) -> Self: ...
102107
# Keep inline with GeoSeries.from_file and geopandas.io.file._read_file
103108
@classmethod
@@ -135,8 +140,8 @@ class GeoDataFrame(GeoPandasBase, pd.DataFrame): # type: ignore[misc]
135140
crs: _ConvertibleToCRS | None = None,
136141
index_col: str | list[str] | None = None,
137142
coerce_float: bool = True,
138-
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = None,
139-
params: list[Scalar] | tuple[Scalar, ...] | Mapping[str, Scalar] | None = None,
143+
parse_dates: Container[str | Mapping[str, Any]] | Mapping[str, str | Mapping[str, Any]] | None = None,
144+
params: SupportsLenAndGetItem[Scalar] | Mapping[str, Scalar] | None = None,
140145
*,
141146
chunksize: int,
142147
) -> Iterator[GeoDataFrame]: ...
@@ -150,8 +155,8 @@ class GeoDataFrame(GeoPandasBase, pd.DataFrame): # type: ignore[misc]
150155
crs: _ConvertibleToCRS | None = None,
151156
index_col: str | list[str] | None = None,
152157
coerce_float: bool = True,
153-
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = None,
154-
params: list[Scalar] | tuple[Scalar, ...] | Mapping[str, Scalar] | None = None,
158+
parse_dates: Container[str | Mapping[str, Any]] | Mapping[str, str | Mapping[str, Any]] | None = None,
159+
params: SupportsLenAndGetItem[Scalar] | Mapping[str, Scalar] | None = None,
155160
chunksize: None = None,
156161
) -> GeoDataFrame: ...
157162
@classmethod
@@ -245,7 +250,7 @@ class GeoDataFrame(GeoPandasBase, pd.DataFrame): # type: ignore[misc]
245250
layer: int | str | None = None,
246251
encoding: str | None = None,
247252
overwrite: bool | None = ...,
248-
**kwargs: Any, # engine and driver dependent
253+
**kwargs, # engine and driver dependent
249254
) -> None: ...
250255
@overload
251256
def set_crs(

stubs/geopandas-stubs/geoseries.pyi

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class GeoSeries(GeoPandasBase, pd.Series[BaseGeometry]): # type: ignore[type-va
6868
ignore_geometry: Literal[False] = False,
6969
layer: int | str | None = None,
7070
encoding: str | None = None,
71-
**kwargs: Any, # engine dependent
71+
**kwargs, # engine dependent
7272
) -> GeoSeries: ...
7373
@classmethod
7474
def from_wkb(
@@ -143,7 +143,7 @@ class GeoSeries(GeoPandasBase, pd.Series[BaseGeometry]): # type: ignore[type-va
143143
layer: int | str | None = None,
144144
encoding: str | None = None,
145145
overwrite: bool | None = ...,
146-
**kwargs: Any, # engine and driver dependent
146+
**kwargs, # engine and driver dependent
147147
) -> None: ...
148148
# *** TODO: compare `__getitem__` with pandas-stubs ***
149149
# def __getitem__(self, key): ...
@@ -195,9 +195,9 @@ class GeoSeries(GeoPandasBase, pd.Series[BaseGeometry]): # type: ignore[type-va
195195
cls: type[json.JSONEncoder] | None = None,
196196
indent: None | int | str = None,
197197
separators: tuple[str, str] | None = None,
198-
default: Callable[[Any], Any] | None = None,
198+
default: Callable[..., Any] | None = None, # as typed in the json stdlib module
199199
sort_keys: bool = False,
200-
**kwds: Any,
200+
**kwds,
201201
) -> str: ...
202202
@overload
203203
def to_wkb(self, hex: Literal[False] = False, **kwargs) -> pd.Series[bytes]: ...

stubs/geopandas-stubs/io/file.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def _read_file(
3636
ignore_geometry: Literal[True],
3737
layer: int | str | None = None,
3838
encoding: str | None = None,
39-
**kwargs: Any, # depends on engine
39+
**kwargs: Any, # depend on engine
4040
) -> pd.DataFrame: ...
4141

4242
class _Schema(TypedDict):

stubs/geopandas-stubs/io/sql.pyi

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sqlite3
2-
from collections.abc import Iterator, Mapping
2+
from _typeshed import SupportsLenAndGetItem
3+
from collections.abc import Container, Iterator, Mapping
34
from contextlib import AbstractContextManager
45
from typing import Any, Protocol, overload
56
from typing_extensions import TypeAlias
@@ -79,10 +80,10 @@ def _read_postgis(
7980
con: _SQLConnection,
8081
geom_col: str = "geom",
8182
crs: _ConvertibleToCRS | None = None,
82-
index_col: str | list[str] | None = None,
83+
index_col: str | Container[str] | None = None,
8384
coerce_float: bool = True,
84-
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = None,
85-
params: list[Scalar] | tuple[Scalar, ...] | Mapping[str, Scalar] | None = None,
85+
parse_dates: Container[str | Mapping[str, Any]] | Mapping[str, str | Mapping[str, Any]] | None = None,
86+
params: SupportsLenAndGetItem[Scalar] | Mapping[str, Scalar] | None = None,
8687
*,
8788
chunksize: int,
8889
) -> Iterator[GeoDataFrame]: ...
@@ -92,10 +93,10 @@ def _read_postgis(
9293
con: _SQLConnection,
9394
geom_col: str = "geom",
9495
crs: _ConvertibleToCRS | None = None,
95-
index_col: str | list[str] | None = None,
96+
index_col: str | Container[str] | None = None,
9697
coerce_float: bool = True,
97-
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = None,
98-
params: list[Scalar] | tuple[Scalar, ...] | Mapping[str, Scalar] | None = None,
98+
parse_dates: Container[str | Mapping[str, Any]] | Mapping[str, str | Mapping[str, Any]] | None = None,
99+
params: SupportsLenAndGetItem[Scalar] | Mapping[str, Scalar] | None = None,
99100
chunksize: None = None,
100101
) -> GeoDataFrame: ...
101102
@overload
@@ -104,9 +105,9 @@ def _read_postgis(
104105
con: _SQLConnection,
105106
geom_col: str = "geom",
106107
crs: _ConvertibleToCRS | None = None,
107-
index_col: str | list[str] | None = None,
108+
index_col: str | Container[str] | None = None,
108109
coerce_float: bool = True,
109-
parse_dates: list[str] | dict[str, str] | dict[str, dict[str, Any]] | None = None,
110-
params: list[Scalar] | tuple[Scalar, ...] | Mapping[str, Scalar] | None = None,
110+
parse_dates: Container[str | Mapping[str, Any]] | Mapping[str, str | Mapping[str, Any]] | None = None,
111+
params: SupportsLenAndGetItem[Scalar] | Mapping[str, Scalar] | None = None,
111112
chunksize: int | None = None,
112113
) -> GeoDataFrame | Iterator[GeoDataFrame]: ...

stubs/geopandas-stubs/plotting.pyi

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class GeoplotAccessor(PlotAccessor):
108108
mark_right: bool = True,
109109
include_bool: bool = False,
110110
backend: str | None = None,
111-
**kwargs,
111+
**kwargs: Any,
112112
) -> Axes: ...
113113
@overload
114114
def __call__(
@@ -150,7 +150,7 @@ class GeoplotAccessor(PlotAccessor):
150150
mark_right: bool = True,
151151
include_bool: bool = False,
152152
backend: str | None = None,
153-
**kwargs,
153+
**kwargs: Any,
154154
) -> NDArray[np.object_]: ... # should be NDArray[Axes] but it is not supported
155155
@overload
156156
def __call__(
@@ -192,7 +192,7 @@ class GeoplotAccessor(PlotAccessor):
192192
mark_right: bool = True,
193193
include_bool: bool = False,
194194
backend: str | None = None,
195-
**kwargs,
195+
**kwargs: Any,
196196
) -> pd.Series[Axes]: ... # type: ignore[type-var] # pyright: ignore[reportInvalidTypeArguments]
197197
@overload
198198
def __call__(

0 commit comments

Comments
 (0)