BUG: Use suffixes in sjoin's how==right branch (#2065)

* Use suffixes in how==right

* add tests

* slightly nicer formatting

* slightly nicer formatting

* add ,

* Update test_sjoin.py

* Update test_sjoin.py

Co-authored-by: Martin Fleischmann <martin@martinfleischmann.net>
This commit is contained in:
Adrian Garcia Badaracco
2021-08-23 22:08:14 +01:00
committed by GitHub
co-authored by Martin Fleischmann
parent befb2e88da
commit 7f486db671
2 changed files with 18 additions and 0 deletions
+1
View File
@@ -319,6 +319,7 @@ def _frame_join(indices, left_df, right_df, how, lsuffix, rsuffix):
left_index=True,
right_on="_key_left",
how="right",
suffixes=("_{}".format(lsuffix), "_{}".format(rsuffix)),
)
.set_index(index_right)
.drop(["_key_left", "_key_right"], axis=1)
+17
View File
@@ -89,6 +89,23 @@ def dfs(request):
class TestSpatialJoin:
@pytest.mark.parametrize(
"how, lsuffix, rsuffix, expected_cols",
[
("left", "left", "right", {"col_left", "col_right", "index_right"}),
("inner", "left", "right", {"col_left", "col_right", "index_right"}),
("right", "left", "right", {"col_left", "col_right", "index_left"}),
("left", "lft", "rgt", {"col_lft", "col_rgt", "index_rgt"}),
("inner", "lft", "rgt", {"col_lft", "col_rgt", "index_rgt"}),
("right", "lft", "rgt", {"col_lft", "col_rgt", "index_lft"}),
],
)
def test_suffixes(self, how: str, lsuffix: str, rsuffix: str, expected_cols):
left = GeoDataFrame({"col": [1], "geometry": [Point(0, 0)]})
right = GeoDataFrame({"col": [1], "geometry": [Point(0, 0)]})
joined = sjoin(left, right, how=how, lsuffix=lsuffix, rsuffix=rsuffix)
assert set(joined.columns) == expected_cols | set(("geometry",))
@pytest.mark.parametrize("dfs", ["default-index", "string-index"], indirect=True)
def test_crs_mismatch(self, dfs):
index, df1, df2, expected = dfs