Skip to content
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

Set warning stacklevels for validation #372

Open
bmcfee opened this issue Mar 21, 2024 · 1 comment
Open

Set warning stacklevels for validation #372

bmcfee opened this issue Mar 21, 2024 · 1 comment

Comments

@bmcfee
Copy link
Collaborator

bmcfee commented Mar 21, 2024

Validator functions often raise warnings when something isn't quite right, eg:

mir_eval/mir_eval/chord.py

Lines 640 to 644 in 57f7c31

# When either label list is empty, warn the user
if len(reference_labels) == 0:
warnings.warn('Reference labels are empty')
if len(estimated_labels) == 0:
warnings.warn('Estimated labels are empty')

However, the warning shows up to the user as coming from the validate function, which is not all that helpful since they never call this directly. We can make this more useful by setting stacklevel=2.

This way the warning will point to the evaluator that called validate, which is a little more helpful for debugging purposes, especially when the user is calling a module-level evaluate() function.

@bmcfee bmcfee added this to the 0.8 milestone Mar 21, 2024
@craffel
Copy link
Owner

craffel commented Mar 22, 2024

Good idea! Didn't know you could specify where in the stack the warning should come up.

bmcfee added a commit to bmcfee/mir_eval that referenced this issue Mar 26, 2024
@bmcfee bmcfee removed this from the 0.8 milestone Mar 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants