Skip to content

Fix #1034: Set default outcome learner and replace assertions with ValueErrors - #1039

Open
su-jin1425 wants to merge 1 commit into
uber:masterfrom
su-jin1425:fix-issue-1034
Open

Fix #1034: Set default outcome learner and replace assertions with ValueErrors#1039
su-jin1425 wants to merge 1 commit into
uber:masterfrom
su-jin1425:fix-issue-1034

Conversation

@su-jin1425

Copy link
Copy Markdown
Contributor

Proposed changes

Fixes #1034.

This PR updates rlearner_score to use a default LGBMRegressor when an outcome learner is not provided. This allows users to call rlearner_score with X without having to manually provide an outcome learner.

It also replaces input validation assert statements with ValueError exceptions in the CATE scoring functions. This ensures validation errors are raised consistently, including when Python is run with optimization enabled.

Before

image

After

image

Test

Before

git checkout --detach 9a2327811406240925e9b8c0ce16734a04da52d7

@'
import warnings
warnings.filterwarnings("ignore")

import inspect
import pandas as pd
import numpy as np
from causalml.metrics import rlearner_score

X = pd.DataFrame({"x": np.arange(100)})
df = pd.DataFrame({
    "y": np.arange(100, dtype=float),
    "w": [0, 1] * 50
})

default = inspect.signature(rlearner_score).parameters["outcome_learner"].default

print("=== BEFORE ===")
print("COMMIT: 9a2327811406240925e9b8c0ce16734a04da52d7")
print("outcome_learner default:", default)

try:
    rlearner_score(
        df,
        X=X,
        outcome_col="y",
        treatment_col="w"
    )
    print("RESULT: UNEXPECTED SUCCESS")
except AssertionError:
    print("RESULT: AssertionError - ISSUE REPRODUCED")
'@ | python -

After

git checkout --detach 06510496d77480c23ab49549bc677971fd5410f8

@'
import warnings
warnings.filterwarnings("ignore")

import inspect
import pandas as pd
import numpy as np
from causalml.metrics import rlearner_score

X = pd.DataFrame({"x": np.arange(100)})
df = pd.DataFrame({
    "y": np.arange(100, dtype=float),
    "w": [0, 1] * 50
})

default = inspect.signature(rlearner_score).parameters["outcome_learner"].default

print("=== AFTER ===")
print("COMMIT: 06510496d77480c23ab49549bc677971fd5410f8")
print("outcome_learner default:", default)

try:
    rlearner_score(
        df,
        X=X,
        outcome_col="y",
        treatment_col="w"
    )
    print("RESULT: SUCCESS - ISSUE #1034 FIXED")
except Exception as e:
    print("RESULT: FAILED")
    print(type(e).__name__, e)
'@ | python -

Changes

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update (if none of the other choices apply)

Checklist

  • I have read the CONTRIBUTING doc
  • I have signed the CLA
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in downstream modules

Further comments

The previous implementation used assert for user input validation. Since assertions can be disabled with Python's -O option, these checks were changed to explicit ValueError exceptions.

The rlearner_score change also provides a default outcome learner so that the documented usage with X works without requiring users to explicitly construct and pass an outcome learner.

Copilot AI balanced review requested due to automatic review settings August 28, 2026 07:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

rlearner_score still requires outcome_learner while its siblings default to LightGBM

2 participants