pynapple-org / pynapple

PYthon Neural Analysis Package :pineapple:
https://pynapple-org.github.io/pynapple/
MIT License
246 stars 61 forks source link

Global management of warnings #54

Open apeyrache opened 2 years ago

apeyrache commented 2 years ago

some functions throw warnings. There should be a way to switch them off globally (for example when running an analysis on a large dataset after checking its validity on a few sessions)

dcxSt commented 2 years ago

You can run files with a flag (stackoverflow) python -W ignore foo.py

If this is no good how about turning those warnings into logs with the built-in logging library. Perhaps this is more suitable for some things? logging.warning

Where exactly does this come up?

This is what I get from recursively grepping "warn" for this repository, can you identify the troublesome ones?

.//tests/test_neurosuite.py:import warnings
.//tests/test_neurosuite.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_neurosuite.py:with warnings.catch_warnings():
.//tests/test_neurosuite.py:    warnings.simplefilter("ignore")
.//tests/test_time_series.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_time_series.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_phy.py:import warnings
.//tests/test_phy.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_phy.py:with warnings.catch_warnings():
.//tests/test_phy.py:    warnings.simplefilter("ignore")
.//tests/test_tuning_curves.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_tuning_curves.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_cnmfe.py:import warnings
.//tests/test_cnmfe.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_cnmfe.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_cnmfe.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_nwb.py:import warnings
.//tests/test_nwb.py:@pytest.mark.filterwarnings("ignore")
.//tests/test_nwb.py:with warnings.catch_warnings():
.//tests/test_nwb.py:    warnings.simplefilter("ignore")
.//tests/test_nwb.py:    @pytest.mark.filterwarnings("ignore")
.//docs/tutorials/tutorial_pynapple_process.py:import warnings
.//docs/tutorials/tutorial_pynapple_process.py:warnings.filterwarnings('ignore')
.//docs/notebooks/pynapple-process-notebook.ipynb:    "import warnings\n",
.//docs/notebooks/pynapple-process-notebook.ipynb:    "warnings.filterwarnings('ignore')\n",
.//pynapple/core/interval_set.py:import warnings
.//pynapple/core/interval_set.py:            if False, will give a warning when a fix is needed (default: False)
.//pynapple/core/interval_set.py:                                                give_warning=False)
.//pynapple/core/interval_set.py:                                              give_warning=False)            
.//pynapple/core/interval_set.py:            warnings.warn("start is not sorted.", stacklevel=2)
.//pynapple/core/interval_set.py:            warnings.warn("end is not sorted.", stacklevel=2)
.//pynapple/core/interval_set.py:                                            give_warning=False)
.//pynapple/core/interval_set.py:                                          give_warning=False)
.//pynapple/core/interval_set.py:            warnings.warn("Some starts and ends are equal. Removing 1 microsecond!", stacklevel=2)
.//pynapple/core/interval_set.py:            warnings.warn("Some ends precede the relative start. Dropping them!", stacklevel=2)
.//pynapple/core/interval_set.py:            warnings.warn("Some starts precede the previous end. Joining them!", stacklevel=2)
.//pynapple/core/interval_set.py:            warnings.warn("Some epochs have no duration", stacklevel=2)
.//pynapple/core/time_series.py:import warnings
.//pynapple/core/time_series.py:        with warnings.catch_warnings():
.//pynapple/core/time_series.py:            warnings.simplefilter("ignore")
.//pynapple/core/time_units.py:from warnings import warn
.//pynapple/core/time_units.py:    def format_timestamps(t, units=None, give_warning=True, sortt = True):
.//pynapple/core/time_units.py:            give_warning: if True, it will warn when the timestamps are not sored
.//pynapple/core/time_units.py:            if give_warning:
.//pynapple/core/time_units.py:                warn('timestamps are not sorted', UserWarning)
.//pynapple/core/ts_group.py:import warnings
.//pynapple/core/ts_group.py:                warnings.warn('Elements should not be passed as numpy array. Default time units is seconds when creating the Ts object.', stacklevel=2)
.//pynapple/core/ts_group.py:                warnings.warn('Elements should not be passed as numpy array. Default time units is seconds when creating the Ts object.', stacklevel=2)
.//pynapple/io/loader.py:import warnings
.//pynapple/io/loader.py:        with warnings.catch_warnings():
.//pynapple/io/loader.py:            warnings.simplefilter("ignore")
.//pynapple/process/tuning_curves.py:import warnings
.//pynapple/process/tuning_curves.py:    with warnings.catch_warnings():
.//pynapple/process/tuning_curves.py:        warnings.simplefilter("ignore")
.//pynapple/process/tuning_curves.py:    with warnings.catch_warnings():
.//pynapple/process/tuning_curves.py:        warnings.simplefilter("ignore")