Source code for pyxu.info.warning

 1# Custom warnings used inside Pyxu.
 2import inspect
 3import warnings
 4
 5
[docs] 6class PyxuWarning(UserWarning): 7 """ 8 Parent class of all warnings raised in Pyxu. 9 """
10 11
[docs] 12class AutoInferenceWarning(PyxuWarning): 13 """ 14 Use when a quantity was auto-inferenced with possible caveats. 15 """
16 17
[docs] 18class PerformanceWarning(PyxuWarning): 19 """ 20 Use for performance-related warnings. 21 """
22 23
[docs] 24def warn_dask_perf(msg: str = None): 25 """ 26 Issue a warning for DASK-related performance issues. 27 28 This method is aware of its context and prints the name of the enclosing function/method which invoked it. 29 30 Parameters 31 ---------- 32 msg: str 33 Custom warning message. 34 """ 35 if msg is None: 36 msg = "Sub-optimal performance for DASK inputs." 37 38 # Get context 39 my_frame = inspect.currentframe() 40 up_frame = inspect.getouterframes(my_frame)[1] 41 header = f"{up_frame.filename}:{up_frame.function}" 42 43 msg = f"[{header}] {msg}" 44 warnings.warn(msg, PerformanceWarning)
45 46
[docs] 47class PrecisionWarning(PyxuWarning): 48 """ 49 Use for precision-related warnings. 50 """
51 52
[docs] 53class DenseWarning(PyxuWarning): 54 """ 55 Use for sparse-based algos which revert to dense arrays. 56 """
57 58
[docs] 59class NonTransparentWarning(PyxuWarning): 60 """ 61 Inform test suite runner of (safe) non-transparent function call. 62 """
63 64
[docs] 65class BackendWarning(PyxuWarning): 66 """ 67 Inform user of a backend-specific problem to be aware of. 68 """
69 70
[docs] 71class ContributionWarning(PyxuWarning): 72 """ 73 Use for warnings related to Pyxu plugins. 74 """