Skip to content

Add regression test for read_file GeoDataFrame return type (#1186)#1339

Open
vickysharma-prog wants to merge 2 commits intoweecology:mainfrom
vickysharma-prog:fix-read-file-geodataframe-1186
Open

Add regression test for read_file GeoDataFrame return type (#1186)#1339
vickysharma-prog wants to merge 2 commits intoweecology:mainfrom
vickysharma-prog:fix-read-file-geodataframe-1186

Conversation

@vickysharma-prog
Copy link
Contributor

@vickysharma-prog vickysharma-prog commented Mar 6, 2026

Description

Adds a regression test for #1186 to ensure read_file() returns a proper GeoDataFrame when passed a pandas DataFrame with an existing geometry column.

Background

Issue #1186 reported that read_file() was returning a pandas DataFrame with shapely geometry column instead of a proper GeoDataFrame. This prevented use of GeoDataFrame methods like .intersects() required by preprocess.split_raster.

The bug was fixed by @bw4sz in commit 6f0aca1 (Refactor read_file - #1042). The refactor introduced DeepForest_DataFrame which properly inherits from GeoDataFrame. However, the specific regression test requested in #1186 was not added.

This PR adds that test to prevent future regressions.

Test Coverage

Test Case 1: DataFrame with WKT string geometry -> Verifies GeoDataFrame + GeoSeries
Test Case 2: DataFrame with shapely geometry objects -> Verifies GeoDataFrame + GeoSeries

Assertions:

  • isinstance(result, gpd.GeoDataFrame)
  • isinstance(result.geometry, gpd.GeoSeries)
  • geometry column exists
  • All geometries are Polygons

Related Issue(s)

Closes #1186

AI-Assisted Development

  • I used AI tools (e.g., GitHub Copilot, ChatGPT, etc.) in developing this PR
  • I understand all the code I'm submitting
  • I have reviewed and validated all AI-generated code
    AI tools used (if applicable):
    AI tools used for initial research and understanding the codebase better. All code was written and verified manually.

@codecov
Copy link

codecov bot commented Mar 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 87.34%. Comparing base (ecf3a1c) to head (810be7e).
⚠️ Report is 7 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1339   +/-   ##
=======================================
  Coverage   87.34%   87.34%           
=======================================
  Files          24       24           
  Lines        2978     2978           
=======================================
  Hits         2601     2601           
  Misses        377      377           
Flag Coverage Δ
unittests 87.34% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@henrykironde henrykironde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will leave this to Ben to have a look


assert isinstance(result_wkt, gpd.GeoDataFrame)
assert isinstance(result_wkt.geometry, gpd.GeoSeries)
assert 'geometry' in result_wkt.columns
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably want to move this statement

assert 'geometry' in result_wkt.columns

above

assert isinstance(result_wkt.geometry, gpd.GeoSeries)

@vickysharma-prog
Copy link
Contributor Author

vickysharma-prog commented Mar 7, 2026

Thanks @henrykironde @bw4sz ! Fixed the assertion order in both test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enforce that read_file returns geopandas dataframe if a pandas df and a geometry column is present.

2 participants