csv-validation 0.0.14__tar.gz → 0.0.16__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.0.14 → csv_validation-0.0.16}/.github/workflows/CI.yml +1 -1
- {csv_validation-0.0.14 → csv_validation-0.0.16}/Cargo.lock +1 -1
- {csv_validation-0.0.14 → csv_validation-0.0.16}/Cargo.toml +1 -1
- {csv_validation-0.0.14 → csv_validation-0.0.16}/PKG-INFO +1 -1
- {csv_validation-0.0.14 → csv_validation-0.0.16}/README.md +8 -5
- {csv_validation-0.0.14 → csv_validation-0.0.16}/src/lib.rs +29 -24
- {csv_validation-0.0.14 → csv_validation-0.0.16}/.gitignore +0 -0
- {csv_validation-0.0.14 → csv_validation-0.0.16}/LICENSE +0 -0
- {csv_validation-0.0.14 → csv_validation-0.0.16}/MANIFEST.in +0 -0
- {csv_validation-0.0.14 → csv_validation-0.0.16}/build.sh +0 -0
- {csv_validation-0.0.14 → csv_validation-0.0.16}/csv_validation.pyi +0 -0
- {csv_validation-0.0.14 → csv_validation-0.0.16}/pyproject.toml +0 -0
- {csv_validation-0.0.14 → csv_validation-0.0.16}/test/empty_values.csv +0 -0
- {csv_validation-0.0.14 → csv_validation-0.0.16}/test/test_file.csv +0 -0
- {csv_validation-0.0.14 → csv_validation-0.0.16}/test/test_file.csv.gz +0 -0
- {csv_validation-0.0.14 → csv_validation-0.0.16}/test/test_validations.yml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: csv_validation
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.16
|
|
4
4
|
Classifier: Programming Language :: Rust
|
|
5
5
|
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
6
6
|
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
@@ -94,13 +94,16 @@ columns:
|
|
|
94
94
|
- Available formats:
|
|
95
95
|
- `integer`: Validates any integer number (positive or negative)
|
|
96
96
|
- `positive integer`: Validates positive integer numbers
|
|
97
|
-
- `
|
|
97
|
+
- `negative integer`: Validates negative integer numbers
|
|
98
|
+
- `decimal`/`decimal point`: Validates any decimal number (positive or negative) using point as decimal separator
|
|
99
|
+
- `negative decimal point`: Validates negative decimal numbers using point as decimal separator
|
|
98
100
|
- `decimal comma`: Validates decimal numbers using comma as decimal separator
|
|
99
|
-
- `positive decimal
|
|
101
|
+
- `positive decimal`/`positive decimal point`: Validates positive decimal numbers using point as decimal separator
|
|
100
102
|
- `positive decimal comma`: Validates positive decimal numbers using comma as decimal separator
|
|
101
|
-
- `decimal scientific`: Validates decimal numbers in scientific notation (e.g.
|
|
102
|
-
- `
|
|
103
|
-
|
|
103
|
+
- `decimal scientific`: Validates decimal numbers in scientific notation (e.g. 23.02e-12)
|
|
104
|
+
- `decimal scientific comma`: Validates decimal numbers in scientific notation using comma as decimal separator
|
|
105
|
+
- `positive decimal scientific`: Validates positive decimal numbers in scientific notation
|
|
106
|
+
- More formats will be added in upcoming versions
|
|
104
107
|
|
|
105
108
|
3. **Minimum Value** (`min`)
|
|
106
109
|
- Check if numeric fields are greater than or equal to a specified value
|
|
@@ -67,7 +67,7 @@ struct ColumnValidations {
|
|
|
67
67
|
struct ValidationSummary {
|
|
68
68
|
validation: Validation,
|
|
69
69
|
wrong_rows: usize,
|
|
70
|
-
|
|
70
|
+
samples_rownum_and_wrong_value: Vec<(usize, String)>
|
|
71
71
|
}
|
|
72
72
|
|
|
73
73
|
#[derive(Serialize, Deserialize)]
|
|
@@ -87,11 +87,11 @@ struct FileValidationSummary {
|
|
|
87
87
|
|
|
88
88
|
impl ValidationSummary {
|
|
89
89
|
fn get_wrong_values_details(&self) -> String {
|
|
90
|
-
let wrong_samples = &self.
|
|
90
|
+
let wrong_samples = &self.samples_rownum_and_wrong_value
|
|
91
91
|
.iter()
|
|
92
|
-
.map(|s| format!("'{}'", s))
|
|
92
|
+
.map(|s| format!("[row {}: '{}']", s.0, s.1))
|
|
93
93
|
.collect::<Vec<String>>()
|
|
94
|
-
.join(",");
|
|
94
|
+
.join(", ");
|
|
95
95
|
format!("Wrong Rows: {} | Sample: {}", self.wrong_rows, wrong_samples)
|
|
96
96
|
}
|
|
97
97
|
}
|
|
@@ -102,7 +102,7 @@ fn build_validation_summaries_map(validations: &Vec<ColumnValidations>) -> HashM
|
|
|
102
102
|
let mut validation_summaries = Vec::new();
|
|
103
103
|
for column_validation in &validation.validations {
|
|
104
104
|
let validation_summary =
|
|
105
|
-
ValidationSummary{validation: (*column_validation).clone(), wrong_rows: 0,
|
|
105
|
+
ValidationSummary{validation: (*column_validation).clone(), wrong_rows: 0, samples_rownum_and_wrong_value: Vec::new()};
|
|
106
106
|
validation_summaries.push(validation_summary);
|
|
107
107
|
}
|
|
108
108
|
validation_summaries_map.insert(validation.column_name.clone(), validation_summaries);
|
|
@@ -155,7 +155,7 @@ fn get_validations(definition_string: &str) -> PyResult<Vec<ColumnValidations>>
|
|
|
155
155
|
// Read the YAML definition with the validations
|
|
156
156
|
let config = YamlLoader::load_from_str(definition_string)
|
|
157
157
|
.map_err(|e| PyRuntimeError::new_err(format!("Invalid YAML format: {}", e)))?;
|
|
158
|
-
|
|
158
|
+
|
|
159
159
|
if config.is_empty() {
|
|
160
160
|
return Err(PyRuntimeError::new_err("Empty YAML definition"));
|
|
161
161
|
}
|
|
@@ -178,7 +178,7 @@ fn get_validations(definition_string: &str) -> PyResult<Vec<ColumnValidations>>
|
|
|
178
178
|
for column in columns_vec {
|
|
179
179
|
let column_def = column.as_hash()
|
|
180
180
|
.ok_or_else(|| PyRuntimeError::new_err("Invalid YAML: each column must be a mapping"))?;
|
|
181
|
-
|
|
181
|
+
|
|
182
182
|
let mut column_name = "";
|
|
183
183
|
let mut validations = vec![];
|
|
184
184
|
|
|
@@ -186,7 +186,7 @@ fn get_validations(definition_string: &str) -> PyResult<Vec<ColumnValidations>>
|
|
|
186
186
|
let key = validation_definition.0.as_str()
|
|
187
187
|
.ok_or_else(|| PyRuntimeError::new_err("Invalid YAML: validation key must be a string"))?;
|
|
188
188
|
let value = validation_definition.1;
|
|
189
|
-
|
|
189
|
+
|
|
190
190
|
let validation = match key {
|
|
191
191
|
"name" => {
|
|
192
192
|
column_name = value.as_str()
|
|
@@ -197,9 +197,9 @@ fn get_validations(definition_string: &str) -> PyResult<Vec<ColumnValidations>>
|
|
|
197
197
|
"regex" => {
|
|
198
198
|
let expr = value.as_str()
|
|
199
199
|
.ok_or_else(|| PyRuntimeError::new_err("Regex must be a string"))?;
|
|
200
|
-
Ok(Validation::RegularExpression {
|
|
201
|
-
expression: String::from(expr),
|
|
202
|
-
alias: String::from("regex")
|
|
200
|
+
Ok(Validation::RegularExpression {
|
|
201
|
+
expression: String::from(expr),
|
|
202
|
+
alias: String::from("regex")
|
|
203
203
|
})
|
|
204
204
|
}
|
|
205
205
|
"min" => {
|
|
@@ -226,9 +226,9 @@ fn get_validations(definition_string: &str) -> PyResult<Vec<ColumnValidations>>
|
|
|
226
226
|
let format = value.as_str()
|
|
227
227
|
.ok_or_else(|| PyRuntimeError::new_err("Format must be a string"))?;
|
|
228
228
|
let regex_for_format = get_regex_for_format(format)?;
|
|
229
|
-
Ok(Validation::RegularExpression {
|
|
230
|
-
expression: regex_for_format,
|
|
231
|
-
alias: format.to_string()
|
|
229
|
+
Ok(Validation::RegularExpression {
|
|
230
|
+
expression: regex_for_format,
|
|
231
|
+
alias: format.to_string()
|
|
232
232
|
})
|
|
233
233
|
}
|
|
234
234
|
"extra" => {
|
|
@@ -282,11 +282,14 @@ fn get_regex_for_format(format: &str) -> PyResult<String> {
|
|
|
282
282
|
match format {
|
|
283
283
|
"integer" => Ok(String::from("^$|^-?\\d+$")),
|
|
284
284
|
"positive integer" => Ok(String::from("^$|^\\d+$")),
|
|
285
|
+
"negative integer" => Ok(String::from("^$|^-\\d+$")),
|
|
285
286
|
"decimal" | "decimal point" => Ok(String::from("^$|^-?\\d+(\\.\\d+)?$")),
|
|
287
|
+
"negative decimal point" => Ok(String::from("^$|^-\\d+(\\.\\d+)?$")),
|
|
286
288
|
"decimal comma" => Ok(String::from("^$|^-?\\d+(,\\d+)?$")),
|
|
287
289
|
"positive decimal point" | "positive decimal" => Ok(String::from("^$|^\\d+(\\.\\d+)?$")),
|
|
288
290
|
"positive decimal comma" => Ok(String::from("^$|^\\d+(,\\d+)?$")),
|
|
289
291
|
"decimal scientific" => Ok(String::from("^$|^-?\\d+(\\.\\d+)?([eE][-+]?\\d+)?$")),
|
|
292
|
+
"decimal scientific comma" => Ok(String::from("^$|^-?\\d+(\\,\\d+)?([eE][-+]?\\d+)?$")),
|
|
290
293
|
"positive decimal scientific" => Ok(String::from("^$|^\\d+(\\.\\d+)?([eE][-+]?\\d+)?$")),
|
|
291
294
|
_ => Err(PyRuntimeError::new_err(format!("Unknown format: {format}")))
|
|
292
295
|
}
|
|
@@ -388,7 +391,7 @@ impl CSVValidator {
|
|
|
388
391
|
fn from_string(definition_string: &str) -> PyResult<Self> {
|
|
389
392
|
let validations = get_validations(definition_string)?;
|
|
390
393
|
let mut regex_map = HashMap::new();
|
|
391
|
-
|
|
394
|
+
|
|
392
395
|
// Pre-Compile and save all Regex expressions
|
|
393
396
|
for column_validation in &validations {
|
|
394
397
|
for validation in &column_validation.validations {
|
|
@@ -486,8 +489,10 @@ impl CSVValidator {
|
|
|
486
489
|
.unwrap();
|
|
487
490
|
|
|
488
491
|
validation_summary.wrong_rows += 1;
|
|
489
|
-
if validation_summary.
|
|
490
|
-
|
|
492
|
+
if validation_summary.samples_rownum_and_wrong_value.len() < MAX_SAMPLE_SIZE as usize {
|
|
493
|
+
let wrong_value = value.to_string();
|
|
494
|
+
let wrong_rownum = validated_rows + 1;
|
|
495
|
+
validation_summary.samples_rownum_and_wrong_value.push((wrong_rownum, wrong_value));
|
|
491
496
|
}
|
|
492
497
|
}
|
|
493
498
|
is_valid_file = is_valid_file && valid;
|
|
@@ -556,7 +561,7 @@ impl CSVValidator {
|
|
|
556
561
|
info!("[✔] OK - File matches the validations");
|
|
557
562
|
}
|
|
558
563
|
else {
|
|
559
|
-
info!("[✖] FAIL: File DOESN'T match all validations");
|
|
564
|
+
info!("[✖] FAIL: File {} DOESN'T match all validations", file_path);
|
|
560
565
|
}
|
|
561
566
|
info!("");
|
|
562
567
|
Ok(is_valid_file)
|
|
@@ -944,7 +949,7 @@ mod tests {
|
|
|
944
949
|
|
|
945
950
|
test_format_validation("decimal scientific", test_cases);
|
|
946
951
|
}
|
|
947
|
-
|
|
952
|
+
|
|
948
953
|
// Helper function to test format validations
|
|
949
954
|
fn test_format_validation(format: &str, test_cases: Vec<(&str, bool)>) {
|
|
950
955
|
let definition = format!("
|
|
@@ -959,16 +964,16 @@ mod tests {
|
|
|
959
964
|
let test_csv = format!("Test\n{}", value);
|
|
960
965
|
let temp_file = format!("test/temp_format_test_{}.csv", format.replace(" ", "_"));
|
|
961
966
|
std::fs::write(&temp_file, test_csv).unwrap();
|
|
962
|
-
|
|
967
|
+
|
|
963
968
|
let result = validator.validate(&temp_file).unwrap();
|
|
964
969
|
assert_eq!(
|
|
965
|
-
result,
|
|
966
|
-
expected,
|
|
967
|
-
"Format '{}' validation failed for value '{}': expected {}, got {}",
|
|
970
|
+
result,
|
|
971
|
+
expected,
|
|
972
|
+
"Format '{}' validation failed for value '{}': expected {}, got {}",
|
|
968
973
|
format, value, expected, result
|
|
969
974
|
);
|
|
970
975
|
|
|
971
976
|
std::fs::remove_file(&temp_file).unwrap();
|
|
972
977
|
}
|
|
973
978
|
}
|
|
974
|
-
}
|
|
979
|
+
}
|
|
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
|