Skip to content

Conversation

@MGAMZ
Copy link
Contributor

@MGAMZ MGAMZ commented Nov 6, 2025

The current implementation when receives an invalid n_jobs during 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.

Copilot AI review requested due to automatic review settings November 6, 2025 05:32
Copy link

Copilot AI left a 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_jobs parameter

💡 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)})."
Copy link

Copilot AI Nov 6, 2025

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__}).\"

Suggested change
), 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__})."

Copilot uses AI. Check for mistakes.
@zm711
Copy link
Member

zm711 commented Nov 8, 2025

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?

@MGAMZ
Copy link
Contributor Author

MGAMZ commented Nov 9, 2025

@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)

@alejoe91
Copy link
Member

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

@MGAMZ
Copy link
Contributor Author

MGAMZ commented Nov 11, 2025

Closing this one~~

@MGAMZ MGAMZ closed this Nov 11, 2025
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.

3 participants