Skip to content

Remove global calls to warnings.resetwarnings() #1205

@rhine3

Description

@rhine3

There are global-level calls to warnings.resetwarnings() within the Audio class that reset any user-provided logging level:

Instance 1:

warnings.resetwarnings()

Instance 2:

warnings.resetwarnings()

For example, this localization code produces a lot of UserWarnings when cross-correlating clips extracted from the beginnings of recordings, even though it's run within a context that should catch all errors. This is because the warning logging level is reset in the Audio module when clips are loaded.

with warnings.catch_warnings():
            warnings.simplefilter("ignore")
            events = array.localize_detections(
                detections=dets_wide,
                max_receiver_dist=row["loca_max_receiver_dist"],
                min_n_receivers=row["loca_min_n_receivers"],
                localization_algorithm=row["loca_algorithm"],
                cc_filter=row["loca_cc_filter"],
                bandpass_ranges={sp: bandpass_ranges[sp] for sp in species_params["detection_species"]},
                num_workers=num_workers
            )

Instead of the global call to warnings.resetwarnings(), we could use a similar with warnings.catch_warnings() context manager in the Audio class to only catch warnings within that context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions