From 026d428ca0a804db24deb357e284744a4278bcee Mon Sep 17 00:00:00 2001 From: Joris Van den Bossche Date: Sun, 26 Feb 2023 14:05:22 +0100 Subject: [PATCH] TST: selecting multiple columns copies GeometryArray with pandas >= 2.0, losing sindex (#2803) --- geopandas/tests/test_sindex.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/geopandas/tests/test_sindex.py b/geopandas/tests/test_sindex.py index eca7242..e9d2e8e 100644 --- a/geopandas/tests/test_sindex.py +++ b/geopandas/tests/test_sindex.py @@ -169,11 +169,19 @@ class TestFrameSindex: def test_rebuild_on_multiple_col_selection(self): """Selecting a subset of columns preserves the index.""" original_index = self.df.sindex - # Selecting a subset of columns preserves the index + # Selecting a subset of columns preserves the index for pandas < 2.0 + # with pandas 2.0, the column is now copied, losing the index (although + # with Copy-on-Write, this will again be preserved) subset1 = self.df[["geom", "A"]] - assert subset1.sindex is original_index + if compat.PANDAS_GE_20: + assert subset1.sindex is not original_index + else: + assert subset1.sindex is original_index subset2 = self.df[["A", "geom"]] - assert subset2.sindex is original_index + if compat.PANDAS_GE_20: + assert subset2.sindex is not original_index + else: + assert subset2.sindex is original_index def test_rebuild_on_update_inplace(self): gdf = self.df.copy()