Autorefresh for Crdc_Dual_Enrollment#1738
Autorefresh for Crdc_Dual_Enrollment#1738Megha18jain wants to merge 4 commits intodatacommonsorg:masterfrom
Conversation
Summary of ChangesHello @Megha18jain, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request establishes a comprehensive and automated pipeline for importing school-level dual enrollment statistics from the U.S. Department of Education's Civil Rights Data Collection (CRDC) into Data Commons. The system is designed to regularly fetch, process, and map CRDC data, ensuring that up-to-date statistical variables related to dual enrollment, disaggregated by various demographic factors, are available. This automation ensures the data remains current and accessible for analysis. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a new data import pipeline for CRDC Dual Enrollment data, including scripts for downloading, preprocessing, and generating statistical variables. The overall structure is good, and the scripts are well-organized. I've provided a few suggestions to improve maintainability, robustness, and documentation clarity. Key points include making the data download script more dynamic, improving error handling in the preprocessing script to avoid silent data loss, and clarifying the instructions in the README.
| if file_path.suffix == ".xlsx": | ||
| df = pd.read_excel(file_path) | ||
| elif file_path.suffix == ".csv": | ||
| df = pd.read_csv(file_path, encoding='latin1', on_bad_lines='skip') |
There was a problem hiding this comment.
Using encoding='latin1' and on_bad_lines='skip' can hide issues with the source data. latin1 can read any byte stream without error, which might garble text if the actual encoding is different (like UTF-8). on_bad_lines='skip' can lead to silent data loss if some rows are malformed. It would be more robust to investigate the correct encoding of the source files and handle or log bad lines instead of skipping them. If these settings are intentional to handle known data quality issues, please add a comment explaining why.
| 3. **Generate the final output:** | ||
| After preprocessing, the data is ready to be imported into Data Commons using the `datacommons` command-line tool. |
There was a problem hiding this comment.
The instruction for generating the final output is a bit vague. It mentions using the datacommons command-line tool, but the manifest.json specifies a different script (stat_var_processor.py). To improve clarity for users, it would be helpful to provide the exact command to run, similar to the other steps.
| 3. **Generate the final output:** | |
| After preprocessing, the data is ready to be imported into Data Commons using the `datacommons` command-line tool. | |
| 3. **Generate the final output:** | |
| Run the statvar import script from the `statvar_imports/crdc_dual_enrollment` directory: | |
| ```bash | |
| python3 ../../tools/statvar_importer/stat_var_processor.py --input_data=preprocessed/*.csv --pv_map=dual_enrollment_pvmap.csv --config_file=metadata.csv --output_path=output/dual_output --existing_statvar_mcf=gs://unresolved_mcf/scripts/statvar/stat_vars.mcf | |
| ``` | |
| This will generate the final `.mcf`, `.tmcf`, and `.csv` files in the `output/` directory. |
| import shutil | ||
| import sys | ||
| from absl import app, flags, logging | ||
| import re |
| def generate_urls(): | ||
| """Generates the list of URLs to download.""" | ||
| urls = [] | ||
| for year in range(2012, 2025): |
There was a problem hiding this comment.
The end year in range(2012, 2025) is hardcoded. This will require manual updates in the future to download new data as it becomes available. To make the script more maintainable, consider making the end year dynamic based on the current year. You will also need to add import datetime at the top of the file.
| for year in range(2012, 2025): | |
| for year in range(2012, datetime.date.today().year + 2): |
| logging.info("Download and organization script finished.") | ||
|
|
||
| if __name__ == "__main__": | ||
| os.chdir(SCRIPT_DIRECTORY) |
There was a problem hiding this comment.
Using os.chdir() can be risky as it changes the current working directory for the entire process, which can lead to unexpected behavior. Since you are already using pathlib to construct absolute paths, it would be safer to rely on those and remove this line. If changing the directory is necessary for a downstream tool, consider wrapping its execution in a subprocess where you can control the CWD without affecting the main script.
| "scripts": [ | ||
| "download.py", | ||
| "preprocess.py", | ||
| "../../tools/statvar_importer/stat_var_processor.py --input_data=preprocessed/*.csv --pv_map=dual_enrollment_pvmap.csv --config_file=metadata.csv --output_path=output/dual_output --existing_statvar_mcf=gs://unresolved_mcf/scripts/statvar/stat_vars.mcf " |
There was a problem hiding this comment.
There is a trailing space at the end of this line. It's a minor style issue, but it's good practice to remove trailing whitespace.
| "../../tools/statvar_importer/stat_var_processor.py --input_data=preprocessed/*.csv --pv_map=dual_enrollment_pvmap.csv --config_file=metadata.csv --output_path=output/dual_output --existing_statvar_mcf=gs://unresolved_mcf/scripts/statvar/stat_vars.mcf " | |
| "../../tools/statvar_importer/stat_var_processor.py --input_data=preprocessed/*.csv --pv_map=dual_enrollment_pvmap.csv --config_file=metadata.csv --output_path=output/dual_output --existing_statvar_mcf=gs://unresolved_mcf/scripts/statvar/stat_vars.mcf" |
No description provided.