Skip to content

Conversation

Copy link

Copilot AI commented Jan 15, 2026

The parametrize_with_checks_slow decorator was incompatible with sklearn 1.8.0+ which removed the generate_only parameter, causing TypeError: got an unexpected keyword argument 'generate_only' in CI tests while still needing to support sklearn 1.4.2 (legacy).

Changes

  • Version Detection: Added runtime detection using inspect.signature() to check sklearn API compatibility
  • Dual API Support:
    • sklearn ≤ 1.4.x: Uses check_estimator(estimator, generate_only=True)
    • sklearn ≥ 1.5: Uses parametrize_with_checks([estimator]) to extract test parameters
  • Function signature: Added generate_only=True parameter with default value for backward compatibility
  • Error Handling: Added robust error handling with helpful messages for sklearn API changes
  • Code Quality: Extracted helper function to reduce duplication and improve maintainability
  • Documentation: Added comprehensive docstrings and comments explaining version-specific behavior and implementation details
# Before
def parametrize_with_checks_slow(fast_arguments, slow_arguments):
    fast_params = [
        list(sklearn.utils.estimator_checks.check_estimator(
            fast_arg, generate_only=True))[0] for fast_arg in fast_arguments
    ]
    ...

# After
def parametrize_with_checks_slow(fast_arguments, slow_arguments, generate_only=True):
    """Parametrize tests with sklearn estimator checks, supporting fast/slow test modes."""
    # Detect sklearn API version and use appropriate method
    check_estimator_sig = inspect.signature(sklearn.utils.estimator_checks.check_estimator)
    supports_generate_only = 'generate_only' in check_estimator_sig.parameters
    
    if supports_generate_only:
        # Old sklearn API (<= 1.4.x)
        fast_params = [
            list(sklearn.utils.estimator_checks.check_estimator(
                fast_arg, generate_only=generate_only))[0] for fast_arg in fast_arguments
        ]
    else:
        # New sklearn API (>= 1.5): use parametrize_with_checks
        fast_params = [_get_first_check_for_estimator(fast_arg) for fast_arg in fast_arguments]
    ...

Testing

  • ✅ sklearn 1.4.2 (legacy): 343 tests collected successfully
  • ✅ sklearn 1.8.0 (latest): 343 tests collected successfully
  • ✅ Backward compatibility maintained with generate_only=True default
  • ✅ Code review: No critical issues
  • ✅ Security scan: No vulnerabilities

Existing callers continue to work unchanged. The fix resolves CI failures while maintaining full compatibility with both legacy and modern sklearn versions.

Original prompt

Update the parametrize_with_checks_slow decorator to accept and properly handle the generate_only argument.

Currently the decorator in tests/_util.py does not accept a generate_only parameter, but usages in the test suite expect to provide it, which causes a TypeError: got an unexpected keyword argument 'generate_only' (see failing logs from Job 60500166432).

Task:

  • Update the function signature of parametrize_with_checks_slow to accept a generate_only argument (default=True for backward compatibility).
  • Ensure generate_only is passed through to sklearn.utils.estimator_checks.check_estimator inside the function.
  • Confirm usage in test code (such as in tests/test_sklearn.py) is compatible and safe, and update the docstring if present to mention the new argument.

Example implementation:

def parametrize_with_checks_slow(fast_arguments, slow_arguments, generate_only=True):
    fast_params = [
        list(sklearn.utils.estimator_checks.check_estimator(
            fast_arg, generate_only=generate_only))[0] for fast_arg in fast_arguments
    ]
    slow_params = [
        list(sklearn.utils.estimator_checks.check_estimator(
            slow_arg, generate_only=generate_only))[0] for slow_arg in slow_arguments
    ]
    return parametrize_slow("estimator,check", fast_params, slow_params)

This enables user code to pass generate_only without errors and resolves the CI/test failures due to this issue.

This pull request was created from Copilot chat.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: MMathisLab <28102185+MMathisLab@users.noreply.github.com>
Copilot AI changed the title [WIP] Update parametrize_with_checks_slow to accept generate_only argument Add generate_only parameter to parametrize_with_checks_slow decorator Jan 15, 2026
Copilot AI requested a review from MMathisLab January 15, 2026 18:05
@MMathisLab MMathisLab requested a review from stes January 15, 2026 18:08
@MMathisLab
Copy link
Member

@copilot ERROR tests/test_sklearn.py - TypeError: got an unexpected keyword argument 'generate_only'

Handle both sklearn 1.4.2 (legacy) and 1.8.0+ (latest) APIs:
- Old API: check_estimator with generate_only parameter
- New API: parametrize_with_checks (generate_only removed)
Fixes TypeError: got an unexpected keyword argument 'generate_only'

Co-authored-by: MMathisLab <28102185+MMathisLab@users.noreply.github.com>
@cla-bot
Copy link

cla-bot bot commented Jan 16, 2026

Thank you for your contribution. We require contributors to sign our Contributor License Agreement (CLA). We do not have a signed CLA on file for you. In order for us to review and merge your code, please sign our CLA here. After you signed, you can comment on this PR with @cla-bot check to trigger another check.

Copy link
Author

Copilot AI commented Jan 16, 2026

@copilot ERROR tests/test_sklearn.py - TypeError: got an unexpected keyword argument 'generate_only'

Fixed in commit 1f307d1. The issue was that sklearn 1.8.0+ removed the generate_only parameter. The function now detects the sklearn version and uses the appropriate API:

  • sklearn ≤ 1.4.x: check_estimator(generate_only=True)
  • sklearn ≥ 1.5: parametrize_with_checks()

Tested with both sklearn 1.4.2 and 1.8.0 - both collect 343 tests successfully.

Copilot AI and others added 2 commits January 16, 2026 20:51
- Extract repeated logic into helper function
- Add error handling for sklearn API changes
- Avoid generator exhaustion by converting to list first
- Filter out None values from check lists

Co-authored-by: MMathisLab <28102185+MMathisLab@users.noreply.github.com>
- Explain why only first check is returned ([0] behavior)
- Document fragility of accessing decorator internals
- Improve code maintainability

Co-authored-by: MMathisLab <28102185+MMathisLab@users.noreply.github.com>
Copilot AI changed the title Add generate_only parameter to parametrize_with_checks_slow decorator Fix sklearn version compatibility for parametrize_with_checks_slow decorator Jan 16, 2026
@AdaptiveMotorControlLab AdaptiveMotorControlLab deleted a comment from cla-bot bot Jan 16, 2026
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