pyspark-testframework 2.2.1__tar.gz → 2.2.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 (44) hide show
  1. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/PKG-INFO +4 -5
  2. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/README.md +3 -4
  3. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/pyspark_testframework.egg-info/PKG-INFO +4 -5
  4. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/_version.py +2 -2
  5. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/dataframe/dataframe_tester.py +13 -3
  6. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/dataquality/dataframe/test_DataFrameTester.py +28 -0
  7. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tutorial.ipynb +17 -18
  8. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/.github/labeler.yml +0 -0
  9. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/.github/release.yml +0 -0
  10. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/.github/workflows/cicd.yml +0 -0
  11. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/.github/workflows/cicd_woonstad_rotterdam.yml +0 -0
  12. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/.github/workflows/labeler.yml +0 -0
  13. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/.github/workflows/publish-to-pypi.yml +0 -0
  14. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/.gitignore +0 -0
  15. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/.pre-commit-config.yaml +0 -0
  16. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/LICENSE +0 -0
  17. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/pyproject.toml +0 -0
  18. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/setup.cfg +0 -0
  19. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/pyspark_testframework.egg-info/SOURCES.txt +0 -0
  20. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/pyspark_testframework.egg-info/dependency_links.txt +0 -0
  21. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/pyspark_testframework.egg-info/requires.txt +0 -0
  22. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/pyspark_testframework.egg-info/top_level.txt +0 -0
  23. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/__init__.py +0 -0
  24. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/__init__.py +0 -0
  25. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/_base.py +0 -0
  26. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/dataframe/__init__.py +0 -0
  27. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/tests/__init__.py +0 -0
  28. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/tests/correct_value.py +0 -0
  29. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/tests/integer_string.py +0 -0
  30. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/tests/regex_tst.py +0 -0
  31. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/tests/valid_category.py +0 -0
  32. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/tests/valid_numeric_range.py +0 -0
  33. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/dataquality/tests/valid_numeric_string_range.py +0 -0
  34. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/utils/__init__.py +0 -0
  35. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/src/testframework/utils/decorators.py +0 -0
  36. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/conftest.py +0 -0
  37. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/dataquality/dataframe/tests/test_CorrectValue.py +0 -0
  38. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/dataquality/dataframe/tests/test_IntegerString.py +0 -0
  39. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/dataquality/dataframe/tests/test_RegexTest.py +0 -0
  40. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/dataquality/dataframe/tests/test_ValidCategory.py +0 -0
  41. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/dataquality/dataframe/tests/test_ValidNumericRange.py +0 -0
  42. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/dataquality/dataframe/tests/test_ValidNumericStringRange.py +0 -0
  43. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/utils/decorators/test_account_for_nullable.py +0 -0
  44. {pyspark_testframework-2.2.1 → pyspark_testframework-2.2.3}/tests/utils/decorators/test_allowed_col_types.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyspark-testframework
3
- Version: 2.2.1
3
+ Version: 2.2.3
4
4
  Summary: Testframework for PySpark DataFrames
5
5
  Author-email: Woonstad Rotterdam <info@woonstadrotterdam.nl>, Tomer Gabay <tomer.gabay@woonstadrotterdam.nl>, Vincent van der Meij <vincent.van.der.meij@woonstadrotterdam.nl>, Tiddo Loos <tiddo.loos@woonstadrotterdam.nl>, Ben Verhees <ben.verhees@woonstadrotterdam.nl>
6
6
  License: MIT License
