Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

made pandas dataframe optional to prevent serialization #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/framework/processing/py/port/api/props.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from dataclasses import dataclass
from typing import Optional, TypedDict
from typing import Optional, TypedDict, Dict, Any

import pandas as pd

Expand Down Expand Up @@ -98,14 +98,20 @@ class PropsUIPromptConsentFormTable:

id: str
title: Translatable
data_frame: pd.DataFrame
data_frame: pd.DataFrame | Dict[str, Dict[str, Any]]

def translate_data_frame(self):
if isinstance(self.data_frame, pd.DataFrame):
return self.data_frame.to_json()
else:
return self.data_frame

def toDict(self):
dict = {}
dict["__type__"] = "PropsUIPromptConsentFormTable"
dict["id"] = self.id
dict["title"] = self.title.toDict()
dict["data_frame"] = self.data_frame.to_json()
dict["data_frame"] = self.translate_data_frame()
return dict


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const ConsentForm = (props: Props): JSX.Element => {
const id = tableData.id
const title = Translator.translate(tableData.title, props.locale)
const deletedRowCount = 0
const dataFrame = JSON.parse(tableData.data_frame)
const dataFrame = loadDataFrame(tableData.data_frame)
const headCells = columnNames(dataFrame).map((column: string) => headCell(dataFrame, column))
const head: PropsUITableHead = { __type__: 'PropsUITableHead', cells: headCells }
const body: PropsUITableBody = { __type__: 'PropsUITableBody', rows: rows(dataFrame) }
Expand Down Expand Up @@ -169,6 +169,13 @@ export const ConsentForm = (props: Props): JSX.Element => {
)
}

function loadDataFrame(dataFrame: any) {
if (typeof dataFrame === "string") {
return JSON.parse(dataFrame)
}
return dataFrame;
}

const donateQuestionLabel = new TextBundle()
.add('en', 'Do you want to donate the above data?')
.add('de', 'Möchten Sie die oben genannten Daten spenden?')
Expand Down