pandas 1.4.2

ParametersBackRef
assert_produces_warning(expected_warning: 'type[Warning] | bool | None' = <class 'Warning'>, filter_level='always', check_stacklevel: 'bool' = True, raise_on_extra_warnings: 'bool' = True, match: 'str | None' = None)

Parameters

expected_warning : {Warning, False, None}, default Warning

The type of Exception raised. exception.Warning is the base class for all warnings. To check that no warning is returned, specify False or None .

filter_level : str or None, default "always"

Specifies whether warnings are ignored, displayed, or turned into errors. Valid values are:

  • "error" - turns matching warnings into exceptions

  • "ignore" - discard the warning

  • "always" - always emit a warning

  • "default" - print the warning the first time it is generated from each location

  • "module" - print the warning the first time it is generated from each module

  • "once" - print the warning the first time it is generated

check_stacklevel : bool, default True

If True, displays the line that called the function containing the warning to show were the function is called. Otherwise, the line that implements the function is displayed.

raise_on_extra_warnings : bool, default True

Whether extra warnings not of the type :None:None:`expected_warning` should cause the test to fail.

match : str, optional

Match warning message.

Context manager for running code expected to either raise a specific warning, or not raise any warnings. Verifies that the code raises the expected warning, and that it does not raise any other unexpected warnings. It is basically a wrapper around warnings.catch_warnings .

Examples

This example is valid syntax, but we were not able to check execution
>>> import warnings
... with assert_produces_warning():
...  warnings.warn(UserWarning()) ...
This example is valid syntax, but we were not able to check execution
>>> with assert_produces_warning(False):
...  warnings.warn(RuntimeWarning()) ... Traceback (most recent call last): ... AssertionError: Caused unexpected warning(s): ['RuntimeWarning'].
This example is valid syntax, but we were not able to check execution
>>> with assert_produces_warning(UserWarning):
...  warnings.warn(RuntimeWarning()) Traceback (most recent call last): ... AssertionError: Did not see expected warning of class 'UserWarning'.

..warn:: This is not thread-safe.

See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

pandas._testing._warnings.assert_produces_warning

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


File: /pandas/_testing/_warnings.py#14
type: <class 'function'>
Commit: