Automation of import Finland_Census #2087
Conversation
There was a problem hiding this comment.
Code Review
This pull request automates the import process for the Finland Demographics Dataset by introducing a data_download.py script to fetch data from the Statistics Finland PxWeb API and a run.sh script to orchestrate the download and processing. The README.md and manifest.json have been updated to document and support this automated refresh. Feedback on the changes suggests using the standard csv module in data_download.py to robustly parse headers containing commas, and quoting the wildcard pattern in run.sh to prevent unintended shell expansion.
|
@smarthg-gi : Please add golden checks to the validation |
Added golden checks |
| from absl import logging | ||
| import download_util | ||
|
|
||
| try: |
There was a problem hiding this comment.
Why are we putting the import functionality in try catch block?
There was a problem hiding this comment.
Updated the code
| ) | ||
| return area_code, info_code, year_code | ||
| except Exception as e: | ||
| raise RuntimeError(f'Error fetching variable codes: {e}') from e |
There was a problem hiding this comment.
Any reasons, why we have raised the error here. IMO, this should be a logging statement
There was a problem hiding this comment.
Updated the code, logging is also not required since we are fetching all the variables
| year_code, | ||
| ) | ||
|
|
||
| query = { |
There was a problem hiding this comment.
Add the purpose of these filters either in the README file or as a comment in the code here
There was a problem hiding this comment.
Updated in the code comments
| content = content_bytes.decode('utf-8-sig') | ||
| formatted_content = format_csv_content(content) | ||
|
|
||
| if FileIO: |
There was a problem hiding this comment.
Why we have written two file I/O code statements. I believe we can have all of them without if statement
| header_line = lines[0] | ||
| num_columns = len(next(csv.reader(io.StringIO(header_line)))) | ||
|
|
||
| title = '"Key figures on population by Area, Information and Year"' |
There was a problem hiding this comment.
Any reasons for adding a title line and blank line?
There was a problem hiding this comment.
API download fetches pure data without metadata. Title and blank lines are added to match the pvmap layout.
| ], | ||
| "provenance_url": "https://pxdata.stat.fi/PxWeb/pxweb/en/StatFin/StatFin__vaerak/statfin_vaerak_pxt_11ra.px/table/tableViewLayout1/", | ||
| "provenance_description": "Population data for Finland", | ||
| "provenance_url": "https://stat.fi/en", |
There was a problem hiding this comment.
Provenance URL should be same as provenance URL in CL
| "input_files/*.csv" | ||
| ], | ||
| "cron_schedule": "30 5 1 * *" | ||
| "cron_schedule": "00 05 1,15 * *", |
There was a problem hiding this comment.
Make it a monthly execution rather than fortnightly
| } | ||
| }, | ||
| { | ||
| "rule_id": "Check_goldens_summary_report", |
There was a problem hiding this comment.
Rule I'd should follow the same camel case across all rules
smarthg-gi
left a comment
There was a problem hiding this comment.
Added the comments
Import name =
Finland_CensusPR checklist = Doc
Overview
Automation of Finland Demographics Dataset (
Finland_Census) understatvar_imports/.Key Changes
data_download.pywhich leverages existingutil/download_util.pyfor data download.run.shandmanifest.jsonwith the correct cron schedule and file paths to trigger the download and processing of the data.test_data/.Verification & Validation Proofs
Local CI Presubmit:
./run_tests.sh -apasses 100% (unit tests +yapf --style=googleformatting check).Verification:
stat_var_processor.pyexecuted againsttest_data/finland_census_input.csv;git diff test_data/is clean.Data Commons Lint Check: Executed
java -jar datacommons-import-tool.jar lint output_files/*.csv.Result: 0 errors, 0 warnings. All generated StatVar DCIDs and TMCF references conform to schema rules.