Skip to content

Automation of import Finland_Census #2087

Open
smarthg-gi wants to merge 10 commits into
datacommonsorg:masterfrom
smarthg-gi:Finland_Census_automation
Open

Automation of import Finland_Census #2087
smarthg-gi wants to merge 10 commits into
datacommonsorg:masterfrom
smarthg-gi:Finland_Census_automation

Conversation

@smarthg-gi

@smarthg-gi smarthg-gi commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Import name = Finland_Census
PR checklist = Doc

Overview

Automation of Finland Demographics Dataset ( Finland_Census) under statvar_imports/.

Key Changes

  • Addition of data_download.py which leverages existing util/download_util.py for data download.
  • Updated run.sh and manifest.json with the correct cron schedule and file paths to trigger the download and processing of the data.
  • Executed unit test suite and sample test fixtures under test_data/.

Verification & Validation Proofs

Local CI Presubmit: ./run_tests.sh -a passes 100% (unit tests + yapf --style=google formatting check).
Verification: stat_var_processor.py executed against test_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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread statvar_imports/finland_census/data_download.py Outdated
Comment thread statvar_imports/finland_census/run.sh Outdated
@smarthg-gi smarthg-gi changed the title Automation of import refresh Automation of import Finland_Census Jul 8, 2026
@pulkeet-wq

Copy link
Copy Markdown
Contributor

@smarthg-gi : Please add golden checks to the validation

@smarthg-gi

Copy link
Copy Markdown
Contributor Author

@smarthg-gi : Please add golden checks to the validation

Added golden checks

from absl import logging
import download_util

try:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we putting the import functionality in try catch block?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code

)
return area_code, info_code, year_code
except Exception as e:
raise RuntimeError(f'Error fetching variable codes: {e}') from e

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reasons, why we have raised the error here. IMO, this should be a logging statement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the code, logging is also not required since we are fetching all the variables

year_code,
)

query = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the purpose of these filters either in the README file or as a comment in the code here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated in the code comments

content = content_bytes.decode('utf-8-sig')
formatted_content = format_csv_content(content)

if FileIO:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we have written two file I/O code statements. I believe we can have all of them without if statement

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code updated

header_line = lines[0]
num_columns = len(next(csv.reader(io.StringIO(header_line))))

title = '"Key figures on population by Area, Information and Year"'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any reasons for adding a title line and blank line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Provenance URL should be same as provenance URL in CL

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

"input_files/*.csv"
],
"cron_schedule": "30 5 1 * *"
"cron_schedule": "00 05 1,15 * *",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it a monthly execution rather than fortnightly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

}
},
{
"rule_id": "Check_goldens_summary_report",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule I'd should follow the same camel case across all rules

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated

@smarthg-gi smarthg-gi left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comments

@balit-raibot balit-raibot requested a review from pulkeet-wq July 15, 2026 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants