Skip to content

Commit

Permalink
Improve Darwin Core output
Browse files Browse the repository at this point in the history
  • Loading branch information
rafelafrance committed May 29, 2024
1 parent da327c0 commit 8134111
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion traiter/pylib/darwin_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,20 @@ def add_dyn(self, **kwargs) -> "DarwinCore":
self.dyn_props[key].append(value)
return self

def flatten(self) -> dict[str, Any]:
props = self.props | self.dyn_props
return self.format_dict(props)

@staticmethod
def format_dict(value: dict) -> dict:
return {k: v for k, v in value.items() if v is not None}
formatted = {}
for key, val in value.items():
if val is None:
continue
if isinstance(val, list) and len(val) == 1:
val = val[0]
formatted[key] = val
return formatted

@staticmethod
def ns(name):
Expand Down

0 comments on commit 8134111

Please sign in to comment.