Skip to content

Pytest potential bug case - parameter not passed to a function #21532

@DeflateAwning

Description

@DeflateAwning

Summary

Consider the following test case. I started off without any parameters, then added the keep_right_geometry parameter.

When I added it, I added it to the if keep_right_geometry part, but forgot to add it to the function called.

Not certain if there's a rule that can be made out of this (and it would almost certainly have to be ignored sometimes, as not ALL parameters are used as direct inputs to a function call).

@pytest.mark.parametrize("keep_right_geometry", [True, False])
def test_spacial_join_WITH_different_col_names(keep_right_geometry: bool) -> None:
    box1 = shapely.geometry.box(1, 1, 10, 10).wkt  # Intersects box2
    box2 = shapely.geometry.box(5, 5, 15, 15).wkt  # Intersects box1. contains box3
    box3 = shapely.geometry.box(-5, -5, 0, 0).wkt  # Does not intersect any other box.
    box4 = shapely.geometry.box(11, 11, 14, 14).wkt  # contained in box2.

    df1 = pl.DataFrame({"name_1": ["box1", "box2", "box4"], "geometry_1": [box1, box2, box4]})
    df2 = pl.DataFrame({"name_2": ["box2", "box3", "box4"], "geometry_2": [box2, box3, box4]})

    result_df = spacial_join(
        df1,
        df2,
        left_on="geometry_1",
        right_on="geometry_2",
        where="intersects",
        how="inner",
        keep_right_geometry=keep_right_geometry, # <- I forgot to add this line for 25 minutes of debugging.
    )
    expected_df = pl.DataFrame(
        {
            "name_1": ["box1", "box2", "box2", "box4", "box4"],
            "geometry_1": [box1, box2, box2, box4, box4],
            "name_2": ["box2", "box2", "box4", "box2", "box4"],
            "geometry_2": [box2, box2, box4, box2, box4],
        }
    )

    if keep_right_geometry is False:
        expected_df = expected_df.drop("geometry_2")

    assert_frame_equal(result_df, expected_df)

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionAsking for support or clarification

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions