Skip to content

Commit

Permalink
formatted
Browse files Browse the repository at this point in the history
  • Loading branch information
hrshdhgd committed Nov 13, 2023
1 parent d47bf81 commit 2b93a34
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/sssom/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,27 +148,24 @@ def from_mapping_set_document(cls, doc: MappingSetDocument) -> "MappingSetDataFr
"""Instantiate from a mapping set document."""
if doc.mapping_set.mappings is None:
return cls(df=pd.DataFrame(), converter=doc.converter)

df = pd.DataFrame(get_dict_from_mapping(mapping) for mapping in doc.mapping_set.mappings)
meta = _extract_global_metadata(doc)

# remove columns where all values are blank.
df.replace("", np.nan, inplace=True)
df.dropna(axis=1, how="all", inplace=True) # remove columns with all row = 'None'-s.

slots = _get_sssom_schema_object().dict["slots"]
slots_with_double_as_range = {
slot
for slot, slot_metadata in slots.items()
if slot_metadata["range"] == "double"
slot for slot, slot_metadata in slots.items() if slot_metadata["range"] == "double"
}
non_double_cols = df.loc[:, ~df.columns.isin(slots_with_double_as_range)]
non_double_cols = non_double_cols.replace(np.nan, "")
df[non_double_cols.columns] = non_double_cols

df = sort_df_rows_columns(df)
return cls.with_converter(df=df, converter=doc.converter, metadata=meta)


def to_mapping_set_document(self) -> "MappingSetDocument":
"""Get a mapping set document."""
Expand Down Expand Up @@ -1056,11 +1053,7 @@ def get_dict_from_mapping(map_obj: Union[Any, Dict[Any, Any], SSSOM_Mapping]) ->
slots = sssom_schema_object["slots"]
enums_keys = sssom_schema_object["enums"].keys()

slots_with_double_as_range = [
s
for s in slots.keys()
if slots[s]["range"] == "double"
]
slots_with_double_as_range = [s for s in slots.keys() if slots[s]["range"] == "double"]

for property in map_obj:
if map_obj[property] is not None:
Expand Down Expand Up @@ -1095,7 +1088,6 @@ def get_dict_from_mapping(map_obj: Union[Any, Dict[Any, Any], SSSOM_Mapping]) ->
return map_dict



CURIE_PATTERN = r"[A-Za-z0-9_.]+[:][A-Za-z0-9_]"
CURIE_RE = re.compile(CURIE_PATTERN)

Expand Down

0 comments on commit 2b93a34

Please sign in to comment.