Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Avoid strategy truthiness checks in pandas_strategies to prevent HypothesisWarning #2307

@RedZapdos123

Description

@RedZapdos123

pandera/strategies/pandas_strategies.py uses truthiness checks on Hypothesis strategies (if strategy:), which triggers repeated HypothesisWarning messages.

Minimal Reproducible Example (MRE):

pytest -q tests/strategies/test_strategies.py -k "strategy" --maxfail=1

Observed warning snippet:

pandera/strategies/pandas_strategies.py:832: HypothesisWarning: bool(from_dtype(...)) is always True, did you mean to draw a value?
    if strategy:

Also appears at another location:

pandera/strategies/pandas_strategies.py:1055: HypothesisWarning: ...
    if strategy:

Current Behavior:

The suite emits many HypothesisWarning messages because strategy objects are evaluated in boolean context.

Expected Behavior:

Pandera should use explicit None checks (if strategy is not None: / if strategy is None:) instead of strategy truthiness so Hypothesis warnings are not emitted for this condition.

The MRE run screenshot:

Image

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