Detect Schema Drift
~12 mincode completion
Implement detect_schema_drift(old_schema, new_schema).
Examples
One new column added, one type changed, none removed
- Input
- detect_schema_drift({"a": "float", "b": "str"}, {"a": "int", "b": "str", "c": "bool"})
- Output
- {"added": ["c"], "removed": [], "type_changed": ["a"]}
One column removed, no other changes
- Input
- detect_schema_drift({"x": "int", "y": "float"}, {"x": "int"})
- Output
- {"added": [], "removed": ["y"], "type_changed": []}
Identical schemas: no drift detected
- Input
- detect_schema_drift({"name": "str"}, {"name": "str"})
- Output
- {"added": [], "removed": [], "type_changed": []}
Hints
Hint 1
Sorting first makes the rest straightforward.
Hint 2
Do not forget to sort output lists. That step is easy to skip.
Requirements
Implement
detect_schema_driftand return its result.
Constraints
Standard library only, no imports required
Time limit: 200 ms, Memory: 64 MB
Where this shows up
~12 min
••••••••••••••••
8 employers weight this skill
2 health and bio companies, 2 AI product companies, 1 defense company, 1 enterprise vendor, 1 quant fund, 1 big tech firm. Top match scores 87.
Python
def detect_schema_drift(old_schema: dict, new_schema: dict) -> dict:
"""
Detect schema drift between two column-to-dtype dictionaries.
Returns a dict with three sorted lists:
"added"columns in new_schema but not old_schema
"removed"columns in old_schema but not new_schema
"type_changed"columns present in both but with different dtypes
"""
# YOUR CODE HERE
pass