Hypothesis extension for generating Snowpark DataFrames
Project description
snowpark-checkpoints-hypothesis
NOTE
This package is on Private 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:
- Create a standard Python test function with the different assertions or conditions your code should satisfy for all inputs.
- Add the Hypothesis
@givendecorator to your test function and pass thedataframe_strategyfunction as an argument. - 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:
-
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>
-
Configure your IDE to use the previously created virtual environment:
-
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snowpark_checkpoints_hypothesis-0.1.0rc3.tar.gz.
File metadata
- Download URL: snowpark_checkpoints_hypothesis-0.1.0rc3.tar.gz
- Upload date:
- Size: 25.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7e8c2fe00625035d317aa73a29970c9d56a7c711b3faa493eec06d75913230c7
|
|
| MD5 |
7a8fd1c82627385fcdceee8f9f6c4074
|
|
| BLAKE2b-256 |
557b94ac78fcfa5302ad2330ceb14fe1df4d42e9da0ae75d43d5e8667ff1ec59
|
File details
Details for the file snowpark_checkpoints_hypothesis-0.1.0rc3-py3-none-any.whl.
File metadata
- Download URL: snowpark_checkpoints_hypothesis-0.1.0rc3-py3-none-any.whl
- Upload date:
- Size: 7.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7bbed08c9c3f779d59753e86b2ca632b136db7e2cb600c60a69217d8c0ed9a3
|
|
| MD5 |
e5a798f23c5885987594d5a025ac0b64
|
|
| BLAKE2b-256 |
b58440207b095f866887be4a3ea3df4bf7d3c6d394cb3dce7e16dcf4ec1d0fee
|