Skip to content

Fix Pandas compatibility, DCID collisions, and validation config for NCES_SchoolDistrict - #2175

Open
smarthg-gi wants to merge 1 commit into
datacommonsorg:masterfrom
smarthg-gi:NCES_SchoolDistrict_fix
Open

Fix Pandas compatibility, DCID collisions, and validation config for NCES_SchoolDistrict #2175
smarthg-gi wants to merge 1 commit into
datacommonsorg:masterfrom
smarthg-gi:NCES_SchoolDistrict_fix

Conversation

@smarthg-gi

Copy link
Copy Markdown
Contributor

Changes

  • Pandas 2.0+ Compatibility: Wrapped _PV_FORMAT inputs in tuple(pv) to resolve Series positional indexing KeyError: 1.
  • PyArrow RE2 Regex: Updated quantifier in _SCHOOL_GRADE_PATTERN from \d{,2} to \d{1,2} to restore grade-level StatVars in Pandas 3.0+.
  • DCID Collision Prevention: Added word boundaries to _GENDER regex and configured "Total Staff" population type to avoid duplicate StatVar collisions.
  • Dynamic DC API Root: Removed hardcoded 'dc_api_root': None to dynamically inherit os.environ['DC_API_ROOT'].
  • Validation: Configured validation_config.json with historical deletion threshold.

@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 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.

Comment on lines +136 to +139
# _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 ""

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.

medium

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
  1. PEP 8: Always use a def statement instead of an assignment statement that binds a lambda expression directly to an identifier. (link)

Comment on lines +440 to +441
'dc_api_use_cache': False
# 'dc_api_root': None # Inherits os.environ['DC_API_ROOT'] (autopush in test env / prod in prod env)

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.

medium

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.

Suggested change
'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,

Comment on lines +585 to +586
'dc_api_use_cache': False
# 'dc_api_root': None # Inherits os.environ['DC_API_ROOT'] (autopush in test env / prod in prod env)

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.

medium

Avoid leaving commented-out code in the codebase. Unused configuration options should be completely removed to keep the code clean and maintainable.

Suggested change
'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,

Comment on lines +750 to +751
'dc_api_use_cache': False
# 'dc_api_root': None # Inherits os.environ['DC_API_ROOT'] (autopush in test env / prod in prod env)

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.

medium

Avoid leaving commented-out code in the codebase. Unused configuration options should be completely removed to keep the code clean and maintainable.

Suggested change
'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,

Comment on lines +1055 to +1059
# 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")

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.

medium

Avoid leaving commented-out code blocks in the codebase. Since the logic is no longer needed due to the updated _GENDER regex boundaries, this block should be completely removed.

Comment on lines +375 to +377
# Original without word boundary caused "female" -> "FeMale":
# _GENDER = {"female": "Female", "male": "Male"}
_GENDER = {r"\bfemale\b": "Female", r"\bmale\b": "Male"}

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.

medium

Avoid leaving commented-out code in the codebase. The previous definition of _GENDER should be removed to keep the file clean.

Suggested change
# 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"}

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.

1 participant