@@ -169,6 +169,8 @@ df_tester.test(
169
169
 
170
170
  **Run the `IntegerString` test on the _number_ column**
171
171
 
172
+ By setting the `return_failed_rows` parameter to `True`, we can get only the rows that failed the test.
173
+
172
174
  ```python
173
175
  df_tester.test(
174
176
  col="house_number",
@@ -177,17 +179,14 @@ df_tester.test(
177
179
  ),
178
180
  nullable=True, # nullable, hence null values are converted to True
179
181
  # description is optional, let's not define it for illustration purposes
182
+ return_failed_rows=True, # only return the failed rows
180
183
  ).show()
181
184
  ```
182
185
 
183
186
  +-----------+------------+-------------------------------+
184
187
  |primary_key|house_number|house_number__ValidNumericRange|
185
188
  +-----------+------------+-------------------------------+
186
- | 1| 27| true|
187
- | 2| 31| true|
188
- | 3| 27| true|
189
189
  | 4| -3| false|
190
- | 5| 13| true|
191
190
  +-----------+------------+-------------------------------+
192
191
 
193
192
  **Let's take a look at the test results of the DataFrame using the `.results` attribute.**
@@ -121,6 +121,8 @@ df_tester.test(
121
121
 
122
122
  **Run the `IntegerString` test on the _number_ column**
123
123
 
124
+ By setting the `return_failed_rows` parameter to `True`, we can get only the rows that failed the test.
125
+
124
126
  ```python
125
127
  df_tester.test(
126
128
  col="house_number",
@@ -129,17 +131,14 @@ df_tester.test(
129
131
  ),
130
132
  nullable=True, # nullable, hence null values are converted to True
131
133
  # description is optional, let's not define it for illustration purposes
134
+ return_failed_rows=True, # only return the failed rows
132
135
  ).show()
133
136
  ```
134
137
 
135
138
  +-----------+------------+-------------------------------+
136
139
  |primary_key|house_number|house_number__ValidNumericRange|
137
140
  +-----------+------------+-------------------------------+
138
- | 1| 27| true|
139
- | 2| 31| true|
140
- | 3| 27| true|
141
141
  | 4| -3| false|
142
- | 5| 13| true|
143
142
  +-----------+------------+-------------------------------+
144
143
 
145
144
  **Let's take a look at the test results of the DataFrame using the `.results` attribute.**
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyspark-testframework
3
- Version: 2.2.1
3
+ Version: 2.2.3
4
4
  Summary: Testframework for PySpark DataFrames
5
5
  Author-email: Woonstad Rotterdam <info@woonstadrotterdam.nl>, Tomer Gabay <tomer.gabay@woonstadrotterdam.nl>, Vincent van der Meij <vincent.van.der.meij@woonstadrotterdam.nl>, Tiddo Loos <tiddo.loos@woonstadrotterdam.nl>, Ben Verhees <ben.verhees@woonstadrotterdam.nl>
6
6
  License: MIT License
@@ -169,6 +169,8 @@ df_tester.test(
169
169
 
170
170
  **Run the `IntegerString` test on the _number_ column**
171
171
 
172
+ By setting the `return_failed_rows` parameter to `True`, we can get only the rows that failed the test.
173
+
172
174
  ```python
173
175
  df_tester.test(
174
176
  col="house_number",
@@ -177,17 +179,14 @@ df_tester.test(
177
179
  ),
178
180
  nullable=True, # nullable, hence null values are converted to True
179
181
  # description is optional, let's not define it for illustration purposes
182
+ return_failed_rows=True, # only return the failed rows
180
183
  ).show()
181
184
  ```
182
185
 
183
186
  +-----------+------------+-------------------------------+
184
187
  |primary_key|house_number|house_number__ValidNumericRange|
185
188
  +-----------+------------+-------------------------------+
186
- | 1| 27| true|
187
- | 2| 31| true|
188
- | 3| 27| true|
189
189
  | 4| -3| false|
190
- | 5| 13| true|
191
190
  +-----------+------------+-------------------------------+
192
191
 
193
192
  **Let's take a look at the test results of the DataFrame using the `.results` attribute.**
@@ -12,5 +12,5 @@ __version__: str
12
12
  __version_tuple__: VERSION_TUPLE
13
13
  version_tuple: VERSION_TUPLE
14
14
 
15
- __version__ = version = '2.2.1'
16
- __version_tuple__ = version_tuple = (2, 2, 1)
15
+ __version__ = version = '2.2.3'
16
+ __version_tuple__ = version_tuple = (2, 2, 3)
@@ -138,6 +138,7 @@ class DataFrameTester:
138
138
  filter_rows: Optional[Column] = None,
139
139
  return_extra_cols: Optional[list[str]] = None,
140
140
  dummy_run: bool = False,
141
+ return_failed_rows: bool = False,
141
142
  ) -> DataFrame:
142
143
  """
143
144
  Executes a specific test on a given column of the DataFrame.
@@ -150,6 +151,7 @@ class DataFrameTester:
150
151
  filter_rows (Optional[Column]): Uses df.filter(filter_rows) to filter rows for which the test doesn't apply.
151
152
  return_extra_cols (Optional[list[str]]): Return extra columns from the original dataframe. Defaults to None.
152
153
  dummy_run (bool): If True, perform a dummy run without saving results. Defaults to False.
154
+ return_failed_rows (bool): If True, return only the rows where the test has failed. Defaults to False.
153
155
 
154
156
  Returns:
155
157
  DataFrame: The test results as a DataFrame.
@@ -194,6 +196,9 @@ class DataFrameTester:
194
196
  )
195
197
  self.results = new_test_results
196
198
 
199
+ if return_failed_rows:
200
+ test_result = test_result.filter(F.col(test_name) == F.lit(False))
201
+
197
202
  if return_extra_cols:
198
203
  return test_result.join(
199
204
  self.df.select(*self.primary_key, *return_extra_cols),
@@ -222,6 +227,7 @@ class DataFrameTester:
222
227
  description: Optional[str] = None,
223
228
  fillna_value: Optional[Any] = None,
224
229
  return_extra_cols: Optional[list[str]] = None,
230
+ return_failed_rows: bool = False,
225
231
  ) -> DataFrame:
226
232
  """
227
233
  Adds custom test results to the test DataFrame.
@@ -232,6 +238,7 @@ class DataFrameTester:
232
238
  description (Optional[str]): Description of the test for reporting purposes.
233
239
  fillna_value (Optional[Any]): The value to fill nulls in the test result column after left joining on the primary_key. Defaults to None.
234
240
  return_extra_cols (Optional[list[str]]): Return extra columns from the original dataframe. Defaults to None.
241
+ return_failed_rows (bool): If True, return only the rows where the test has failed. Defaults to False.
235
242
 
236
243
  Returns:
237
244
  DataFrame: The updated test DataFrame with the custom test results.
@@ -278,14 +285,17 @@ class DataFrameTester:
278
285
 
279
286
  self.results = new_test_results
280
287
 
288
+ if return_failed_rows:
289
+ new_test_results = new_test_results.filter(F.col(name) == F.lit(False))
290
+
281
291
  if return_extra_cols:
282
- return self.results.select(*self.primary_key, name).join(
292
+ return new_test_results.select(*self.primary_key, name).join(
283
293
  self.df.select(*self.primary_key, *return_extra_cols),
284
294
  on=self.primary_key,
285
295
  how="left",
286
296
  )
287
297
 
288
- return self.results.select(*self.primary_key, name)
298
+ return new_test_results.select(*self.primary_key, name)
289
299
 
290
300
  @property
291
301
  def summary(self) -> DataFrame:
@@ -408,7 +418,7 @@ class DataFrameTester:
408
418
  if not conditions:
409
419
  return self.results
410
420
 
411
- combined_condition = reduce(lambda x, y: x | y, conditions)
421
+ combined_condition = reduce(lambda x, y: x & y, conditions)
412
422
 
413
423
  return self.results.filter(combined_condition)
414
424
 
@@ -260,3 +260,31 @@ def test_failed_tests(sample_df, spark):
260
260
  tester.test(col="value", test=ValidNumericRange(min_value=11), nullable=True)
261
261
 
262
262
  assert tester.failed_tests.count() == 1
263
+
264
+
265
+ def test_return_failed_rows(sample_df, spark):
266
+ tester = DataFrameTester(df=sample_df, primary_key="id", spark=spark)
267
+ test_result = tester.test(
268
+ col="value",
269
+ test=ValidNumericRange(min_value=11),
270
+ nullable=True,
271
+ return_failed_rows=True,
272
+ )
273
+ assert test_result.count() == 1
274
+
275
+
276
+ def test_return_failed_rows_custom_test(sample_df, spark):
277
+ tester = DataFrameTester(df=sample_df, primary_key="id", spark=spark)
278
+ custom_test_data = [(1, True), (2, False), (3, True), (4, False)]
279
+ custom_test_columns = ["id", "custom_test"]
280
+ custom_test_result = spark.createDataFrame(custom_test_data, custom_test_columns)
281
+
282
+ updated_results = tester.add_custom_test_result(
283
+ result=custom_test_result,
284
+ name="custom_test",
285
+ description="This is a custom test",
286
+ fillna_value=False,
287
+ return_failed_rows=True,
288
+ )
289
+
290
+ assert updated_results.count() == 2
@@ -44,7 +44,7 @@
44
44
  "name": "stdout",
45
45
  "output_type": "stream",
46
46
  "text": [
47
- "24/08/12 14:43:33 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable\n"
47
+ "24/08/13 14:00:40 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable\n"
48
48
  ]
49
49
  },
50
50
  {
@@ -204,7 +204,9 @@
204
204
  "cell_type": "markdown",
205
205
  "metadata": {},
206
206
  "source": [
207
- "**Run the `IntegerString` test on the _number_ column**"
207
+ "**Run the `IntegerString` test on the _number_ column**\n",
208
+ "\n",
209
+ "By setting the `return_failed_rows` parameter to `True`, we can get only the rows that failed the test."
208
210
  ]
209
211
  },
210
212
  {
@@ -219,11 +221,7 @@
219
221
  "+-----------+------------+-------------------------------+\n",
220
222
  "|primary_key|house_number|house_number__ValidNumericRange|\n",
221
223
  "+-----------+------------+-------------------------------+\n",
222
- "| 1| 27| true|\n",
223
- "| 2| 31| true|\n",
224
- "| 3| 27| true|\n",
225
224
  "| 4| -3| false|\n",
226
- "| 5| 13| true|\n",
227
225
  "+-----------+------------+-------------------------------+\n",
228
226
  "\n"
229
227
  ]
@@ -237,6 +235,7 @@
237
235
  " ),\n",
238
236
  " nullable=True, # nullable, hence null values are converted to True\n",
239
237
  " # description is optional, let's not define it for illustration purposes\n",
238
+ " return_failed_rows=True, # only return the failed rows\n",
240
239
  ").show()"
241
240
  ]
242
241
  },
