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): add parametric testing support for the Array dtype #14265

Merged
merged 2 commits into from
Feb 5, 2024

Conversation

alexander-beedie
Copy link
Collaborator

@alexander-beedie alexander-beedie commented Feb 4, 2024

In addition to List (already supported) can now declare/use the Array dtype in parametric tests.

Example

import polars as pl
from hypothesis import given
from polars.testing.parametric import column, create_array_strategy

@given(
    df=dataframes(
        cols=[
            # basic use; declare inner dtype and width
            column("colx", dtype=pl.Array(pl.UInt8, width=3)),
            # use a more sophisticated strategy
            column(
                name="coly", 
                strategy=create_array_strategy(
                    inner_dtype=pl.Array(pl.String, width=2),
                    select_from=["a", "b", "c"],
                    width=2,
            ))]
))
def test_array_stuff(df: pl.DataFrame) -> None:
    print(df)
    
# shape: (6, 2)
# ┌────────────────┬──────────────────────────┐
# │ colx           ┆ coly                     │
# │ ---            ┆ ---                      │
# │ array[u8, 3]   ┆ array[array[str, 2], 2]  │
# ╞════════════════╪══════════════════════════╡
# │ [242, 131, 57] ┆ [["c", "c"], ["c", "a"]] │
# │ [220, 78, 82]  ┆ [["a", "a"], ["b", "a"]] │
# │ [153, 19, 100] ┆ [["a", "c"], ["b", "a"]] │
# │ [154, 195, 82] ┆ [["a", "a"], ["a", "a"]] │
# └────────────────┴──────────────────────────┘

@github-actions github-actions bot added enhancement New feature or an improvement of an existing feature python Related to Python Polars labels Feb 4, 2024
@alexander-beedie alexander-beedie added test Related to the test suite python Related to Python Polars enhancement New feature or an improvement of an existing feature and removed python Related to Python Polars enhancement New feature or an improvement of an existing feature labels Feb 4, 2024
@ritchie46 ritchie46 merged commit bf2766c into pola-rs:main Feb 5, 2024
13 checks passed
@alexander-beedie alexander-beedie deleted the parametric-array-strategy branch February 5, 2024 08:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or an improvement of an existing feature python Related to Python Polars test Related to the test suite
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants