Skip to content

Commit

Permalink
Pull request pnnl#155: updating index column naming for factory
Browse files Browse the repository at this point in the history
Merge in HYP/hypernetx from factory_fixes to develop

* commit '307016673f2e2bc77eee75081d7b8a9abeb9bf5c':
  Fix formatting
  Fixed PR comments from mark
  updating index column naming for factory
  • Loading branch information
amyersppnl authored and bonicim committed Apr 11, 2024
2 parents e6220d2 + 3070166 commit 7249e43
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
31 changes: 23 additions & 8 deletions hypernetx/classes/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,15 @@ def grabweight(cell):

# remove duplicate indices and aggregate using aggregation methods specified.
dfp = dfp[~dfp.index.duplicated(keep="first")]

# rename index columns if necessary
if level == 0 or level == 1:
# rename index column to 'uid'
dfp.index.names = ["uid"]
elif level == 2:
# rename index columns to 'edges' and 'nodes'
dfp.index.names = ["edges", "nodes"]

return dfp


Expand Down Expand Up @@ -231,16 +240,22 @@ def dict_factory_method(
attribute_df = pd.DataFrame(attribute_data)
DF = pd.concat([DF, attribute_df], axis=1)

# id the dataeframe is for edges or nodes.
# if the dictionary is for edges or nodes.
elif level == 1 or level == 0:
attribute_data = []
for key in D:
attributes_of_key = D[key]
attribute_data.append(attributes_of_key)

attribute_data = {weight_col: [], misc_properties_col: []}
for data_uid in D.values():
if isinstance(data_uid, dict):
attributes_of_uid = data_uid
if weight_col in attributes_of_uid:
weight_val = attributes_of_uid.pop(weight_col)
attribute_data[weight_col] += [weight_val]
else:
attribute_data[weight_col] += [default_weight]
attribute_data[misc_properties_col] += [attributes_of_uid]

attribute_df = pd.DataFrame(attribute_data)
DF = pd.concat(
[pd.DataFrame(list(D.keys()), columns=uid_cols), attribute_df], axis=1
)
DF = pd.concat([pd.DataFrame(list(D.keys())), attribute_df], axis=1)

# get property store from dataframe
PS = dataframe_factory_method(
Expand Down
2 changes: 0 additions & 2 deletions hypernetx/classes/incidence_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,8 @@ def restrict_to(self, level, items, inplace=False):
def equivalence_classes(self, level=0):
if level == 0:
old_dict = self._elements
col = "edges"
elif level == 1:
old_dict = self._memberships
col = "nodes"
else:
return self.data

Expand Down

0 comments on commit 7249e43

Please sign in to comment.