snowpark-checkpoints-validators 0.3.2__tar.gz → 0.3.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/PKG-INFO +1 -1
  2. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/__version__.py +1 -1
  3. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/snowpark_sampler.py +30 -3
  4. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/utils/constants.py +13 -0
  5. snowpark_checkpoints_validators-0.3.3/test/unit/test_snowpark_sampler.py +96 -0
  6. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/.gitignore +0 -0
  7. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/CHANGELOG.md +0 -0
  8. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/LICENSE +0 -0
  9. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/README.md +0 -0
  10. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/pyproject.toml +0 -0
  11. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/__init__.py +0 -0
  12. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/checkpoint.py +0 -0
  13. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/errors.py +0 -0
  14. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/io_utils/__init__.py +0 -0
  15. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/io_utils/io_default_strategy.py +0 -0
  16. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/io_utils/io_env_strategy.py +0 -0
  17. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/io_utils/io_file_manager.py +0 -0
  18. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/job_context.py +0 -0
  19. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/singleton.py +0 -0
  20. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/spark_migration.py +0 -0
  21. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/utils/__init__.py +0 -0
  22. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/utils/extra_config.py +0 -0
  23. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/utils/logging_utils.py +0 -0
  24. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/utils/pandera_check_manager.py +0 -0
  25. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/utils/supported_types.py +0 -0
  26. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/utils/telemetry.py +0 -0
  27. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/utils/utils_checks.py +0 -0
  28. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/validation_result_metadata.py +0 -0
  29. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/src/snowflake/snowpark_checkpoints/validation_results.py +0 -0
  30. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/.coveragerc +0 -0
  31. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/e2eexample.py +0 -0
  32. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_compare_utils.py +0 -0
  33. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/df_mode_dataframe_mismatch_telemetry.json +0 -0
  34. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/df_mode_dataframe_telemetry.json +0 -0
  35. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/spark_checkpoint_df_fail_telemetry.json +0 -0
  36. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/spark_checkpoint_df_pass_telemetry.json +0 -0
  37. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/spark_checkpoint_limit_sample_telemetry.json +0 -0
  38. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/spark_checkpoint_random_sample_telemetry.json +0 -0
  39. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/spark_checkpoint_scalar_fail_telemetry.json +0 -0
  40. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/spark_checkpoint_scalar_passing_telemetry.json +0 -0
  41. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/test_df_check_custom_check_telemetry.json +0 -0
  42. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/test_df_check_fail_telemetry.json +0 -0
  43. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/test_df_check_from_file_telemetry.json +0 -0
  44. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/test_df_check_skip_check_telemetry.json +0 -0
  45. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/test_df_check_telemetry.json +0 -0
  46. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/test_input_fail_telemetry.json +0 -0
  47. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/test_input_telemetry.json +0 -0
  48. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/test_output_fail_telemetry.json +0 -0
  49. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/telemetry_expected/test_output_telemetry.json +0 -0
  50. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/test_pandera.py +0 -0
  51. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/test_parquet.py +0 -0
  52. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/integ/test_spark_checkpoint.py +0 -0
  53. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/io_utils/test_default_strategy.py +0 -0
  54. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_checkpoints.py +0 -0
  55. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_extra_config.py +0 -0
  56. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_job_context.py +0 -0
  57. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_logger.py +0 -0
  58. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_logging_utils.py +0 -0
  59. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_pandera_check_manager.py +0 -0
  60. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_spark_migration.py +0 -0
  61. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_telemetry.py +0 -0
  62. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_utils_checks.py +0 -0
  63. {snowpark_checkpoints_validators-0.3.2 → snowpark_checkpoints_validators-0.3.3}/test/unit/test_validation_result_metadata.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: snowpark-checkpoints-validators
3
- Version: 0.3.2
3
+ Version: 0.3.3
4
4
  Summary: Migration tools for Snowpark
5
5
  Project-URL: Bug Tracker, https://github.com/snowflakedb/snowpark-checkpoints/issues
6
6
  Project-URL: Source code, https://github.com/snowflakedb/snowpark-checkpoints/
