Skip to content

fix: scitype-correct export_code examples, is_pipeline, dataset, loaded models (#534) - #547

Open
Shashankss1205 wants to merge 1 commit into
mainfrom
fix/534-export-code
Open

fix: scitype-correct export_code examples, is_pipeline, dataset, loaded models (#534)#547
Shashankss1205 wants to merge 1 commit into
mainfrom
fix/534-export-code

Conversation

@Shashankss1205

Copy link
Copy Markdown
Collaborator

Fixes #534.

Four export_code defects (the string-escaping one, BUG-02, was already fixed in #518):

BUG-03 — fit example was forecaster-shaped for every scitype

export_code(handle, include_fit_example=true) always emitted fit(y) / predict(fh), so running the generated code raised AttributeError for transformers (no predict), splitters (no fit), and classifiers. The example now branches on object_type:

  • transformer → fit_transform(y)
  • splitter → iterate split(y)
  • classifier/regressor → fit(X, y) / predict(X)
  • forecaster → fit(y) / predict(fh)

All four generated examples are executed in the tests.

BUG-04 — is_pipeline false-positived on any list argument

is_pipeline = ... or "[" in spec flagged e.g. SlidingWindowSplitter(fh=[1,2,3]) as a pipeline. Now derived from the instance: a craft * in the spec or hasattr(instance, "steps").

NB-15 — dataset argument ignored; unknown names silently used airline

The dataset param is now honoured, and an unknown dataset is rejected with a clear error (rather than silently falling back to load_airline).

NB-17 — loaded models couldn't be exported

load_model handles carry no craft spec, so export failed with "No craft spec found". They now emit a runnable load_model("<path>") snippet built from the handle metadata.

Testing

  • New tests/test_export_code_scitype.py (11 tests): is_pipeline true/false cases; exec of the generated example for forecaster/transformer/splitter/classifier; unknown-dataset rejected and known-dataset (lynx) used; loaded-model handle emits a load_model snippet.
  • Full suite: 275 passed.

🤖 Generated with Claude Code

…ed models (#534)

- BUG-03: the fit example was forecaster-shaped for every scitype, so running
  the generated code for a transformer/splitter/classifier raised
  AttributeError. Branch the example on object_type: transformers get
  fit_transform, splitters iterate split(), classifiers/regressors get
  fit(X, y)/predict(X), forecasters keep fit(y)/predict(fh). All four generated
  examples now execute.
- BUG-04: is_pipeline used "[" in spec, false-positiving on any list argument.
  Derive it from the instance instead (spec "*" operator or hasattr steps).
- NB-15: the dataset argument was ignored and unknown names silently fell back
  to airline. Honour it, and reject an unknown dataset with a clear error.
- NB-17: loaded models carry no craft spec and failed with "No craft spec
  found". Emit a runnable load_model(path) snippet from the handle metadata.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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] export_code: forecaster-shaped fit example for all scitypes, is_pipeline false-positives, ignored dataset param, fails on loaded models

1 participant