Skip to content

Commit

Permalink
REF: use dict comprehension instead of map to process PROJ strings
Browse files Browse the repository at this point in the history
  • Loading branch information
snowman2 committed Jun 5, 2022
1 parent 3813abb commit 494bc38
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions pyproj/crs/crs.py
Expand Up @@ -573,7 +573,11 @@ def to_dict(self) -> dict:
"""

def parse(val):
proj_string = self.to_proj4()
if proj_string is None:
return {}

def _parse(val):
if val.lower() == "true":
return True
if val.lower() == "false":
Expand All @@ -588,16 +592,13 @@ def parse(val):
pass
return _try_list_if_string(val)

proj_string = self.to_proj4()
if proj_string is None:
return {}

items = map(
lambda kv: len(kv) == 2 and (kv[0], parse(kv[1])) or (kv[0], None),
(part.lstrip("+").split("=", 1) for part in proj_string.strip().split()),
)
def _process_step(step):
step_parts = step.lstrip("+").split("=", maxsplit=1)
if len(step_parts) == 2:
return step_parts[0], _parse(step_parts[1])
return step_parts[0], None

return {key: value for key, value in items if value is not False}
return dict(_process_step(step) for step in proj_string.strip().split())

def to_cf(
self,
Expand Down

0 comments on commit 494bc38

Please sign in to comment.