From 17fe21ed15442d2cd30bd3d39171e1e6e2b44b68 Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Fri, 12 Nov 2021 00:49:12 +0100 Subject: [PATCH] TST/COMPAT: update GeometryArray getitem error type + fix tests (#2219) * TST/COMPAT: update GeometryArray getitem error type + fix tests * fix doctest for GEOS 3.10 --- geopandas/array.py | 11 +++++++---- geopandas/tests/test_extension_array.py | 12 ++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/geopandas/array.py b/geopandas/array.py index 0532c08..fd7b7fc 100644 --- a/geopandas/array.py +++ b/geopandas/array.py @@ -363,10 +363,12 @@ class GeometryArray(ExtensionArray): # for pandas >= 1.0, validate and convert IntegerArray/BooleanArray # to numpy array, pass-through non-array-like indexers idx = pd.api.indexers.check_array_indexer(self, idx) - if isinstance(idx, (Iterable, slice)): return GeometryArray(self.data[idx], crs=self.crs) else: - raise TypeError("Index type not supported", idx) + if isinstance(idx, (Iterable, slice)): + return GeometryArray(self.data[idx], crs=self.crs) + else: + raise TypeError("Index type not supported", idx) def __setitem__(self, key, value): if compat.PANDAS_GE_10: @@ -740,8 +742,9 @@ class GeometryArray(ExtensionArray): >>> a = a.to_crs(3857) >>> to_wkt(a) - array(['POINT (111319 111325)', 'POINT (222639 222684)', - 'POINT (333958 334111)'], dtype=object) + array(['POINT (111319.490793 111325.142866)', + 'POINT (222638.981587 222684.208506)', + 'POINT (333958.47238 334111.171402)'], dtype=object) >>> a.crs # doctest: +SKIP Name: WGS 84 / Pseudo-Mercator diff --git a/geopandas/tests/test_extension_array.py b/geopandas/tests/test_extension_array.py index 6e1205b..9582404 100644 --- a/geopandas/tests/test_extension_array.py +++ b/geopandas/tests/test_extension_array.py @@ -231,6 +231,18 @@ def as_array(request): return request.param +@pytest.fixture +def invalid_scalar(data): + """ + A scalar that *cannot* be held by this ExtensionArray. + + The default should work for most subclasses, but is not guaranteed. + + If the array can hold any item (i.e. object dtype), then use pytest.skip. + """ + return object.__new__(object) + + # Fixtures defined in pandas/conftest.py that are also needed: defining them # here instead of importing for compatibility