Skip to content

Refactor sparql.query_df() to use query_raw#36

Merged
mbruns91 merged 14 commits intomainfrom
refactor/query_df
Mar 26, 2026
Merged

Refactor sparql.query_df() to use query_raw#36
mbruns91 merged 14 commits intomainfrom
refactor/query_df

Conversation

@mbruns91
Copy link
Copy Markdown
Contributor

@mbruns91 mbruns91 commented Mar 26, 2026

  • Rework SparqlResource.query_df() to fetch JSON via query_raw() instead of SPARQLWrapper
  • Tighten query_df() validation for dataset, query, and columns
  • Preserve requested column order and handle missing bindings consistently in DataFrame conversion
  • Update unit tests to cover invalid JSON, dataset trimming, missing bindings, and column validation
  • Improve testing by adding
    • a delegation test for query_df()
    • verification that invalid columns prevent any call to query_raw()

@github-actions
Copy link
Copy Markdown

Binder 👈 Launch a binder notebook on branch pyiron/courier/refactor/query_df

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 26, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.78%. Comparing base (7fb637b) to head (62e213d).
⚠️ Report is 19 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #36      +/-   ##
==========================================
- Coverage   90.20%   89.78%   -0.43%     
==========================================
  Files          17       17              
  Lines         429      421       -8     
==========================================
- Hits          387      378       -9     
- Misses         42       43       +1     

☔ 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
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Refactors Ontodocker SPARQL DataFrame querying to reuse the existing HTTP-based query_raw() flow (instead of SPARQLWrapper), while tightening input validation and improving DataFrame column/binding handling.

Changes:

  • Reworked SparqlResource.query_df() to call query_raw() and decode SPARQL results from JSON text.
  • Strengthened validation for dataset, query, and columns, and ensured stable column ordering with consistent missing-binding handling.
  • Updated/expanded unit tests for invalid JSON, dataset trimming, missing bindings, and request construction (params/headers/auth).

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
courier/services/ontodocker/sparql.py Refactors query_df() to fetch via query_raw() and adds stricter validation + JSON decoding error handling.
courier/services/ontodocker/_compat.py Minor cleanup in make_dataframe() implementation/docstring while keeping missing bindings mapped to None.
tests/unit/test_ontodocker_client.py Updates SPARQL resource tests to assert GET+params+Accept behavior, dataset trimming, invalid JSON handling, and token via session headers.
tests/unit/services/ontodocker/test_compat.py Adjusts dataframe compatibility test to assert missing variables yield None consistently.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@mbruns91
Copy link
Copy Markdown
Contributor Author

mbruns91 commented Mar 26, 2026

Coverage was lowered by 0928119 and e98d786, so I improved unit test coverage in 30205e7:

  • Added a delegation test for query_df() that patches query_raw() and verifies:
    • query_df() passes through the raw dataset and query inputs unchanged
    • it uses accept="application/sparql-results+json"
    • it still returns the expected DataFrame from the mocked JSON payload
  • Added a short-circuit test that verifies invalid columns prevents any call to query_raw()

@mbruns91 mbruns91 merged commit 8a6ade2 into main Mar 26, 2026
19 of 20 checks passed
@samwaseda samwaseda deleted the refactor/query_df branch March 26, 2026 14:37
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.

3 participants