Skip to main content

Hypothesis extension for generating Snowpark DataFrames

Project description

snowpark-checkpoints-hypothesis


This package is on Public Preview.

snowpark-checkpoints-hypothesis is a Hypothesis extension for generating Snowpark DataFrames. This project provides strategies to facilitate testing and data generation for Snowpark DataFrames using the Hypothesis library.

Installation

You can install this package using either pip or conda:

pip install snowpark-checkpoints-hypothesis
--or--
conda install snowpark-checkpoints-hypothesis

Usage

The typical workflow for using the Hypothesis library to generate Snowpark dataframes is as follows:

  1. Create a standard Python test function with the different assertions or conditions your code should satisfy for all inputs.
  2. Add the Hypothesis @given decorator to your test function and pass the dataframe_strategy function as an argument.
  3. Run the test. When the test is executed, Hypothesis will automatically provide the generated inputs as arguments to the test.

Example 1: Generate Snowpark DataFrames from a JSON schema file

You can use the dataframe_strategy function to create Snowpark DataFrames from a JSON schema file generated by the collect_dataframe_checkpoint function of the snowpark-checkpoints-collectors package:

from hypothesis import given
from snowflake.hypothesis_snowpark import dataframe_strategy
from snowflake.snowpark import DataFrame, Session


@given(
    df=dataframe_strategy(
        schema="path/to/schema.json",
        session=Session.builder.getOrCreate(),
        size=10,
    )
)
def test_my_function(df: DataFrame):
    # Test your function here
    ...

Example 2: Generate Snowpark DataFrames from a Pandera DataFrameSchema object

You can also use the dataframe_strategy function to create Snowpark DataFrames from a Pandera DataFrameSchema object:

import pandera as pa
from hypothesis import given
from snowflake.hypothesis_snowpark import dataframe_strategy
from snowflake.snowpark import DataFrame, Session

@given(
    df=dataframe_strategy(
        schema=pa.DataFrameSchema(
            {
                "A": pa.Column(pa.Int, checks=pa.Check.in_range(0, 10)),
                "B": pa.Column(pa.Bool),
            }
        ),
        session=Session.builder.getOrCreate(),
        size=10,
    )
)
def test_my_function(df: DataFrame):
    # Test your function here
    ...

Development

Set up a development environment

To set up a development environment, follow the steps below:

  1. Create a virtual environment using venv or conda. Replace <env-name> with the name of your environment.

    Using venv:

    python3.11 -m venv <env-name>
    source <env-name>/bin/activate
    

    Using conda:

    conda create -n <env-name> python=3.11
    conda activate <env-name>
    
  2. Configure your IDE to use the previously created virtual environment:

  3. Install the project dependencies:

    pip install hatch
    pip install -e .
    

Running Tests

To run tests, run the following command.

hatch run test:check

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snowpark_checkpoints_hypothesis-0.2.0.tar.gz (35.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snowpark_checkpoints_hypothesis-0.2.0-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file snowpark_checkpoints_hypothesis-0.2.0.tar.gz.

File metadata

File hashes

Hashes for snowpark_checkpoints_hypothesis-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c5095f6a142d75f43dd4c354d0f2d6997ba4b05441d57acd4838e35e0df6c54d
MD5 987a5bb87a8d24e1b2d3440d6fb23534
BLAKE2b-256 96e5f127132227cc9e5ddc9def6ab60760763f1f52b264e8f4f4394404e8e908

See more details on using hashes here.

File details

Details for the file snowpark_checkpoints_hypothesis-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for snowpark_checkpoints_hypothesis-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b170abccb55a84052e0446ebaeba613876da0c2cfa44c82a3dd4a0799e7ad6c4
MD5 ee94bf6e1fa7cb3598e7754135ed9c96
BLAKE2b-256 d0f523fa628a4558bca579058e0b1f142cecdab0967a03027131d3f349d7a6fd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page