Fix Pandas compatibility, DCID collisions, and validation config for NCES_SchoolDistrict - #2175
Fix Pandas compatibility, DCID collisions, and validation config for NCES_SchoolDistrict #2175smarthg-gi wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces several updates to the US NCES demographics processing, including adding 'Total Staff' mapping, fixing a regex pattern for school grades, adding word boundaries to gender replacement keys to prevent incorrect replacements, fixing a missing comma in the school district configuration, and adding a validation configuration. The reviewer feedback recommends replacing the lambda assignment for _PV_FORMAT with a standard function to comply with PEP 8 and improve performance. Additionally, the reviewer advises completely removing various commented-out code blocks across the modified files to keep the codebase clean.
| # _PV_FORMAT = lambda prop_val: f'"{prop_val[0]}": "dcs:{prop_val[1]}"' \ | ||
| # if 'None' not in prop_val[1] else "" | ||
| _PV_FORMAT = lambda pv: f'"{tuple(pv)[0]}": "dcs:{tuple(pv)[1]}"' \ | ||
| if 'None' not in str(tuple(pv)[1]) else "" |
There was a problem hiding this comment.
According to PEP 8, you should always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier. Additionally, calling tuple(pv) three times within the lambda is inefficient. Defining a proper helper function improves both readability and performance.
def _PV_FORMAT(pv):
t = tuple(pv)
return f'"{t[0]}": "dcs:{t[1]}"' if 'None' not in str(t[1]) else ""References
- PEP 8: Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier. (link)
| 'dc_api_use_cache': False | ||
| # 'dc_api_root': None # Inherits os.environ['DC_API_ROOT'] (autopush in test env / prod in prod env) |
There was a problem hiding this comment.
Avoid leaving commented-out code in the codebase. Since version control tracks history, unused configuration options should be completely removed to keep the code clean and maintainable.
| 'dc_api_use_cache': False | |
| # 'dc_api_root': None # Inherits os.environ['DC_API_ROOT'] (autopush in test env / prod in prod env) | |
| 'dc_api_use_cache': False, |
| 'dc_api_use_cache': False | ||
| # 'dc_api_root': None # Inherits os.environ['DC_API_ROOT'] (autopush in test env / prod in prod env) |
There was a problem hiding this comment.
Avoid leaving commented-out code in the codebase. Unused configuration options should be completely removed to keep the code clean and maintainable.
| 'dc_api_use_cache': False | |
| # 'dc_api_root': None # Inherits os.environ['DC_API_ROOT'] (autopush in test env / prod in prod env) | |
| 'dc_api_use_cache': False, |
| 'dc_api_use_cache': False | ||
| # 'dc_api_root': None # Inherits os.environ['DC_API_ROOT'] (autopush in test env / prod in prod env) |
There was a problem hiding this comment.
Avoid leaving commented-out code in the codebase. Unused configuration options should be completely removed to keep the code clean and maintainable.
| 'dc_api_use_cache': False | |
| # 'dc_api_root': None # Inherits os.environ['DC_API_ROOT'] (autopush in test env / prod in prod env) | |
| 'dc_api_use_cache': False, |
| # Commented out: _GENDER in replacement_functions now uses word boundaries (\bfemale\b) | ||
| # so "FeMale" is never generated. | ||
| # for col in df_parsed.columns.values.tolist(): | ||
| # df_parsed[col] = df_parsed[col].astype( | ||
| # 'str').str.replace("FeMale", "Female") |
| # Original without word boundary caused "female" -> "FeMale": | ||
| # _GENDER = {"female": "Female", "male": "Male"} | ||
| _GENDER = {r"\bfemale\b": "Female", r"\bmale\b": "Male"} |
There was a problem hiding this comment.
Avoid leaving commented-out code in the codebase. The previous definition of _GENDER should be removed to keep the file clean.
| # Original without word boundary caused "female" -> "FeMale": | |
| # _GENDER = {"female": "Female", "male": "Male"} | |
| _GENDER = {r"\bfemale\b": "Female", r"\bmale\b": "Male"} | |
| _GENDER = {r"\bfemale\b": "Female", r"\bmale\b": "Male"} |
Changes
_PV_FORMATinputs intuple(pv)to resolve Series positional indexingKeyError: 1._SCHOOL_GRADE_PATTERNfrom\d{,2}to\d{1,2}to restore grade-level StatVars in Pandas 3.0+._GENDERregex and configured"Total Staff"population type to avoid duplicate StatVar collisions.'dc_api_root': Noneto dynamically inheritos.environ['DC_API_ROOT'].validation_config.jsonwith historical deletion threshold.