From c98cbc27f89c01c7b782db1d9c07c6842918eb0b Mon Sep 17 00:00:00 2001 From: Felix Oesterle <6945681+fso42@users.noreply.github.com> Date: Wed, 18 Mar 2026 14:52:25 +0100 Subject: [PATCH] refactor(cfgUtils): change handling of `nan` and special character checks in `simDFTest` refactor(cfgUtils): change `nan` handling and indexing in `simDFTest` --- avaframe/in3Utils/cfgUtils.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/avaframe/in3Utils/cfgUtils.py b/avaframe/in3Utils/cfgUtils.py index dafd133ba..36d476e33 100644 --- a/avaframe/in3Utils/cfgUtils.py +++ b/avaframe/in3Utils/cfgUtils.py @@ -914,13 +914,13 @@ def convertDF2numerics(simDF): simDFTest = simDFTest.replace("-", "", regex=False) # check for str(np.nan) as these cannot be converted to numerics by pd.to_numeric # but as friction model parameters are set to nans this is required here - if simDFTest.str.match("nan").any(): + if simDFTest.dropna().astype(str).eq("nan").any(): simDF = setStrnanToNan(simDF, simDFTest, name) # also include columns where nan is in first row - so check for any row if simDFTest.str.isdigit().any() and (name != "tSteps"): # problem here is that it finds even if not present in | although not in ini simDFTest = simDF[name].str.replace("|", "§", regex=False) - if simDFTest.str.contains("§").any() == False: + if simDFTest.astype(str).str.contains("§", regex=False).any() == False: simDF[name] = pd.to_numeric(simDF[name]) log.debug("Converted to numeric %s" % name) else: @@ -950,10 +950,10 @@ def setStrnanToNan(simDF, simDFTest, name): nanIndex = simDFTest.str.match("nan", flags=re.IGNORECASE) simIndex = simDF.index.values - # loop over each row and use simDF.at to avoid copy vs view warning + # loop over each row and use iloc to avoid duplicate index issues for index, nanInd in enumerate(nanIndex): if nanInd: - simDF.at[simIndex[index], name] = np.nan + simDF.iloc[index, simDF.columns.get_loc(name)] = np.nan log.info("%s for index: %s set to numpy nan" % (name, index)) return simDF