Skip to content

Commit

Permalink
duplicate values when not updated in the table
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineBellemare committed Feb 6, 2025
1 parent 28d9e2a commit 326deb1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/goofi/nodes/outputs/writecsv.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import datetime
import os

import numpy as np

from goofi.data import Data, DataType
from goofi.node import Node
from goofi.params import StringParam
Expand All @@ -28,14 +26,15 @@ def setup(self):
self.last_filename = None
self.base_filename = None # Track the base filename without timestamp
self.written_files = set() # Track files to ensure headers are written
self.last_values = {} # Store the last known value for each column

def process(self, table_input: Data):
# Check if writing is enabled
if not self.params["Write"]["write"].value:
return

table_data = table_input.data

# Extract actual data content, handling multiple columns
actual_data = {
key: (value.data if isinstance(value, Data) else value)
Expand All @@ -58,6 +57,16 @@ def flatten(data):
for col in flattened_data:
flattened_data[col] += [None] * (max_length - len(flattened_data[col]))

# Replace None with the last known value
for col in flattened_data:
if col not in self.last_values:
self.last_values[col] = None # Initialize with None if not present
for i in range(len(flattened_data[col])):
if flattened_data[col][i] is None:
flattened_data[col][i] = self.last_values[col]
else:
self.last_values[col] = flattened_data[col][i] # Update the last known value

# Convert to DataFrame
df = self.pd.DataFrame(flattened_data)

Expand Down

0 comments on commit 326deb1

Please sign in to comment.