Skip to content

Commit

Permalink
Implementation of re-creating variables from dataframe + metadata in …
Browse files Browse the repository at this point in the history
…attrs
  • Loading branch information
IKCAP committed Jul 5, 2024
1 parent 7fd6e35 commit 93bdb20
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions pylipd/classes/datatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import re
import pandas as pd
import json
from pylipd.classes.variable import Variable
from pylipd.utils import uniqid
from pylipd.classes.variable import Variable

Expand Down Expand Up @@ -242,6 +243,9 @@ def getDataFrame(self, use_standard_names=False) -> pd.DataFrame:
return df

def setDataFrame(self, df: pd.DataFrame):
# Need to delete all existing variables
# Create new set of variable objects using the metadata
pass
self.variables = []
for colname in df.attrs:
v = Variable.from_json(df.attrs[colname])
v.setValues(json.dumps(df[colname].to_list()))
self.addVariable(v)
8 changes: 6 additions & 2 deletions pylipd/classes/templates/datatable.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pandas as pd
import json
from pylipd.classes.variable import Variable

### START TEMPLATE FUNCTION ###
# Special Functions manually added for DataTable class
Expand Down Expand Up @@ -33,7 +34,10 @@ def getDataFrame(self, use_standard_names=False) -> pd.DataFrame:

### START TEMPLATE FUNCTION ###
def setDataFrame(self, df: pd.DataFrame):
# Need to delete all existing variables
# Create new set of variable objects using the metadata
pass
self.variables = []
for colname in df.attrs:
v = Variable.from_json(df.attrs[colname])
v.setValues(json.dumps(df[colname].to_list()))
self.addVariable(v)
### END TEMPLATE FUNCTION ###

0 comments on commit 93bdb20

Please sign in to comment.