Skip to content

Commit

Permalink
Use pandas string accessors for slightly cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
ppinchuk committed Jun 30, 2022
1 parent 71a766c commit 51f1f44
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
3 changes: 3 additions & 0 deletions reVX/setbacks/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ def _parse_regulations(self, regulations_fpath):
logger.error(msg)
raise RuntimeError(msg)

feature_types = regulations['Feature Type'].str.strip().str.lower()
regulations['Feature Type'] = feature_types

return regulations.to_crs(crs=self.crs)

def _parse_county_regulations(self, regulations):
Expand Down
2 changes: 1 addition & 1 deletion reVX/setbacks/parcel_setbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _parse_regulations(self, regulations_fpath):
"""
regulations = super()._parse_regulations(regulations_fpath)

mask = regulations['Feature Type'].apply(str.strip) == 'Property Line'
mask = regulations['Feature Type'] == 'property line'
regulations = regulations.loc[mask]

return regulations
Expand Down
4 changes: 2 additions & 2 deletions reVX/setbacks/water_setbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def _parse_regulations(self, regulations_fpath):
"""
regulations = super()._parse_regulations(regulations_fpath)

feats = regulations['Feature Type'].apply(str.strip).apply(str.lower)
regulations = regulations.loc[feats == 'water']
mask = regulations['Feature Type'] == 'water'
regulations = regulations.loc[mask]

return regulations
8 changes: 4 additions & 4 deletions reVX/setbacks/wind_setbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ def _parse_regulations(self, regulations_fpath):
"""
regulations = super()._parse_regulations(regulations_fpath)

mask = ((regulations['Feature Type'] == 'Structures')
mask = ((regulations['Feature Type'] == 'structures')
& (regulations['Comment'] != 'Occupied Community Buildings'))
regulations = regulations.loc[mask]

Expand Down Expand Up @@ -522,7 +522,7 @@ def _parse_regulations(self, regulations_fpath):
"""
regulations = super()._parse_regulations(regulations_fpath)

feature_types = {'Roads', 'Highways', 'Highways 111'}
feature_types = {'roads', 'highways', 'highways 111'}
mask = regulations['Feature Type'].isin(feature_types)
regulations = regulations.loc[mask]

Expand Down Expand Up @@ -585,7 +585,7 @@ def _parse_regulations(self, regulations_fpath):
"""
regulations = super()._parse_regulations(regulations_fpath)

mask = regulations['Feature Type'] == 'Transmission'
mask = regulations['Feature Type'] == 'transmission'
regulations = regulations.loc[mask]

return regulations
Expand Down Expand Up @@ -617,7 +617,7 @@ def _parse_regulations(self, regulations_fpath):
sup = super(TransmissionWindSetbacks, self)
regulations = sup._parse_regulations(regulations_fpath)

mask = regulations['Feature Type'] == 'Railroads'
mask = regulations['Feature Type'] == 'railroads'
regulations = regulations.loc[mask]

return regulations
4 changes: 2 additions & 2 deletions tests/test_setbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_local_parcels(max_workers, regulations_fpath):

regulations = pd.read_csv(regulations_fpath)
property_lines = (
regulations['Feature Type'].apply(str.strip) == 'Property Line'
regulations['Feature Type'].str.strip() == 'Property Line'
)
counties_should_have_exclusions = set(
regulations[property_lines].FIPS.unique()
Expand Down Expand Up @@ -294,7 +294,7 @@ def test_local_water(max_workers, regulations_fpath, expected_sum):
counties_with_exclusions = set(exc['cnty_fips'][np.where(test)])

regulations = pd.read_csv(regulations_fpath)
feats = regulations['Feature Type'].apply(str.strip).apply(str.lower)
feats = regulations['Feature Type'].str.strip().str.lower()
counties_should_have_exclusions = set(
regulations[feats == 'water'].FIPS.unique()
)
Expand Down

0 comments on commit 51f1f44

Please sign in to comment.