From 7b59dafb10e3656336934e1436af8beeb4393a93 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Tue, 9 Dec 2025 11:10:09 +0000 Subject: [PATCH 1/6] chore: ignore log files in test folder --- .gitignore | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.gitignore b/.gitignore index db4049f..be61a59 100644 --- a/.gitignore +++ b/.gitignore @@ -30,5 +30,8 @@ __pycache__ *.Identifier !requirements.txt .jupyter_cache + +# Ignore log files +tests/*.log tests/multiprocess_log.txt .vscode From b9949d2042a8292ff98dfe504f97d8b1c44b236b Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Thu, 11 Dec 2025 11:35:52 +0000 Subject: [PATCH 2/6] fix: make sure all values before unit conversion are numeric --- pyAMARES/kernel/PriorKnowledge.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pyAMARES/kernel/PriorKnowledge.py b/pyAMARES/kernel/PriorKnowledge.py index dc4a4ba..3b81dc0 100644 --- a/pyAMARES/kernel/PriorKnowledge.py +++ b/pyAMARES/kernel/PriorKnowledge.py @@ -181,6 +181,9 @@ def unitconverter(df_ini, MHz=120.0): pandas.DataFrame: A DataFrame with converted unit values in specified rows. """ df = deepcopy(df_ini) + df = df.apply( + pd.to_numeric, errors="raise", downcast="float" + ) # By this point the values should only be numeric if "chemicalshift" in df.index: df.loc["chemicalshift", df.notna().loc["chemicalshift"]] *= MHz @@ -189,7 +192,7 @@ def unitconverter(df_ini, MHz=120.0): if "phase" in df.index: df.loc["phase", df.notna().loc["phase"]] = np.deg2rad( - df.loc["phase"][df.notna().loc["phase"]].astype(float) + df.loc["phase"][df.notna().loc["phase"]] ) return df From 6e9cc7017aa5164b4b7fed2171c828ffbb42117a Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Mon, 5 Jan 2026 10:38:51 +0000 Subject: [PATCH 3/6] chore: improve log ignore pattern --- .gitignore | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index be61a59..43aa725 100644 --- a/.gitignore +++ b/.gitignore @@ -32,6 +32,6 @@ __pycache__ .jupyter_cache # Ignore log files -tests/*.log +tests/**/*.log tests/multiprocess_log.txt .vscode From 355691fb72b28cfc35f950b8abea38d81f0a06cc Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Mon, 5 Jan 2026 10:39:25 +0000 Subject: [PATCH 4/6] chore: add current env flag for nbval environment detection --- pytest.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pytest.ini b/pytest.ini index f7fb197..e481281 100644 --- a/pytest.ini +++ b/pytest.ini @@ -1,3 +1,3 @@ [pytest] -addopts = --nbval-lax +addopts = --nbval-lax --nbval-current-env testpaths = tests From 3da033130f919217b4f1751d659b1008cb28bbd1 Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Mon, 5 Jan 2026 10:43:03 +0000 Subject: [PATCH 5/6] fix: nbval current env in workflow --- .github/workflows/test-notebooks.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-notebooks.yml b/.github/workflows/test-notebooks.yml index e842d3e..59a0101 100644 --- a/.github/workflows/test-notebooks.yml +++ b/.github/workflows/test-notebooks.yml @@ -42,7 +42,7 @@ jobs: done - name: Run notebook tests - run: pytest --nbval-lax --current-env tests/ + run: pytest --nbval-lax --nbval-current-env tests/ - name: Upload executed notebooks on failure if: failure() From f2a0078b241e686019142afa89b41aedaa4b23fb Mon Sep 17 00:00:00 2001 From: Sebastian Bauer Date: Mon, 5 Jan 2026 10:55:53 +0000 Subject: [PATCH 6/6] fix: all map functions to be backward compatible --- pyAMARES/kernel/PriorKnowledge.py | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/pyAMARES/kernel/PriorKnowledge.py b/pyAMARES/kernel/PriorKnowledge.py index 3b81dc0..6bad6fb 100644 --- a/pyAMARES/kernel/PriorKnowledge.py +++ b/pyAMARES/kernel/PriorKnowledge.py @@ -329,13 +329,19 @@ def generateparameter( else: raise NotImplementedError("file format must be Excel (xlsx) or CSV!") - # Compatible with pandas both older and newer than 2.1.0 - pk = ( - pk.map(safe_convert_to_numeric) - if hasattr(pk, "map") - else pk.applymap(safe_convert_to_numeric) - ) # To be compatible with CSV + def backward_compatible_map(df, func): + # Check if the newer 'map' method exists (pandas >= 2.1.0) + if hasattr(df, "map"): + return df.map(func) + # Fallback to the older 'applymap' (pandas < 2.1.0) + elif hasattr(df, "applymap"): + return df.applymap(func) # type: ignore + else: + raise AttributeError( + "Pandas DataFrame has neither 'map' nor 'applymap' method." + ) + pk = backward_compatible_map(pk, safe_convert_to_numeric) peaklist = pk.columns.to_list() # generate a peak list directly from the [assert_peak_format(x) for x in peaklist] dfini = extractini(pk, MHz=MHz) # Parse initial values @@ -348,17 +354,8 @@ def generateparameter( df_lb2 = unitconverter(df_lb, MHz=MHz) df_ub2 = unitconverter(df_ub, MHz=MHz) # Make sure the bounds are numeric - # Compatible with pandas both older and newer than 2.1.0 - df_lb2 = ( - df_lb2.map(safe_convert_to_numeric) - if hasattr(df_lb2, "map") - else df_lb2.applymap(safe_convert_to_numeric) - ) - df_ub2 = ( - df_ub2.map(safe_convert_to_numeric) - if hasattr(df_ub2, "map") - else df_ub2.applymap(safe_convert_to_numeric) - ) + df_lb2 = backward_compatible_map(df_lb2, safe_convert_to_numeric) + df_ub2 = backward_compatible_map(df_ub2, safe_convert_to_numeric) if g_global is False: logger.debug( "Parameter g will be fit with the initial value set in the file %s" % fname