csv-validation 0.1.1__tar.gz → 0.1.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.
- {csv_validation-0.1.1 → csv_validation-0.1.3}/Cargo.lock +1 -1
- {csv_validation-0.1.1 → csv_validation-0.1.3}/Cargo.toml +3 -3
- {csv_validation-0.1.1 → csv_validation-0.1.3}/PKG-INFO +16 -16
- {csv_validation-0.1.1 → csv_validation-0.1.3}/README.md +15 -15
- {csv_validation-0.1.1 → csv_validation-0.1.3}/src/lib.rs +59 -11
- {csv_validation-0.1.1 → csv_validation-0.1.3}/.github/workflows/CI.yml +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/.gitignore +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/LICENSE +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/MANIFEST.in +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/build.sh +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/csv_validation.pyi +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/pyproject.toml +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/test/duplicated_unique_keys.csv +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/test/empty_values.csv +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/test/test_file.csv +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/test/test_file.csv.gz +0 -0
- {csv_validation-0.1.1 → csv_validation-0.1.3}/test/test_validations.yml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "csv_validation"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.3"
|
|
4
4
|
edition = "2021"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
|
|
@@ -14,14 +14,14 @@ csv = "1.3.1"
|
|
|
14
14
|
flate2 = "1.1.0"
|
|
15
15
|
log = "0.4.26"
|
|
16
16
|
# abi3-py310 makes the wheels forward-compatible with 3.11, 3.12 ...
|
|
17
|
-
pyo3 = { version = "0.23.
|
|
17
|
+
pyo3 = { version = "0.23.5", features = ["abi3-py310"] }
|
|
18
18
|
pyo3-log = "0.12.1"
|
|
19
19
|
regex = "1.11.1"
|
|
20
20
|
simple_logger = "5.0.0"
|
|
21
21
|
yaml-rust2 = "0.10.0"
|
|
22
22
|
serde = { version = "1.0.218", features = ["derive"] }
|
|
23
23
|
redb = "3.1.0"
|
|
24
|
-
tempfile = "3.
|
|
24
|
+
tempfile = "3.25.0"
|
|
25
25
|
|
|
26
26
|
[features]
|
|
27
27
|
extension-module = ["pyo3/extension-module"]
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: csv_validation
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.3
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
@@ -193,12 +193,12 @@ columns:
|
|
|
193
193
|
What you will see in the summary:
|
|
194
194
|
- Always shows the number of duplicate key groups found.
|
|
195
195
|
- If there are more than 100 duplicate groups, only the first 100 are displayed as a sample (with their occurrence counts), and the total number is indicated.
|
|
196
|
-
- If no duplicates are found, it reports: "
|
|
196
|
+
- If no duplicates are found, it reports: "No duplicates found".
|
|
197
197
|
|
|
198
198
|
Sample output (composite key):
|
|
199
199
|
|
|
200
200
|
```
|
|
201
|
-
UNIQUE KEY: column(s):
|
|
201
|
+
UNIQUE KEY: column(s): isin, date, score_provider
|
|
202
202
|
|
|
203
203
|
DUPLICATED KEYS (groups found: 134)
|
|
204
204
|
--------------------------------------------------
|
|
@@ -213,7 +213,7 @@ If none:
|
|
|
213
213
|
```
|
|
214
214
|
UNIQUE KEYS CHECK
|
|
215
215
|
--------------------------------------------------
|
|
216
|
-
- No
|
|
216
|
+
- No duplicates found
|
|
217
217
|
```
|
|
218
218
|
|
|
219
219
|
Performance note: Duplicate detection stores only the unique keys on disk and keeps a tiny in-memory summary used for printing the report. This allows validating huge datasets with minimal RAM usage.
|
|
@@ -242,7 +242,7 @@ validator.set_decimal_separator(",") # Use comma
|
|
|
242
242
|
The library provides detailed validation reports through Python's logging system. When a validation fails, you'll get information about:
|
|
243
243
|
- Which columns failed validation
|
|
244
244
|
- What type of validation failed
|
|
245
|
-
- Sample of invalid values
|
|
245
|
+
- Sample of invalid values (including row numbers)
|
|
246
246
|
- Number of rows that failed each validation
|
|
247
247
|
|
|
248
248
|
### Example of validation report
|
|
@@ -256,27 +256,27 @@ Rows: 232230 | Columns: 5
|
|
|
256
256
|
CORRECT COLUMNS: 3/5
|
|
257
257
|
--------------------------------------------------
|
|
258
258
|
- County: [✔] OK
|
|
259
|
-
✔ -
|
|
259
|
+
✔ - regex: '^.*$'
|
|
260
260
|
- City: [✔] OK
|
|
261
|
-
✔ -
|
|
261
|
+
✔ - regex: '^.*$'
|
|
262
262
|
- Model Year: [✔] OK
|
|
263
|
-
✔ -
|
|
264
|
-
✔ -
|
|
265
|
-
✔ -
|
|
263
|
+
✔ - regex: '^[0-9]+$'
|
|
264
|
+
✔ - min: 1999
|
|
265
|
+
✔ - max: 2025.78
|
|
266
266
|
|
|
267
267
|
WRONG COLUMNS: 2/5
|
|
268
268
|
--------------------------------------------------
|
|
269
269
|
- State: [✖] FAIL
|
|
270
|
-
✖ -
|
|
271
|
-
"Wrong Rows: 93 | Sample: 'GA','NJ','CT','NJ','CT'
|
|
270
|
+
✖ - values: 'WA', 'OR', 'NY', 'DC', 'CA', 'TX', 'FL', 'OK', 'MO', 'KS', 'VA', 'MA', 'MO', 'NC', 'IL', 'AL', 'WY', 'CO', 'PA', 'WI', 'MD', 'NV', 'AZ'
|
|
271
|
+
"Wrong Rows: 93 | Sample: [row 12: 'GA'], [row 15: 'NJ'], [row 22: 'CT'], [row 23: 'NJ'], [row 24: 'CT']"
|
|
272
272
|
- Postal Code: [✖] FAIL
|
|
273
|
-
✔ -
|
|
274
|
-
✖ -
|
|
275
|
-
"Wrong Rows: 4 | Sample: '','','',''"
|
|
273
|
+
✔ - integer
|
|
274
|
+
✖ - non_empty
|
|
275
|
+
"Wrong Rows: 4 | Sample: [row 45: ''], [row 123: ''], [row 456: ''], [row 789: '']"
|
|
276
276
|
|
|
277
277
|
VALIDATION RESULT
|
|
278
278
|
--------------------------------------------------
|
|
279
|
-
[✖] FAIL: File DOESN'T match all validations
|
|
279
|
+
[✖] FAIL: File /test.csv DOESN'T match all validations
|
|
280
280
|
```
|
|
281
281
|
|
|
282
282
|
## Development
|
|
@@ -181,12 +181,12 @@ columns:
|
|
|
181
181
|
What you will see in the summary:
|
|
182
182
|
- Always shows the number of duplicate key groups found.
|
|
183
183
|
- If there are more than 100 duplicate groups, only the first 100 are displayed as a sample (with their occurrence counts), and the total number is indicated.
|
|
184
|
-
- If no duplicates are found, it reports: "
|
|
184
|
+
- If no duplicates are found, it reports: "No duplicates found".
|
|
185
185
|
|
|
186
186
|
Sample output (composite key):
|
|
187
187
|
|
|
188
188
|
```
|
|
189
|
-
UNIQUE KEY: column(s):
|
|
189
|
+
UNIQUE KEY: column(s): isin, date, score_provider
|
|
190
190
|
|
|
191
191
|
DUPLICATED KEYS (groups found: 134)
|
|
192
192
|
--------------------------------------------------
|
|
@@ -201,7 +201,7 @@ If none:
|
|
|
201
201
|
```
|
|
202
202
|
UNIQUE KEYS CHECK
|
|
203
203
|
--------------------------------------------------
|
|
204
|
-
- No
|
|
204
|
+
- No duplicates found
|
|
205
205
|
```
|
|
206
206
|
|
|
207
207
|
Performance note: Duplicate detection stores only the unique keys on disk and keeps a tiny in-memory summary used for printing the report. This allows validating huge datasets with minimal RAM usage.
|
|
@@ -230,7 +230,7 @@ validator.set_decimal_separator(",") # Use comma
|
|
|
230
230
|
The library provides detailed validation reports through Python's logging system. When a validation fails, you'll get information about:
|
|
231
231
|
- Which columns failed validation
|
|
232
232
|
- What type of validation failed
|
|
233
|
-
- Sample of invalid values
|
|
233
|
+
- Sample of invalid values (including row numbers)
|
|
234
234
|
- Number of rows that failed each validation
|
|
235
235
|
|
|
236
236
|
### Example of validation report
|
|
@@ -244,27 +244,27 @@ Rows: 232230 | Columns: 5
|
|
|
244
244
|
CORRECT COLUMNS: 3/5
|
|
245
245
|
--------------------------------------------------
|
|
246
246
|
- County: [✔] OK
|
|
247
|
-
✔ -
|
|
247
|
+
✔ - regex: '^.*$'
|
|
248
248
|
- City: [✔] OK
|
|
249
|
-
✔ -
|
|
249
|
+
✔ - regex: '^.*$'
|
|
250
250
|
- Model Year: [✔] OK
|
|
251
|
-
✔ -
|
|
252
|
-
✔ -
|
|
253
|
-
✔ -
|
|
251
|
+
✔ - regex: '^[0-9]+$'
|
|
252
|
+
✔ - min: 1999
|
|
253
|
+
✔ - max: 2025.78
|
|
254
254
|
|
|
255
255
|
WRONG COLUMNS: 2/5
|
|
256
256
|
--------------------------------------------------
|
|
257
257
|
- State: [✖] FAIL
|
|
258
|
-
✖ -
|
|
259
|
-
"Wrong Rows: 93 | Sample: 'GA','NJ','CT','NJ','CT'
|
|
258
|
+
✖ - values: 'WA', 'OR', 'NY', 'DC', 'CA', 'TX', 'FL', 'OK', 'MO', 'KS', 'VA', 'MA', 'MO', 'NC', 'IL', 'AL', 'WY', 'CO', 'PA', 'WI', 'MD', 'NV', 'AZ'
|
|
259
|
+
"Wrong Rows: 93 | Sample: [row 12: 'GA'], [row 15: 'NJ'], [row 22: 'CT'], [row 23: 'NJ'], [row 24: 'CT']"
|
|
260
260
|
- Postal Code: [✖] FAIL
|
|
261
|
-
✔ -
|
|
262
|
-
✖ -
|
|
263
|
-
"Wrong Rows: 4 | Sample: '','','',''"
|
|
261
|
+
✔ - integer
|
|
262
|
+
✖ - non_empty
|
|
263
|
+
"Wrong Rows: 4 | Sample: [row 45: ''], [row 123: ''], [row 456: ''], [row 789: '']"
|
|
264
264
|
|
|
265
265
|
VALIDATION RESULT
|
|
266
266
|
--------------------------------------------------
|
|
267
|
-
[✖] FAIL: File DOESN'T match all validations
|
|
267
|
+
[✖] FAIL: File /test.csv DOESN'T match all validations
|
|
268
268
|
```
|
|
269
269
|
|
|
270
270
|
## Development
|
|
@@ -336,7 +336,7 @@ fn validation_for_non_empty() -> Validation {
|
|
|
336
336
|
}
|
|
337
337
|
|
|
338
338
|
fn regex_for_non_empty() -> String {
|
|
339
|
-
String::from("^.+$")
|
|
339
|
+
String::from("(?s)^.+$")
|
|
340
340
|
}
|
|
341
341
|
|
|
342
342
|
fn validate_column_names(reader: &mut Reader<Box<dyn Read>>, validations: &Vec<ColumnValidations>) -> PyResult<bool> {
|
|
@@ -350,18 +350,29 @@ fn validate_column_names(reader: &mut Reader<Box<dyn Read>>, validations: &Vec<C
|
|
|
350
350
|
debug!("Actual Column Names: {:?}", headers);
|
|
351
351
|
|
|
352
352
|
if expected_column_names != headers {
|
|
353
|
+
info!("");
|
|
354
|
+
info!("COLUMNS VALIDATION");
|
|
355
|
+
info!("--------------------------------------------------");
|
|
353
356
|
if expected_column_names.len() != headers.len() {
|
|
354
|
-
info!("The number of columns in the CSV file doesn't match the validations:");
|
|
357
|
+
info!("[✖] The number of columns in the CSV file ({}) doesn't match the expected validations ({}):", headers.len(), expected_column_names.len());
|
|
355
358
|
let expected_columns_set: HashSet<String> = expected_column_names.iter().cloned().collect();
|
|
356
359
|
let headers_set: HashSet<String> = headers.iter().cloned().collect();
|
|
357
|
-
|
|
358
|
-
|
|
360
|
+
|
|
361
|
+
let unexpected: Vec<_> = headers_set.difference(&expected_columns_set).collect();
|
|
362
|
+
if !unexpected.is_empty() {
|
|
363
|
+
info!(" - Unexpected columns in CSV: {:?}", unexpected);
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
let missing: Vec<_> = expected_columns_set.difference(&headers_set).collect();
|
|
367
|
+
if !missing.is_empty() {
|
|
368
|
+
info!(" - Missing expected columns: {:?}", missing);
|
|
369
|
+
}
|
|
359
370
|
}
|
|
360
371
|
else {
|
|
361
|
-
info!("The CSV file has the same number of columns
|
|
362
|
-
for (expected_column, header) in zip(
|
|
372
|
+
info!("[✖] The CSV file has the same number of columns but some names or order are different:");
|
|
373
|
+
for (i, (expected_column, header)) in expected_column_names.iter().zip(headers.iter()).enumerate() {
|
|
363
374
|
if expected_column != header {
|
|
364
|
-
info!("{:?}
|
|
375
|
+
info!(" - Column {}: Expected {:?} but found {:?}", i + 1, expected_column, header);
|
|
365
376
|
}
|
|
366
377
|
}
|
|
367
378
|
}
|
|
@@ -510,13 +521,17 @@ impl CSVValidator {
|
|
|
510
521
|
let mut rdr = get_reader_from(file_path, self.separator)?;
|
|
511
522
|
|
|
512
523
|
// First validation: Ensure column names and order are exactly as expected
|
|
513
|
-
if validate_column_names(&mut rdr, &self.validations)? {
|
|
514
|
-
info!("Columns names and order are correct");
|
|
515
|
-
}
|
|
516
|
-
else {
|
|
524
|
+
if !validate_column_names(&mut rdr, &self.validations)? {
|
|
517
525
|
error!("Expected columns != File columns. Cannot continue with rest of the validations");
|
|
526
|
+
|
|
527
|
+
info!("");
|
|
528
|
+
info!("VALIDATION RESULT");
|
|
529
|
+
info!("--------------------------------------------------");
|
|
530
|
+
info!("[✖] FAIL: File {} DOESN'T match all validations", file_path);
|
|
531
|
+
info!("");
|
|
518
532
|
return Ok(false);
|
|
519
533
|
}
|
|
534
|
+
info!("Columns names and order are correct");
|
|
520
535
|
|
|
521
536
|
// Second validation: If column names match, check if also the values match the validations
|
|
522
537
|
let mut validation_summaries_map = build_validation_summaries_map(&self.validations);
|
|
@@ -817,6 +832,18 @@ mod tests {
|
|
|
817
832
|
SimpleLogger::new().init().unwrap();
|
|
818
833
|
}
|
|
819
834
|
|
|
835
|
+
#[test]
|
|
836
|
+
fn test_wrong_headers_same_count() {
|
|
837
|
+
let definition = String::from("
|
|
838
|
+
columns:
|
|
839
|
+
- name: First Column
|
|
840
|
+
- name: WRONG Second Column
|
|
841
|
+
- name: Third Column
|
|
842
|
+
");
|
|
843
|
+
let validator = CSVValidator::from_string(&definition).unwrap();
|
|
844
|
+
assert!(!validator.validate("test/test_file.csv").unwrap());
|
|
845
|
+
}
|
|
846
|
+
|
|
820
847
|
#[test]
|
|
821
848
|
fn test_wrong_headers() {
|
|
822
849
|
let definition = String::from("
|
|
@@ -923,6 +950,27 @@ mod tests {
|
|
|
923
950
|
assert!(!validator.validate("test/empty_values.csv").unwrap());
|
|
924
951
|
}
|
|
925
952
|
|
|
953
|
+
#[test]
|
|
954
|
+
fn test_non_empty_with_multiline_value() {
|
|
955
|
+
use std::fs;
|
|
956
|
+
let definition = String::from("
|
|
957
|
+
columns:
|
|
958
|
+
- name: ColumnA
|
|
959
|
+
extra: non_empty
|
|
960
|
+
");
|
|
961
|
+
|
|
962
|
+
let path_of_file_to_validate = "test/test_multiline_non_empty.csv";
|
|
963
|
+
let file_content = "ColumnA\n\"line1\nline2\"";
|
|
964
|
+
fs::write(path_of_file_to_validate, file_content).unwrap();
|
|
965
|
+
|
|
966
|
+
let validator = CSVValidator::from_string(&definition).unwrap();
|
|
967
|
+
let result = validator.validate(path_of_file_to_validate).unwrap();
|
|
968
|
+
|
|
969
|
+
fs::remove_file(path_of_file_to_validate).unwrap();
|
|
970
|
+
|
|
971
|
+
assert!(result, "non_empty validation failed for multiline value");
|
|
972
|
+
}
|
|
973
|
+
|
|
926
974
|
#[test]
|
|
927
975
|
fn test_unique_key_validation() {
|
|
928
976
|
let definition_with_non_empty_column = String::from("
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|