@@ -13,4 +13,4 @@
13
13
  # See the License for the specific language governing permissions and
14
14
  # limitations under the License.
15
15
 
16
- __version__ = "0.3.2"
16
+ __version__ = "0.3.3"
@@ -21,6 +21,10 @@ import pandas
21
21
 
22
22
  from snowflake.snowpark import DataFrame as SnowparkDataFrame
23
23
  from snowflake.snowpark_checkpoints.job_context import SnowparkJobContext
24
+ from snowflake.snowpark_checkpoints.utils.constants import (
25
+ INTEGER_TYPE_COLLECTION,
26
+ PANDAS_LONG_TYPE,
27
+ )
24
28
 
25
29
 
26
30
  LOGGER = logging.getLogger(__name__)
@@ -73,17 +77,17 @@ class SamplingAdapter:
73
77
  "Applying random sampling with fraction %s",
74
78
  self.sample_frac,
75
79
  )
76
- df_sample = arg.sample(frac=self.sample_frac).to_pandas()
80
+ df_sample = to_pandas(arg.sample(frac=self.sample_frac))
77
81
  else:
78
82
  LOGGER.info(
79
83
  "Applying random sampling with size %s", self.sample_number
80
84
  )
81
- df_sample = arg.sample(n=self.sample_number).to_pandas()
85
+ df_sample = to_pandas(arg.sample(n=self.sample_number))
82
86
  else:
83
87
  LOGGER.info(
84
88
  "Applying limit sampling with size %s", self.sample_number
85
89
  )
86
- df_sample = arg.limit(self.sample_number).to_pandas()
90
+ df_sample = to_pandas(arg.limit(self.sample_number))
87
91
 