@@ -532,22 +531,10 @@
532
531
  "execution_count": 17,
533
532
  "metadata": {},
534
533
  "outputs": [
535
- {
536
- "name": "stderr",
537
- "output_type": "stream",
538
- "text": [
539
- "Java HotSpot(TM) 64-Bit Server VM warning: CodeCache is full. Compiler has been disabled.\n",
540
- "Java HotSpot(TM) 64-Bit Server VM warning: Try increasing the code cache size using -XX:ReservedCodeCacheSize=\n"
541
- ]
542
- },
543
534
  {
544
535
  "name": "stdout",
545
536
  "output_type": "stream",
546
537
  "text": [
547
- "CodeCache: size=131072Kb used=36992Kb max_used=37010Kb free=94079Kb\n",
548
- " bounds [0x000000010b1e8000, 0x000000010d658000, 0x00000001131e8000]\n",
549
- " total_blobs=13403 nmethods=12493 adapters=821\n",
550
- " compilation: disabled (not enough contiguous free space left)\n",
551
538
  "+-------------------------------+-------------------------------------------------------------+-------+--------+-----------------+--------+-----------------+\n",
552
539
  "|test |description |n_tests|n_passed|percentage_passed|n_failed|percentage_failed|\n",
553
540
  "+-------------------------------+-------------------------------------------------------------+-------+--------+-----------------+--------+-----------------+\n",
@@ -607,10 +594,22 @@
607
594
  "execution_count": 19,
608
595
  "metadata": {},
609
596
  "outputs": [
597
+ {
598
+ "name": "stderr",
599
+ "output_type": "stream",
600
+ "text": [
601
+ "Java HotSpot(TM) 64-Bit Server VM warning: CodeCache is full. Compiler has been disabled.\n",
602
+ "Java HotSpot(TM) 64-Bit Server VM warning: Try increasing the code cache size using -XX:ReservedCodeCacheSize=\n"
603
+ ]
604
+ },
610
605
  {
611
606
  "name": "stdout",
612
607
  "output_type": "stream",
613
608
  "text": [
609
+ "CodeCache: size=131072Kb used=42866Kb max_used=43080Kb free=88205Kb\n",
610
+ " bounds [0x00000001069e8000, 0x0000000109458000, 0x000000010e9e8000]\n",
611
+ " total_blobs=14494 nmethods=13584 adapters=821\n",
612
+ " compilation: disabled (not enough contiguous free space left)\n",
614
613
  "+-----------+-----------------------+-------------------------------+-------------+\n",
615
614
  "|primary_key|street__ValidStreetName|house_number__ValidNumericRange|has_bath_room|\n",
616
615
  "+-----------+-----------------------+-------------------------------+-------------+\n",