-
Notifications
You must be signed in to change notification settings - Fork 138
Script to generate and validate goldens for an import #1905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
c641f9f
Support 0 eval results
ajaits 58b4253
Goldens validator for import
ajaits 4128621
fix golden csv output
ajaits 857cbde
fix goldens generator
ajaits 2960346
move data_sampler to seperate pr
ajaits 0252583
add GOLDENS validator
ajaits 92f4dcc
self review
ajaits 9ac07d5
lint
ajaits c8eb263
update master
ajaits ca499d2
sync
ajaits 543e8f5
gemini review
ajaits 0579ee6
gemini review
ajaits c515da5
Merge branch 'master' of https://github.com/datacommonsorg/data into …
ajaits fb01985
fix review comments
ajaits 8cf761c
Merge branch 'master' of https://github.com/datacommonsorg/data into …
ajaits 200ba39
Merge branch 'master' of https://github.com/datacommonsorg/data into …
ajaits 0ee2e4e
review comments
ajaits a18c676
lint
ajaits a0ec13f
fix tests
ajaits c130826
update readme
ajaits 5257056
gemini review
ajaits f17b874
update readme
ajaits File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
6 changes: 6 additions & 0 deletions
6
scripts/us_fed/treasury_constant_maturity_rates/golden_data/golden_summary_report.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| StatVar,NumPlaces,MinDate,MeasurementMethods,Units | ||
| InterestRate_TreasuryNote_3Year,1,1962-01-02,[ConstantMaturityRate],[Percent] | ||
| InterestRate_TreasuryBond_20Year,1,1962-01-02,[ConstantMaturityRate],[Percent] | ||
| InterestRate_TreasuryNote_5Year,1,1962-01-02,[ConstantMaturityRate],[Percent] | ||
| InterestRate_TreasuryNote_10Year,1,1962-01-02,[ConstantMaturityRate],[Percent] | ||
| InterestRate_TreasuryBill_1Year,1,1962-01-02,[ConstantMaturityRate],[Percent] |
4 changes: 4 additions & 0 deletions
4
.../treasury_constant_maturity_rates/golden_data/golden_treasury_constant_maturity_rates.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| date,1-Month,3-Month,6-Month,1-Year,2-Year,3-Year,5-Year,7-Year,10-Year,20-Year,30-Year | ||
| 1962-01-02,,,,3.22,,3.70,3.88,,4.06,4.07, | ||
| 1962-02-01,,,,3.30,,3.81,4.00,,4.09,4.13, | ||
| 1962-04-19,,,,3.00,,3.37,3.60,,3.82,3.91, |
20 changes: 20 additions & 0 deletions
20
scripts/us_fed/treasury_constant_maturity_rates/validation_config.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| { | ||
| "schema_version": "1.0", | ||
| "rules": [ | ||
| { | ||
| "rule_id": "check_goldens_output_csv", | ||
| "validator": "GOLDENS_CHECK", | ||
| "params": { | ||
| "golden_files": "golden_data/golden_treasury_constant_maturity_rates.csv", | ||
| "input_files": "treasury_constant_maturity_rates.csv" | ||
| } | ||
| }, | ||
| { | ||
| "rule_id": "check_goldens_summary_report", | ||
| "validator": "GOLDENS_CHECK", | ||
| "params": { | ||
| "golden_files": "golden_data/golden_summary_report.csv" | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| # Validation Config. | ||
|
|
||
| The default validations in [validation_config.json](validation_config.json) are | ||
| applied for all imports in auto refresh. | ||
|
|
||
| To add additional import specific validations, create a validation_config.json | ||
| in the import script folder and add it to the | ||
| config_overrides.validation_config_file parameter in the manifest.json. | ||
|
|
||
| To override or disable a default validation rule, copy the rule to the | ||
| import specific config with the same rule id and | ||
| set the `enabled` setting to false. | ||
|
|
||
| Here is an example to override the deleted records threshold and | ||
| disable lint check for a specific import. | ||
| ```json | ||
| { | ||
| "schema_version": "1.0", | ||
| "rules": [ | ||
| { | ||
| "rule_id": "check_deleted_records_percent", | ||
| "description": "Override default threshold to 10%", | ||
| "validator": "DELETED_RECORDS_PERCENT", | ||
| "params": { | ||
| "threshold": 10 | ||
| } | ||
| }, | ||
| { | ||
| "rule_id": "check_lint_error_count", | ||
| "enabled": false, | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
| Here are some additional details for each validation rule. | ||
|
|
||
| ## Golden Set Validation with `GOLDENS_CHECK` | ||
|
|
||
| The `GOLDENS_CHECK` validator ensures that the import contains a specific set of expected records. This is useful for verifying that critical StatVars, Places, or specific metadata combinations are always present in the output. | ||
|
|
||
| The validator compares the input data (usually from the `stats` data source) against one or more "golden" files (MCF or CSV). | ||
|
|
||
| If any of the combination of values in a row of the golden file is not present | ||
| in the input, the validation is treated as a failure. | ||
| The missing golden rows are listed in the validation report json. | ||
|
|
||
| ### Configuration Parameters | ||
| - `golden_files`: A list or glob pattern of golden MCF or CSV files to compare against. | ||
| - `goldens_key_property`: A list of properties to match on. If not specified, all properties in the golden record must match. | ||
| - `input_files`: (Optional) A list of glob pattern of input files to be compared with goldens. If not provided, the data source defined in the rule's `scope` is used. | ||
|
|
||
| ### GOLDENS_CHECK Validator Example | ||
|
|
||
| **Rule:** "Ensure that observations for `Count_Person` and `Median_Age_Person` are present in the import as defined in our critical golden set." | ||
|
|
||
| ```json | ||
| { | ||
| "rule_id": "verify_critical_obs", | ||
| "validator": "GOLDENS_CHECK", | ||
| "params": { | ||
| "golden_files": ["golden_data/critical_stats.csv"], | ||
| "input_files": "processed_obs.csv" | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The goldens can be generated from a CSV file using the `validator_goldens.py` | ||
| script. | ||
|
|
||
| To generate goldens for the summary_report.csv to verify that all the expected | ||
| StatVars are generated with the corresponding number of places and dates, run | ||
| the following: | ||
|
|
||
| ```shell | ||
| python3 validator_goldens.py \ | ||
| --validate_goldens_input=summary_report.csv \ | ||
| --generate_goldens=goldens_data/golden_summary_report.csv \ | ||
| --generate_goldens_property_sets="StatVar|NumPlaces|MinDate|MeasurementMethods|Units|ScalingFactors|observationPeriods" | ||
| ``` | ||
|
|
||
| To generate goldens for observations that include important | ||
| statvars, places and dates, run the following with selected StatVar and | ||
| place dcids loaded from txt files: | ||
|
|
||
| ```shell | ||
| python3 validator_goldens.py \ | ||
| --validate_goldens_input=output/observations.csv \ | ||
| --generate_goldens=golden_data/golden_observations.csv \ | ||
| --goldens_must_include="variableMeasured:gs://unresolved_mcf/import_validation/nl_statvars.csv,observationAbout:gs://unresolved_mcf/import_validation/top_100k_places.csv" \ | ||
| --generate_goldens_property_sets="variableMeasured|unit|scalingFactor|observationPeriod|measurementMethod,observationAbout,observationDate" | ||
| ``` | ||
|
|
||
| To enable goldens validation with files generated above | ||
| while relaxing the default deleted records threshold, add the following | ||
| valiation rules to the validation config: | ||
|
|
||
| ```json | ||
| { | ||
| "schema_version": "1.0", | ||
| "rules": [ | ||
| { | ||
| "rule_id": "check_deleted_records_percent", | ||
| "description": "Relax default deleted records threshold to 10% with additional goldens check to catch statvar series deletions", | ||
| "validator": "DELETED_RECORDS_PERCENT", | ||
| "params": { | ||
| "threshold": 10 | ||
| } | ||
| }, | ||
| { | ||
| "rule_id": "check_golden_summary_report", | ||
| "validator": "GOLDENS_CHECK", | ||
| "params": { | ||
| "golden_files": "golden_data/golden_summary_report.csv" | ||
| } | ||
| }, | ||
| { | ||
| "rule_id": "check_golden_observations_statvar_places_dates", | ||
| "validator": "GOLDENS_CHECK", | ||
| "params": { | ||
| "golden_files": "golden_data/golden_observations.csv" | ||
| "input_files": "output/observations.csv" | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.