Skip to content

Commit 1346479

Browse files
Fix Pandas downcast
1 parent e7d39ed commit 1346479

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

accelforge/mapper/FFM/_pareto_df/df_convention.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import functools
22
import re
3-
3+
import pandas as pd
44
from accelforge.util import NUMPY_FLOAT_TYPE
55
from accelforge.util._frozenset import fzs
66
from accelforge.frontend.workload import Rank
@@ -212,9 +212,16 @@ def is_n_iterations_col(c: str) -> bool:
212212
def ensure_float_type(df, target, source):
213213
if target in df:
214214
target_type = df[target].dtype
215-
source_type = df[source].dtype
216-
if target_type != source_type:
215+
else:
216+
target_type = NUMPY_FLOAT_TYPE
217+
218+
if isinstance(source, pd.Series):
219+
if target in df and target_type != source.dtype:
217220
df[target] = df[target].astype(NUMPY_FLOAT_TYPE)
221+
elif source in df:
222+
if target_type != df[source].dtype:
223+
if target in df:
224+
df[target] = df[target].astype(NUMPY_FLOAT_TYPE)
218225
df[source] = df[source].astype(NUMPY_FLOAT_TYPE)
219226

220227

@@ -227,6 +234,12 @@ def max_to_col(df, target, source):
227234
ensure_float_type(df, target, source)
228235
df.loc[:, target] = df[[target, source]].max(axis=1) if target in df else df[source]
229236

237+
def add_to_col(df, target, source):
238+
ensure_float_type(df, target, source)
239+
if isinstance(source, pd.Series):
240+
df[target] = df[target] + source
241+
else:
242+
df.loc[:, target] = df[target] + df[source] if target in df else df[source]
230243

231244
def is_objective_col(c):
232245
return partition_col(c, "Total") is not None

0 commit comments

Comments
 (0)