OntodockerClient: Refactor query_df()#32
Closed
mbruns91 wants to merge 9 commits intoontodocker_clientfrom
Closed
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## ontodocker_client #32 +/- ##
=====================================================
- Coverage 90.20% 89.97% -0.23%
=====================================================
Files 17 17
Lines 449 449
=====================================================
- Hits 405 404 -1
- Misses 44 45 +1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
There was a problem hiding this comment.
Pull request overview
Refactors OntodockerClient.sparql.query_df() to reuse the internal HTTP-based query_raw() pathway (removing the prior SPARQLWrapper-based approach) and updates result-to-DataFrame compatibility behavior and tests accordingly.
Changes:
- Reimplemented
SparqlResource.query_df()to callquery_raw()andjson.loads()the response. - Updated
_compat.make_dataframe()to build rows by requestedcolumnsand yieldNonefor missing variables. - Adjusted unit tests to assert HTTP GET usage/headers and the new missing-variable behavior.
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 |
query_df() now reuses query_raw() and decodes SPARQL results JSON directly. |
courier/services/ontodocker/_compat.py |
DataFrame construction now follows requested column order and fills missing bindings with None. |
tests/unit/test_ontodocker_client.py |
Updates query_df() test to validate GET/params/Accept header behavior and token handling via session headers. |
tests/unit/services/ontodocker/test_compat.py |
Updates expectation for missing variables in bindings to yield None instead of raising. |
Comments suppressed due to low confidence (1)
courier/services/ontodocker/_compat.py:123
make_dataframe()now fills missing variables in a binding withNoneinstead of raising due to row/column length mismatch. The docstring doesn't mention this behavioral change, which is important for callers interpreting missing data. Consider documenting that missing binding entries for requestedcolumnsyieldNone(or NA).
def make_dataframe(result: dict, columns: list[str]) -> pd.DataFrame:
"""Convert a SPARQL JSON result into a pandas DataFrame.
Parameters
----------
result
SPARQL JSON result containing `result["results"]["bindings"]`.
columns
Column labels for the resulting DataFrame.
Returns
-------
df
DataFrame containing one row per binding.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…ng ValueError, dataset trimming and hanling of missing bindings
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refactor
OntodockerClient.query_df()to re-usequery_raw()instead of using its own Implementation.This way, we also get rid of
SPARQLWrapperas dependency.