88
92
  LOGGER.info(
89
93
  "Successfully sampled the DataFrame. Resulting DataFrame shape: %s",
@@ -122,3 +126,26 @@ class SamplingAdapter:
122
126
  else:
123
127
  pyspark_sample_args.append(arg)
124
128
  return pyspark_sample_args
129
+
130
+
131
+ def to_pandas(sampled_df: SnowparkDataFrame) -> pandas.DataFrame:
132
+ """Convert a Snowpark DataFrame to a Pandas DataFrame, handling missing values and type conversions."""
133
+ LOGGER.debug("Converting Snowpark DataFrame to Pandas DataFrame")
134
+ pandas_df = sampled_df.toPandas()
135
+ pandas_df = normalize_missing_values_pandas(pandas_df)
136
+ return pandas_df
137
+
138
+
139
+ def normalize_missing_values_pandas(df: pandas.DataFrame) -> pandas.DataFrame:
140
+ """Normalize missing values in a Pandas DataFrame to ensure consistent handling of NA values."""
141
+ fill_values = {}
142
+ for col, dtype in df.dtypes.items():
143
+ if dtype in INTEGER_TYPE_COLLECTION or str(dtype) in PANDAS_LONG_TYPE:
144
+ fill_values[col] = 0
145
+ elif dtype is float or dtype == "float64":
146
+ fill_values[col] = 0.0
147
+ elif dtype is bool or dtype == "bool" or dtype == "boolean":
148
+ fill_values[col] = False
149
+ elif dtype is object or dtype == "object" or dtype is str:
150
+ fill_values[col] = ""
151
+ return df.fillna(value=fill_values)
@@ -133,3 +133,16 @@ VALIDATION_RESULTS_JSON_FILE_NAME: Final[str] = "checkpoint_validation_results.j
133
133
  SNOWFLAKE_CHECKPOINT_CONTRACT_FILE_PATH_ENV_VAR: Final[
134
134
  str
135
135
  ] = "SNOWFLAKE_CHECKPOINT_CONTRACT_FILE_PATH"
136
+
137
+ BYTE_COLUMN_TYPE = "byte"
138
+ INTEGER_COLUMN_TYPE = "integer"
139
+ LONG_COLUMN_TYPE = "long"
140
+ SHORT_COLUMN_TYPE = "short"
141
+
142
+ PANDAS_LONG_TYPE = "Int64"
143
+ INTEGER_TYPE_COLLECTION = [
144
+ BYTE_COLUMN_TYPE,
145
+ INTEGER_COLUMN_TYPE,
146
+ LONG_COLUMN_TYPE,
147
+ SHORT_COLUMN_TYPE,
148
+ ]
@@ -0,0 +1,96 @@
1
+ # Copyright 2025 Snowflake Inc.
2
+ # SPDX-License-Identifier: Apache-2.0
3
+
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+
16
+ from snowflake.snowpark_checkpoints.snowpark_sampler import (
17
+ normalize_missing_values_pandas,
18
+ to_pandas,
19
+ )
20
+ import pandas as pd
21
+ import numpy as np
22
+
23
+
24
+ class DummySnowparkDF:
25
+ def __init__(self, pandas_df):
26
+ self._pandas_df = pandas_df
27
+
28
+ def toPandas(self):
29
+ return self._pandas_df
30
+
31
+
32
+ def test_normalize_missing_values_pandas_integers():
33
+ df = pd.DataFrame({"a": [1, None, 3], "b": [None, 2, 3]}, dtype="Int64")
34
+ result = normalize_missing_values_pandas(df)
35
+ assert result["a"].iloc[1] == 0
36
+ assert result["b"].iloc[0] == 0
37
+
38
+
39
+ def test_normalize_missing_values_pandas_floats():
40
+ df = pd.DataFrame({"a": [1.1, np.nan, 3.3], "b": [np.nan, 2.2, 3.3]})
41
+ result = normalize_missing_values_pandas(df)
42
+ assert result["a"].iloc[1] == 0.0
43
+ assert result["b"].iloc[0] == 0.0
44
+
45
+
46
+ def test_normalize_missing_values_pandas_bools():
47
+ df = pd.DataFrame(
48
+ {"a": [True, None, False], "b": [None, False, True]}, dtype="boolean"
49
+ )
50
+ result = normalize_missing_values_pandas(df)
51
+ assert result["a"].iloc[1] is np.False_
52
+ assert result["b"].iloc[0] is np.False_
53
+
54
+
55
+ def test_normalize_missing_values_pandas_objects_and_strings():
56
+ df = pd.DataFrame(
57
+ {"a": ["foo", None, "bar"], "b": [None, "baz", "qux"]}, dtype="object"
58
+ )
59
+ result = normalize_missing_values_pandas(df)
60
+ assert result["a"].iloc[1] == ""
61
+ assert result["b"].iloc[0] == ""
62
+
63
+
64
+ def test_normalize_missing_values_pandas_mixed_types(): ###
65
+ df = pd.DataFrame(
66
+ {
67
+ "int_col": pd.Series([1, None], dtype="Int64"),
68
+ "float_col": [1.1, np.nan],
69
+ "bool_col": pd.Series([True, None], dtype="boolean"),
70
+ "str_col": ["a", None],
71
+ }
72
+ )
73
+ result = normalize_missing_values_pandas(df)
74
+ assert result["int_col"].iloc[1] == 0
75
+ assert result["float_col"].iloc[1] == 0.0
76
+ assert result["bool_col"].iloc[1] is np.False_
77
+ assert result["str_col"].iloc[1] == ""
78
+
79
+
80
+ def test_to_pandas_calls_normalize(monkeypatch):
81
+ df = pd.DataFrame({"a": [1, None], "b": [None, "foo"]})
82
+ dummy_snowpark_df = DummySnowparkDF(df)
83
+ called = {}
84
+
85
+ def fake_normalize(df_arg):
86
+ called["was_called"] = True
87
+ return df_arg.fillna(0)
88
+
89
+ monkeypatch.setattr(
90
+ "snowflake.snowpark_checkpoints.snowpark_sampler.normalize_missing_values_pandas",
91
+ fake_normalize,
92
+ )
93
+
94
+ result = to_pandas(dummy_snowpark_df)
95
+ assert called.get("was_called", False)
96
+ assert isinstance(result, pd.DataFrame)