Skip to content

OntodockerClient: Refactor query_df()#32

Closed
mbruns91 wants to merge 9 commits intoontodocker_clientfrom
refactor_query_df
Closed

OntodockerClient: Refactor query_df()#32
mbruns91 wants to merge 9 commits intoontodocker_clientfrom
refactor_query_df

Conversation

@mbruns91
Copy link
Copy Markdown
Contributor

Refactor OntodockerClient.query_df() to re-use query_raw() instead of using its own Implementation.
This way, we also get rid of SPARQLWrapper as dependency.

@github-actions
Copy link
Copy Markdown

Binder 👈 Launch a binder notebook on branch pyiron/courier/refactor_query_df

@mbruns91 mbruns91 requested a review from samwaseda March 19, 2026 13:34
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 19, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 89.97%. Comparing base (d8df495) to head (34da671).

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.
📢 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 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 call query_raw() and json.loads() the response.
  • Updated _compat.make_dataframe() to build rows by requested columns and yield None for 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 with None instead 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 requested columns yield None (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.

Comment thread courier/services/ontodocker/sparql.py
Comment thread courier/services/ontodocker/sparql.py
@mbruns91 mbruns91 marked this pull request as draft March 25, 2026 11:11
@mbruns91 mbruns91 deleted the branch ontodocker_client March 26, 2026 10:25
@mbruns91 mbruns91 closed this Mar 26, 2026
@mbruns91 mbruns91 deleted the refactor_query_df branch March 26, 2026 10:26
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.

2 participants