Skip to content

Avoid pickling lambda in dask LabelBinarizer pytests#7898

Merged
rapids-bot[bot] merged 3 commits intorapidsai:release/26.04from
aamijar:fix-lambda-LabelBinarizer
Mar 16, 2026
Merged

Avoid pickling lambda in dask LabelBinarizer pytests#7898
rapids-bot[bot] merged 3 commits intorapidsai:release/26.04from
aamijar:fix-lambda-LabelBinarizer

Conversation

@aamijar
Copy link
Copy Markdown
Member

@aamijar aamijar commented Mar 16, 2026

Resolves #7241

    |     result = pickle.dumps(x, **dump_kwargs)
    |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    | AttributeError: Can't get local object 'test_basic_functions.<locals>.<lambda>'

To prevent this error and the following exception handling altogether we can avoid using a lambda.

@aamijar aamijar requested a review from a team as a code owner March 16, 2026 07:21
@aamijar aamijar requested a review from csadorf March 16, 2026 07:21
@github-actions github-actions Bot added the Cython / Python Cython or Python issue label Mar 16, 2026
@aamijar aamijar changed the base branch from main to release/26.04 March 16, 2026 07:22
@aamijar aamijar added non-breaking Non-breaking change bug Something isn't working labels Mar 16, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 8aea1587-d2d9-49eb-8775-e98a14693efc

📥 Commits

Reviewing files that changed from the base of the PR and between 4f00f71 and de54a67.

📒 Files selected for processing (1)
  • python/cuml/tests/dask/test_dask_label_binarizer.py

📝 Walkthrough

Summary by CodeRabbit

  • Tests
    • Refactored internal test utilities for improved code clarity and maintainability.

Walkthrough

This change refactors a test file by extracting an inline lambda function into a named helper function _get_block(x) that returns x.get(). The helper is used in a map_blocks operation to retrieve values from Dask/CuPy blocks during test execution.

Changes

Cohort / File(s) Summary
Test Helper Refactoring
python/cuml/tests/dask/test_dask_label_binarizer.py
Extracted inline lambda into named helper function _get_block(x) for retrieving block values; preserves dtype handling and transformation workflow.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: replacing a lambda with a named function to avoid pickling issues in the dask LabelBinarizer tests.
Description check ✅ Passed The description is directly related to the changeset, referencing the linked issue and explaining the motivation for avoiding the lambda to prevent pickle serialization errors.
Linked Issues check ✅ Passed The code changes directly address the root cause identified in issue #7241 by replacing the problematic lambda with a named function _get_block to prevent pickle errors.
Out of Scope Changes check ✅ Passed All changes are scoped to the dask LabelBinarizer test file and directly address the lambda pickling issue; no extraneous modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
📝 Coding Plan
  • Generate coding plan for human review comments

Comment @coderabbitai help to get the list of available commands and usage tips.

@jcrist
Copy link
Copy Markdown
Member

jcrist commented Mar 16, 2026

Dask uses cloudpickle, which can serialize lambdas just fine. It's very weird that we see issues here only sometimes, rather than always or never.

That said, this fix isn't wrong, it just shouldn't be necessary. Happy to merge, but I suspect there's something else sneaky going on here.

@jcrist
Copy link
Copy Markdown
Member

jcrist commented Mar 16, 2026

This needs #7901 before tests will pass.

@aamijar
Copy link
Copy Markdown
Member Author

aamijar commented Mar 16, 2026

/merge

@rapids-bot rapids-bot Bot merged commit 84867fb into rapidsai:release/26.04 Mar 16, 2026
91 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Cython / Python Cython or Python issue non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI] RecursionError in test_basic_functions on dask LabelBinarizer tests

3 participants