venv
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
import warnings
|
||||
|
||||
import pandas as pd
|
||||
import pytest
|
||||
from geopandas.testing import assert_geodataframe_equal
|
||||
from pandas.testing import assert_index_equal
|
||||
|
||||
from shapely.geometry import Point
|
||||
|
||||
from geopandas import GeoDataFrame, GeoSeries
|
||||
from geopandas._compat import HAS_PYPROJ, PANDAS_GE_21
|
||||
|
||||
import pytest
|
||||
from geopandas.testing import assert_geodataframe_equal
|
||||
from pandas.testing import assert_index_equal
|
||||
|
||||
|
||||
class TestMerging:
|
||||
@@ -59,6 +61,7 @@ class TestMerging:
|
||||
assert isinstance(res, GeoSeries)
|
||||
assert isinstance(res.geometry, GeoSeries)
|
||||
|
||||
@pytest.mark.skipif(not HAS_PYPROJ, reason="pyproj not available")
|
||||
def test_concat_axis0_crs(self):
|
||||
# CRS not set for both GeoDataFrame
|
||||
res = pd.concat([self.gdf, self.gdf])
|
||||
@@ -100,6 +103,7 @@ class TestMerging:
|
||||
[self.gdf, self.gdf.set_crs("epsg:4326"), self.gdf.set_crs("epsg:4327")]
|
||||
)
|
||||
|
||||
@pytest.mark.skipif(not HAS_PYPROJ, reason="pyproj not available")
|
||||
def test_concat_axis0_unaligned_cols(self):
|
||||
# https://github.com/geopandas/geopandas/issues/2679
|
||||
gdf = self.gdf.set_crs("epsg:4326").assign(
|
||||
@@ -133,6 +137,40 @@ class TestMerging:
|
||||
partial_none_case.iloc[0] = None
|
||||
pd.concat([single_geom_col, partial_none_case])
|
||||
|
||||
def test_concat_axis0_crs_wkt_mismatch(self):
|
||||
pyproj = pytest.importorskip("pyproj")
|
||||
|
||||
# https://github.com/geopandas/geopandas/issues/326#issuecomment-1727958475
|
||||
wkt_template = """GEOGCRS["WGS 84",
|
||||
ENSEMBLE["World Geodetic System 1984 ensemble",
|
||||
MEMBER["World Geodetic System 1984 (Transit)"],
|
||||
MEMBER["World Geodetic System 1984 (G730)"],
|
||||
MEMBER["World Geodetic System 1984 (G873)"],
|
||||
MEMBER["World Geodetic System 1984 (G1150)"],
|
||||
MEMBER["World Geodetic System 1984 (G1674)"],
|
||||
MEMBER["World Geodetic System 1984 (G1762)"],
|
||||
MEMBER["World Geodetic System 1984 (G2139)"],
|
||||
ELLIPSOID["WGS 84",6378137,298.257223563,LENGTHUNIT["metre",1]],
|
||||
ENSEMBLEACCURACY[2.0]],PRIMEM["Greenwich",0,
|
||||
ANGLEUNIT["degree",0.0174532925199433]],CS[ellipsoidal,2],
|
||||
AXIS["geodetic latitude (Lat)",north,ORDER[1],
|
||||
ANGLEUNIT["degree",0.0174532925199433]],
|
||||
AXIS["geodetic longitude (Lon)",east,ORDER[2],
|
||||
ANGLEUNIT["degree",0.0174532925199433]],
|
||||
USAGE[SCOPE["Horizontal component of 3D system."],
|
||||
AREA["World.{}"],BBOX[-90,-180,90,180]],ID["EPSG",4326]]"""
|
||||
wkt_v1 = wkt_template.format("")
|
||||
wkt_v2 = wkt_template.format(" ") # add additional whitespace
|
||||
crs1 = pyproj.CRS.from_wkt(wkt_v1)
|
||||
crs2 = pyproj.CRS.from_wkt(wkt_v2)
|
||||
# pyproj crs __hash__ based on WKT strings means these are distinct in a
|
||||
# set are but equal by equality
|
||||
assert len({crs1, crs2}) == 2
|
||||
assert crs1 == crs2
|
||||
expected = pd.concat([self.gdf, self.gdf]).set_crs(crs1)
|
||||
res = pd.concat([self.gdf.set_crs(crs1), self.gdf.set_crs(crs2)])
|
||||
assert_geodataframe_equal(expected, res)
|
||||
|
||||
def test_concat_axis1(self):
|
||||
res = pd.concat([self.gdf, self.df], axis=1)
|
||||
|
||||
@@ -145,10 +183,18 @@ class TestMerging:
|
||||
# https://github.com/geopandas/geopandas/issues/1230
|
||||
# Expect that concat should fail gracefully if duplicate column names belonging
|
||||
# to geometry columns are introduced.
|
||||
expected_err = (
|
||||
"GeoDataFrame does not support multiple columns using the geometry"
|
||||
" column name 'geometry'"
|
||||
)
|
||||
if PANDAS_GE_21:
|
||||
# _constructor_from_mgr changes mean we now get the concat specific error
|
||||
# message in this case too
|
||||
expected_err = (
|
||||
"Concat operation has resulted in multiple columns using the geometry "
|
||||
"column name 'geometry'."
|
||||
)
|
||||
else:
|
||||
expected_err = (
|
||||
"GeoDataFrame does not support multiple columns using the geometry"
|
||||
" column name 'geometry'"
|
||||
)
|
||||
with pytest.raises(ValueError, match=expected_err):
|
||||
pd.concat([self.gdf, self.gdf], axis=1)
|
||||
|
||||
@@ -161,10 +207,11 @@ class TestMerging:
|
||||
with pytest.raises(ValueError, match=expected_err2):
|
||||
pd.concat([df2, df2], axis=1)
|
||||
|
||||
# Check that two geometry columns is fine, if they have different names
|
||||
res3 = pd.concat([df2.set_crs("epsg:4326"), self.gdf], axis=1)
|
||||
# check metadata comes from first df
|
||||
self._check_metadata(res3, geometry_column_name="geom", crs="epsg:4326")
|
||||
if HAS_PYPROJ:
|
||||
# Check that two geometry columns is fine, if they have different names
|
||||
res3 = pd.concat([df2.set_crs("epsg:4326"), self.gdf], axis=1)
|
||||
# check metadata comes from first df
|
||||
self._check_metadata(res3, geometry_column_name="geom", crs="epsg:4326")
|
||||
|
||||
@pytest.mark.filterwarnings("ignore:Accessing CRS")
|
||||
def test_concat_axis1_geoseries(self):
|
||||
|
||||
Reference in New Issue
Block a user