Skip to content

fix(runs): support string setup_string in OpenMLTraceIteration.get_parameters() - #1794

Open
shellyco-code wants to merge 1 commit into
openml:mainfrom
shellyco-code:fix/trace-iteration-get-parameters
Open

shellyco-code wants to merge 1 commit into
openml:mainfrom
shellyco-code:fix/trace-iteration-get-parameters

Conversation

@shellyco-code

Copy link
Copy Markdown
Contributor

Metadata

Details

  • What does this PR implement/fix? Explain your changes.

    1. In OpenMLTraceIteration.get_parameters(): Added support for setup_string when passed as a JSON string (deserializing with json.loads) as well as dictionary formats, safely extracting parameter values.
    2. Updated setup_string type annotation to str | dict[str, Any] | None = None and updated docstrings for both setup_string and parameters to align with current typing.
    3. Corrected TypeError message in __post_init__ to state dict instead of outdated OrderedDict, and added validation for setup_string.
    4. Added unit tests in tests/test_runs/test_trace.py covering string JSON parsing, dict inputs, error cases, and OpenMLRunTrace.trace_to_arff() integration.
  • Why is this change necessary? What is the problem it solves?
    OpenMLTraceIteration documents setup_string as a JSON string, and unit tests initialize it as such. However, get_parameters() previously called .items() directly on self.setup_string, which immediately raised AttributeError: 'str' object has no attribute 'items' and broke downstream trace exports (such as trace_to_arff()).

  • How can I reproduce the issue this PR is solving and its solution?
    Run the new test cases:

    pytest tests/test_runs/test_trace.py -k "test_trace_iteration"
  • Any other comments?
    All pre-commit hooks (ruff, ruff format, mypy) and unit tests pass cleanly.

…rameters()

- Deserialize JSON string setup_string in get_parameters() before extracting parameters
- Support both str and dict inputs for setup_string and update type hints
- Correct TypeError message in __post_init__ to reference dict instead of OrderedDict
- Add unit tests for get_parameters() with JSON strings, dicts, and invalid types

Signed-off-by: Shelly Chahar <shellychahar57@gmail.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 4.16667% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 49.30%. Comparing base (ccb5244) to head (85a536a).

Files with missing lines Patch % Lines
openml/runs/trace.py 4.16% 23 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1794      +/-   ##
==========================================
- Coverage   49.48%   49.30%   -0.19%     
==========================================
  Files          63       63              
  Lines        5565     5586      +21     
==========================================
  Hits         2754     2754              
- Misses       2811     2832      +21     

☔ View full report in Codecov by Harness.
📢 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.

This branch has not been deployed

No deployments
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.

[BUG] OpenMLTraceIteration.get_parameters() crashes with AttributeError when setup_string is a string

2 participants