API reference · assignments/hw1.py · 991 lines
assignments.hw1
Assignment 1 autograder — "The Donut Effect for Philadelphia ZIP Codes".
Graded against assignment_template/assignment-1.ipynb.
The class downloads its own Zillow ZHVI extract, and Zillow revises that file continuously, so absolute row counts, ZIP counts and final percentages are not gradeable facts. These checks ask whether each step in the instructions worked, and verify it against the student's own data:
- the tidy frame must match the student's own (ZIP x date) grid,
- the two split frames must partition the student's own Philadelphia ZIPs,
- the percent-increase function is called on a frame the grader builds, so the right answer is known regardless of what the student loaded,
- the final comparison is checked for shape and direction, never for a value.
The only fixed values live in rubrics/hw1.yaml, and they are the ones the assignment itself fixes: the Center City ZIP list printed in the template, and the two comparison dates named in the instructions.
Summary
| Name | Kind | Description |
|---|---|---|
HW1Grader | class |
Constants
| Name | Value | Notes |
|---|---|---|
DEFAULT_CENTER_WORDS | ('center', 'centre', 'cc', 'inner', 'inside', 'in', 'within', 'downtown', 'core', 'central') | Name words that place a value in one group or the other (see _group_of). |
DEFAULT_OUTSIDE_WORDS | ('outside', 'outer', 'out', 'non', 'not', 'rest', 'other', 'others', 'remaining', 'suburb', 'suburbs', 'beyond', 'excluding', 'noncenter') | |
DATE_COLUMN_RE | re.compile('(19|20)\\d{2}[-/_.]?\\d{1,2}|^\\d{1,2}[-/.]\\d{1,2}[-/.](19|20)?\\d{2}$') | A Zillow extract's value columns are dates: "2020-03-31", "2020-03", and — once Excel has re-saved the file — "3/31/2020" or "3/31/20". |
Classes
No description.
Class attributes
| Name | Type | Default | Notes |
|---|---|---|---|
assignment_id | | 'hw1' |
Properties
Rubric checks 6
Each check_<rubric_id> method grades the rubric item with that id and returns one RubricItemResult.
- check_data_loading(ctx: GradingContext, item: RubricItem) -> RubricItemResult #[source]
10 ptsstructuralData loaded correctlyrubrics/hw1.yaml
The ZHVI file is read with pandas from a relative path.
Config keys:
absolute_path_penaltymin_date_columnsmissing_read_penaltyno_dataframe_penaltyrequired_imports
- check_philadelphia_subset(ctx: GradingContext, item: RubricItem) -> RubricItemResult #[source]
15 ptsdeterministicData trimmed to Philadelphiarubrics/hw1.yaml
A Philadelphia-only subset of the ZHVI data exists.
Config keys:
city_column_hintsexpected_city_valuesexpected_state_valuesexpected_zip_prefixmin_zip_countstate_column_hints
- check_tidy_transformation(ctx: GradingContext, item: RubricItem) -> RubricItemResult #[source]
20 ptsdeterministicData melted into tidy formatrubrics/hw1.yaml
Wide date columns are melted into rows, with the values in a column named ZHVI as the instructions require.
Config keys:
consistency_tolerancemin_long_ratiorequired_value_columnvalue_column_alternativeswrong_name_penalty_ratio
- check_center_city_split(ctx: GradingContext, item: RubricItem) -> RubricItemResult #[source]
15 ptsdeterministicCenter City split correctlyrubrics/hw1.yaml
The tidy data is split into a greater-Center-City frame and a frame for the rest of Philadelphia, using the ZIP list supplied in the template.
Config keys:
center_city_zipsflag_column_credit_ratiomin_match_similaritypartition_tolerancerequire_partition
- check_percent_increase_function(ctx: GradingContext, item: RubricItem) -> RubricItemResult #[source]
20 ptshidden_testPercent increase function worksrubrics/hw1.yaml
calculate_percent_increase(group_df) returns the percent change in ZHVI between the two dates named in the assignment.
Config keys:
abs_tolcasesend_datefirst_last_credit_ratiofraction_form_credit_ratioframerel_tolselectorstart_datestub_credit_ratiotabular_return_credit_ratiotypewhole_frame_credit_ratio
- check_donut_effect_comparison(ctx: GradingContext, item: RubricItem) -> RubricItemResult #[source]
10 ptsdeterministicCenter City vs. rest of Philadelphia comparedrubrics/hw1.yaml
Average percent increase is computed per ZIP code for both groups and the two averages are compared.
Config keys:
center_wordsexpect_outside_greateroutside_wordspercent_hintsplausible_range