-
Notifications
You must be signed in to change notification settings - Fork 230
Improve violation message on n_jobs
#4200
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve violation message on n_jobs
#4200
Conversation
for more information, see https://pre-commit.ci
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR improves error handling in the fix_job_kwargs function by enhancing the assert statement's error message to provide more diagnostic information when n_jobs has an invalid value.
Key Changes
- Enhanced the assertion error message to include the actual value and type of the invalid
n_jobsparameter
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| assert isinstance(n_jobs, (float, np.integer, int)) and n_jobs != 0, "n_jobs must be a non-zero int or float" | ||
| assert ( | ||
| isinstance(n_jobs, (float, np.integer, int)) and n_jobs != 0 | ||
| ), f"n_jobs must be a non-zero int or float, got {n_jobs} ({type(n_jobs)})." |
Copilot
AI
Nov 6, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message includes the raw type object representation which is verbose and technical. Consider using type(n_jobs).__name__ instead to provide a cleaner, more readable type name. For example: f\"n_jobs must be a non-zero int or float, got {n_jobs} (type: {type(n_jobs).__name__}).\"
| ), f"n_jobs must be a non-zero int or float, got {n_jobs} ({type(n_jobs)})." | |
| ), f"n_jobs must be a non-zero int or float, got {n_jobs} (type: {type(n_jobs).__name__})." |
|
I am a little torn on this to be honest. I do appreciate better error messages in general, but for something so fundamental as an int or float it seems okay to just tell the user to use the int or float. Could you give me an example of when this has actually caused a problem? |
|
@zm711 The original error was a simple mistake I made in my code. In my programming practice, I tend to report not only the error type but also the contextual state. That's why I submitted this PR. I think your point is also valid—if you feel it's unnecessary, I'm happy to close this PR. I cannot provide the original erroneous code, but its pseudo-code structure is similar to the following: n_jobs = False # WRONG INPUT HERE
analyzer: sc.SortingAnalyzer
analyzer.compute(ext_name, save=save, n_jobs=n_jobs, **kwargs) |
|
Thanks @MGAMZ I actually agree with @. The styles are already quite clear in the current message! Let's close this! Feel free to open new PRs if you find something is unclear |
|
Closing this one~~ |
The current implementation when receives an invalid
n_jobsduring extensions computation DOES NOT include the incorrect input. It's better to tell users not only they are wrong but also what is the wrong input right now.