-
Notifications
You must be signed in to change notification settings - Fork 91
External input validator #1243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
cfreedman
merged 12 commits into
CodeForPhilly:staging
from
gabecano4308:external-input-validator
Jun 29, 2025
Merged
External input validator #1243
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
2c5dc9f
feat(validator): add validator for council districts
gabecano4308 f201f76
adding validator for city owned properties and altered some comments
gabecano4308 1fc1c57
updating pandera imports
gabecano4308 63fb0c7
updating pandera imports
gabecano4308 2fee362
ruff formatted
gabecano4308 7135861
added new schemas, corrected param names
gabecano4308 59c168a
feat(FilterView): ruff formatting
gabecano4308 3960ff6
feat(FilterView): ruff formatting
gabecano4308 5a22b91
feat(FilterView): align nullable stat
gabecano4308 0875393
feat(FilterView): ruff
gabecano4308 5ba572a
feat(FilterView): changing dataframemodel to dataframeschema in base
gabecano4308 c53e739
feat(FilterView): switched standardized_address for street_address. s…
gabecano4308 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,21 +1,74 @@ | ||
| import geopandas as gpd | ||
|
|
||
| import pandera.pandas as pa | ||
| import pandas as pd | ||
| from .base import BaseValidator | ||
|
|
||
| # Expecting ~7,796 records returned (within ±20% tolerance). | ||
| # This is checked in CityOwnedPropertiesInputSchema | ||
| expected = 7796 | ||
| lower = int(expected * 0.8) | ||
| upper = int(expected * 1.2) | ||
|
|
||
| CityOwnedPropertiesInputSchema = pa.DataFrameSchema( | ||
| columns={ | ||
| "opa_id": pa.Column(pa.Int, checks=pa.Check(lambda s: s.dropna() != "")), | ||
| "agency": pa.Column(pa.String, nullable=True), | ||
| "sideyardeligible": pa.Column( | ||
| pa.Category, nullable=True, checks=pa.Check.isin(["Yes", "No"]) | ||
| ), | ||
| "geometry": pa.Column("geometry"), | ||
| }, | ||
| checks=pa.Check(lambda df: lower <= df.shape[0] <= upper), | ||
| strict=True, | ||
| ) | ||
|
|
||
| CityOwnedPropertiesOutputSchema = pa.DataFrameSchema( | ||
| columns={ | ||
| "opa_id": pa.Column(pa.Int, checks=pa.Check(lambda s: s.dropna() != "")), | ||
| "market_value": pa.Column(pa.Int, nullable=True), | ||
| "sale_date": pa.Column(pd.DatetimeTZDtype(tz="UTC"), nullable=True), | ||
| "sale_price": pa.Column(pa.Float, nullable=True), | ||
| "owner_1": pa.Column(pa.String, nullable=True), | ||
| "owner_2": pa.Column(pa.String, nullable=True), | ||
| "building_code_description": pa.Column(pa.String, nullable=True), | ||
| "zip_code": pa.Column(pa.String, nullable=True), | ||
| "zoning": pa.Column(pa.String, nullable=True), | ||
| "parcel_type": pa.Column(pa.String, nullable=True), | ||
| "standardized_address": pa.Column(pa.String, nullable=True), | ||
| "vacant": pa.Column(pa.Bool, nullable=True), | ||
| "district": pa.Column(pa.String, nullable=True), | ||
| "neighborhood": pa.Column(pa.String, nullable=True), | ||
| "rco_info": pa.Column(pa.String, nullable=True), | ||
| "rco_names": pa.Column(pa.String, nullable=True), | ||
| "city_owner_agency": pa.Column(pa.String, nullable=True), | ||
| "side_yard_eligible": pa.Column( | ||
| pa.Category, nullable=True, checks=pa.Check.isin(["Yes", "No"]) | ||
| ), | ||
| "geometry": pa.Column("geometry"), | ||
| }, | ||
| strict=True, | ||
| ) | ||
|
|
||
|
|
||
| class CityOwnedPropertiesInputValidator(BaseValidator): | ||
| """Validator for access city owned properties service input.""" | ||
| """ | ||
| Validator for the city-owned properties dataset input. | ||
| schema and _custom_validation() are used by validate() in the parent class. | ||
| """ | ||
|
|
||
| schema = None | ||
| schema = CityOwnedPropertiesInputSchema | ||
|
|
||
| def _custom_validation(self, gdf: gpd.GeoDataFrame): | ||
| pass | ||
|
|
||
|
|
||
| class CityOwnedPropertiesOutputValidator(BaseValidator): | ||
| """Validator for city owned properties service output.""" | ||
| """ | ||
| Validator for the city-owned properties dataset output. | ||
| schema and _custom_validation() are used by validate() in the parent class. | ||
| """ | ||
|
|
||
| schema = None | ||
| schema = CityOwnedPropertiesOutputSchema | ||
|
|
||
| def _custom_validation(self, gdf: gpd.GeoDataFrame): | ||
| pass | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think these should be going on the
CityOwnedPropertiesInputValidatorsince this is defining a schema for the incoming data. The...OutputValidatorsare used to monitor the accumulated, constructed dataset in the pipeline after each service is called, so they should have an evolving schema that depends on the particular columns that are being changed or added progressively by the services.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. Where exactly should CityOwnedPropertiesInputValidator be called? I see in your framework setup you installed decorators with OutputValidators for each data_util, but InputValidators aren't being called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea the input validators need to be called slightly differently since they're coming in on the data loader. The input validators should be passed in to the respective loader class for each of the data services seen in the class definition here. Then the validation is called whenever data loading occurs here and the result is passed out.