feat: allow predict_file to accept pandas DataFrame instead of only C… - #1409
feat: allow predict_file to accept pandas DataFrame instead of only C…#1409proofbyhuman wants to merge 3 commits into
Conversation
…l sites Addresses review feedback on weecology#1409. - FromCSVFile.prepare_items called read_file without root_dir. That worked while csv_file was always a path, because read_file infers the root from the file's directory, but this PR also accepts DataFrames, where there is no path to infer from. predict_file(input_file=df, root_dir=...) then failed with "root_dir argument not specified and input is a dataframe". Forward root_dir so the argument is honoured. - Update the remaining predict_file call sites to input_file, including scripts/predict.py and the user guide. Two of them passed the file positionally, so they silently rebound to input_file without warning. test_predict_file_deprecated_csv_file keeps csv_file on purpose, since it asserts the DeprecationWarning is raised. - root_dir docstring promised a fallback to "image_dir" in config, but no such key exists. Describe what actually happens instead. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
|
Both points addressed. Call sites. All 13 are updated — the 11 keyword ones (
While updating the call sites I hit the bug that was actually breaking the DataFrame path: Local runs on this branch: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1409 +/- ##
==========================================
+ Coverage 86.61% 86.67% +0.05%
==========================================
Files 26 28 +2
Lines 3736 4075 +339
==========================================
+ Hits 3236 3532 +296
- Misses 500 543 +43
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Description
This PR resolves issue #797 by allowing the
predict_filemethod to accept a pandas DataFrame directly, in addition to CSV file paths.Changes Made:
src/deepforest/main.py: Renamed the primary argument fromcsv_filetoinput_file. Addedcsv_fileas an optional deprecated argument with aDeprecationWarningto maintain backward compatibility.src/deepforest/datasets/prediction.py: Updated theFromCSVFileclass__init__type hint to acceptstr | pd.DataFrame, removing the previous restriction that forced the input to be a string.Why this works:
The downstream function
utilities.read_filealready natively supports bothstrandpd.DataFrameinputs. This change simply removes the unnecessary type restriction at the entry point, fulfilling the feature request without altering the core processing logic.Testing:
Local environment constraints prevented running the full test suite locally, but the changes are minimal and strictly type-hint/deprecation additions. GitHub Actions will verify that existing tests continue to pass.
Related Issue(s)
Closes #797
AI-Assisted Development
AI tools used (if applicable):