Skip to content

Add demo test for multioutput_reduced_gradient.py - #12397

Open
Nityahapani wants to merge 1 commit into
dmlc:masterfrom
Nityahapani:test/multioutput-reduced-gradient-demo
Open

Add demo test for multioutput_reduced_gradient.py#12397
Nityahapani wants to merge 1 commit into
dmlc:masterfrom
Nityahapani:test/multioutput-reduced-gradient-demo

Conversation

@Nityahapani

Copy link
Copy Markdown
Contributor

Add demo test for multioutput_reduced_gradient.py

Summary

test_demos.py runs most demo scripts as a real subprocess smoke test.
multioutput_reduced_gradient.py had no coverage. This is genuinely the
only thing exercising xgboost.objective.TreeObjective at all (grepped
tests/python/*.py for both the script name and TreeObjective directly —
zero hits either way), so this is the sole safety net for that experimental
feature, not just a routine smoke test.

Change

+@pytest.mark.skipif(**tm.no_sklearn())
+def test_multioutput_reduced_gradient_demo() -> None:
+    # Runs with the default `--device cpu`; `cupy` is only imported on the
+    # (unused here) `--device cuda` code paths.
+    script = os.path.join(PYTHON_DEMO_DIR, "multioutput_reduced_gradient.py")
+    cmd = [PYTHON, script]
+    subprocess.check_call(cmd)

Verification

  • Runs with the script's default --device cpu (no args needed)
  • Its three import cupy statements are all inside else branches gated on
    self.device == "cpu" checks — confirmed by reading each one's
    surrounding context directly — so none of them execute on this path, no
    cupy/GPU dependency for this test
  • no_sklearn() skip marker matches every other sklearn-dependent test in
    this file (the script uses sklearn.datasets.make_regression,
    sklearn.base.BaseEstimator, and sklearn.decomposition.TruncatedSVD,
    all part of core scikit-learn, no extra dependency)

I also checked the other 8 demo scripts currently missing test coverage
(cat_in_the_dat.py, cover_type.py, gamma_regression.py,
gpu_tree_shap.py, learning_to_rank.py, quantile_data_iterator.py,
spark_estimator_examples.py, update_process.py) and confirmed each is
correctly excluded for a real reason (local-only data files, GPU/RAPIDS
dependencies, a large external ranking dataset, or pyspark) — not further
oversights, so this PR is scoped to just the one genuine gap.

test_demos.py runs most demo scripts as a real subprocess smoke test.
multioutput_reduced_gradient.py had no coverage; this is the only
thing exercising xgboost.objective.TreeObjective at all (grepped
tests/python/*.py for both the script name and TreeObjective directly
-- zero hits either way), so this is genuinely the sole safety net
for that experimental feature, not just a routine smoke test.

Verified this is a real gap and not another false positive like my
earlier mistake with prediction_intervals.py: re-ran the demo-vs-test
comparison from scratch on a clean master checkout with a more robust
grep pattern, and separately grepped the test file directly for both
the script's filename and its actual class names (TreeObjective,
LsObjMean, LsObjSvd) to be sure.

Runs with the script's default `--device cpu` (no args needed). Its
three `import cupy` statements are all inside `else` branches gated
on `self.device == "cpu"` checks (confirmed by reading each one's
surrounding context directly), so none of them execute on this path
-- no cupy/GPU dependency for this test.

`no_sklearn()` skip marker matches every other sklearn-dependent test
in this file (the script uses sklearn.datasets.make_regression,
sklearn.base.BaseEstimator, and sklearn.decomposition.TruncatedSVD,
all part of core scikit-learn, no extra dependency).
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.

1 participant