Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(python): In hypothesis testing strategies, enable Decimal strategy by default #15321

Merged
merged 3 commits into from
Mar 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions py-polars/polars/testing/parametric/strategies.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from __future__ import annotations

import os
from datetime import datetime, timedelta
from itertools import chain
from random import choice, randint, shuffle
Expand Down Expand Up @@ -273,14 +272,11 @@ def update(self, items: StrategyLookup) -> Self: # type: ignore[override]
Categorical: strategy_categorical,
String: strategy_string,
Binary: strategy_binary,
Decimal: strategy_decimal(),
}
)
nested_strategies: StrategyLookup = StrategyLookup()

# note: decimal support is in early development and requires activation
if os.environ.get("POLARS_ACTIVATE_DECIMAL") == "1":
scalar_strategies[Decimal] = strategy_decimal()


def _get_strategy_dtypes(
*,
Expand Down
18 changes: 0 additions & 18 deletions py-polars/tests/parametric/test_series.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,6 @@
from polars.testing import assert_series_equal
from polars.testing.parametric import series

# TODO: once Decimal is a little further along, start actively probing it
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this TODO, because we already have tests for to_list, and for the strategy itself. More tests are always welcome, but don't have to be a TODO like this.

# @given(
# s=series(max_size=10, dtype=pl.Decimal, null_probability=0.1),
# )
# def test_series_decimal(
# s: pl.Series,
# ) -> None:
# with pl.Config(activate_decimals=True):
# assert s.dtype == pl.Decimal
# assert s.to_list() == list(s)
#
# s_div = s / D(123)
# s_mul = s * D(123)
# s_sub = s - D(123)
# s_add = s - D(123)
#
# etc...


@given(
s=series(min_size=1, max_size=10, dtype=pl.Datetime),
Expand Down
8 changes: 7 additions & 1 deletion py-polars/tests/parametric/test_testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,13 @@ def test_invalid_arguments() -> None:
column("colx", strategy=sampled_from([None]))


@given(s=series(allowed_dtypes=pl.Binary))
@given(s=series(dtype=pl.Binary))
@settings(max_examples=5)
def test_strategy_dtype_binary(s: pl.Series) -> None:
assert s.dtype == pl.Binary


@given(s=series(dtype=pl.Decimal))
@settings(max_examples=5)
def test_strategy_dtype_decimal(s: pl.Series) -> None:
assert s.dtype == pl.Decimal
Loading