From f6238d611ed6b544bdea58afa917b43f423b9dc2 Mon Sep 17 00:00:00 2001 From: Pierre-Francois Leget Date: Wed, 26 Feb 2025 13:56:08 -0500 Subject: [PATCH 1/2] fix what was wrong for python 3.13 --- treegp/kernels.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/treegp/kernels.py b/treegp/kernels.py index 7960feb..888b5c1 100644 --- a/treegp/kernels.py +++ b/treegp/kernels.py @@ -27,6 +27,8 @@ def eval_kernel(kernel): kernel = sklearn.gaussian_process.kernels.RBF(1) """ + namespace = {} + def recurse_subclasses(cls): out = [] for c in cls.__subclasses__(): @@ -36,17 +38,17 @@ def recurse_subclasses(cls): clses = recurse_subclasses(Kernel) for cls in clses: - module = __import__(cls.__module__, globals(), locals(), cls) - execstr = "{0} = module.{0}".format(cls.__name__) - exec(execstr, globals(), locals()) + module = __import__(cls.__module__, globals(), namespace, [cls.__name__]) + namespace[cls.__name__] = getattr(module, cls.__name__) + + from numpy import array # if needed in the namespace - from numpy import array # noqa: F401 + # Add array to the namespace if necessary + namespace["array"] = array try: - k = eval(kernel) - except (KeyboardInterrupt, SystemExit): - raise - except Exception as e: # pragma: no cover + k = eval(kernel, namespace) + except Exception as e: raise RuntimeError( "Failed to evaluate kernel string {0!r}. " "Original exception: {1}".format(kernel, e) From f038f6bdab83d9113a3e14a804a934592b6c8898 Mon Sep 17 00:00:00 2001 From: Pierre-Francois Leget Date: Wed, 26 Feb 2025 13:57:21 -0500 Subject: [PATCH 2/2] remove 3.8 and add 3.13 --- .github/workflows/test_treegp.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test_treegp.yaml b/.github/workflows/test_treegp.yaml index 8c21d01..6dcfd92 100644 --- a/.github/workflows/test_treegp.yaml +++ b/.github/workflows/test_treegp.yaml @@ -14,7 +14,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [ 3.8, 3.9, "3.10", "3.11", "3.12" ] + python-version: [ 3.9, "3.10", "3.11", "3.12", "3.13" ] steps: - uses: actions/checkout@v2